Improved Timezone Support
Updated Timezone Support
In 5.1, timezone support has been improved for DateTime
objects going in & out of Datastore.
Datstore keeps the data recorded as UTC.
Data coming out through PHP-GDS as Entities
You can now expect any DateTime
object coming out of Datastore from PHP-GDS to have your current PHP default timezone applied. Example follows:
date_default_timezone_set('America/New_York');
$obj_store = new GDS\Store('Book');
$obj_book = $obj_store->fetchOne();
echo $obj_book->published->format('c'); // 2004-02-12T15:19:21-05:00
echo $obj_book->published->getTimezone()->getName(); // America/New_York
Data going in - multi format support
If you pass in a DateTime
object (or anything matching DateTimeInterface
), we will respect the timezone set on it.
Any other string-based value passed in for a datetime
field will be converted to a DateTimeImmutable
object before being converted to UTC, using the standard PHP methods:
https://www.php.net/manual/en/datetime.construct.php
This means that unless using a timestamp value (e.g. @946684800
), or a value with a timezone already stated (e.g. 2010-01-28T15:00:00+02:00
), we will assume the value is in your current timezone context.