Extends DateTimeType with support for time zones.
string
The classname to use when creating objects.
string
The DateTime format used when converting to string.
array|string|int
The locale-aware format marshal()
uses when _useLocaleParser
is true.
array<string>
The DateTime formats allowed by marshal()
.
string|null
Identifier name for this type
bool
Whether marshal()
should use locale-aware parser with _localeMarshalFormat
.
DateTimeZone|null
Database time zone.
DateTimeZone
Default time zone.
bool
Whether database time zone is kept when converting
bool
Whether we want to override the time of the converted Time objects so it points to the start of the day.
DateTimeZone|null
User time zone.
Constructor
Converts a string into a DateTime object after parsing it using the locale aware parser with the format set by setLocaleFormat()
.
Converts a string into a DateTime object after parsing it using the formats in _marshalFormats
.
Set the classname to use when building objects.
Returns the base type name that this class is inheriting.
Get the classname used for building objects.
Returns type identifier name for this object.
Returns an array of the values converted to the PHP representation of this type.
Convert request data into a datetime object.
Generate a new primary key value for a given type.
Set database timezone.
Set whether DateTime object created from database string is converted to default time zone.
Sets the locale-aware format used by marshal()
when parsing strings.
Alias for setDatabaseTimezone()
.
Set user timezone.
Convert DateTime instance into strings.
Casts given value from a database type to a PHP equivalent.
Casts given value to Statement equivalent
Change the preferred class name to the FrozenTime implementation.
Sets whether to parse strings passed to marshal()
using the locale-aware format set by setLocaleFormat()
.
Change the preferred class name to the mutable Time implementation.
__construct(string|null $name = null)
Constructor
string|null
$name optional The name identifying this type
_parseLocaleValue(string $value): Cake\I18n\I18nDateTimeInterface|null
Converts a string into a DateTime object after parsing it using the locale aware parser with the format set by setLocaleFormat()
.
string
$value The value to parse and convert to an object.
Cake\I18n\I18nDateTimeInterface|null
_parseValue(string $value): DateTimeInterface|null
Converts a string into a DateTime object after parsing it using the formats in _marshalFormats
.
string
$value The value to parse and convert to an object.
DateTimeInterface|null
_setClassName(string $class, string $fallback): void
Set the classname to use when building objects.
string
$class The classname to use.
string
$fallback The classname to use when the preferred class does not exist.
void
getBaseType(): string|null
Returns the base type name that this class is inheriting.
This is useful when extending base type for adding extra functionality, but still want the rest of the framework to use the same assumptions it would do about the base type it inherits from.
string|null
getDateTimeClassName(): string
Get the classname used for building objects.
string
getName(): string|null
Returns type identifier name for this object.
string|null
manyToPHP(array $values, array<string> $fields, Cake\Database\DriverInterface $driver): array<string, mixed>
Returns an array of the values converted to the PHP representation of this type.
array
$values array<string>
$fields Cake\Database\DriverInterface
$driver array<string, mixed>
marshal(mixed $value): DateTimeInterface|null
Convert request data into a datetime object.
Most useful for converting request data into PHP objects, that make sense for the rest of the ORM/Database layers.
mixed
$value Request data
DateTimeInterface|null
newId(): mixed
Generate a new primary key value for a given type.
This method can be used by types to create new primary key values when entities are inserted.
mixed
setDatabaseTimezone(DateTimeZone|string|null $timezone): $this
Set database timezone.
This is the time zone used when converting database strings to DateTime instances and converting DateTime instances to database strings.
DateTimeZone|string|null
$timezone Database timezone.
$this
setKeepDatabaseTimezone(bool $keep): $this
Set whether DateTime object created from database string is converted to default time zone.
If your database date times are in a specific time zone that you want to keep in the DateTime instance then set this to true.
When false, datetime timezones are converted to default time zone. This is default behavior.
bool
$keep If true, database time zone is kept when converting to DateTime instances.
$this
setLocaleFormat(array|string $format): $this
Sets the locale-aware format used by marshal()
when parsing strings.
See Cake\I18n\Time::parseDateTime()
for accepted formats.
array|string
$format The locale-aware format
$this
setTimezone(DateTimeZone|string|null $timezone): $this
Alias for setDatabaseTimezone()
.
DateTimeZone|string|null
$timezone Database timezone.
$this
setUserTimezone(DateTimeZone|string|null $timezone): $this
Set user timezone.
This is the time zone used when marshalling strings to DateTime instances.
DateTimeZone|string|null
$timezone User timezone.
$this
toDatabase(mixed $value, Cake\Database\DriverInterface $driver): string|null
Convert DateTime instance into strings.
mixed
$value The value to convert.
Cake\Database\DriverInterface
$driver The driver instance to convert with.
string|null
toPHP(mixed $value, Cake\Database\DriverInterface $driver): DateTimeInterface|null
Casts given value from a database type to a PHP equivalent.
mixed
$value Value to be converted to PHP equivalent
Cake\Database\DriverInterface
$driver Object from which database preferences and configuration will be extracted
DateTimeInterface|null
toStatement(mixed $value, Cake\Database\DriverInterface $driver): mixed
Casts given value to Statement equivalent
mixed
$value value to be converted to PDO statement
Cake\Database\DriverInterface
$driver object from which database preferences and configuration will be extracted
mixed
useImmutable(): $this
Change the preferred class name to the FrozenTime implementation.
$this
useLocaleParser(bool $enable = true): $this
Sets whether to parse strings passed to marshal()
using the locale-aware format set by setLocaleFormat()
.
bool
$enable optional Whether to enable
$this
useMutable(): $this
Change the preferred class name to the mutable Time implementation.
$this
The classname to use when creating objects.
string
The DateTime format used when converting to string.
string
The locale-aware format marshal()
uses when _useLocaleParser
is true.
See Cake\I18n\Time::parseDateTime()
for accepted formats.
array|string|int
The DateTime formats allowed by marshal()
.
array<string>
Identifier name for this type
string|null
Whether marshal()
should use locale-aware parser with _localeMarshalFormat
.
bool
Database time zone.
DateTimeZone|null
Default time zone.
DateTimeZone
Whether database time zone is kept when converting
bool
Whether we want to override the time of the converted Time objects so it points to the start of the day.
This is primarily to avoid subclasses needing to re-implement the same functionality.
bool
User time zone.
DateTimeZone|null
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.4/class-Cake.Database.Type.DateTimeTimezoneType.html