Details
-
Improvement
-
Resolution: Unresolved
-
High
-
None
-
1.3.0, 1.6.0
-
all
Description
Hi here,
First the storage is good, this issue is all about initialization.
The DateAndTime\Value does not set the correct current timezone.
In fact this issue comes from a PHP Datetime specifity:
http://php.net/manual/en/datetime.construct.php
The $timezone parameter and the current timezone are ignored when the $time parameter either is a UNIX timestamp (e.g. @946684800) or specifies a timezone (e.g. 2010-01-28T15:00:00+02:00).
Then by default when I use the API and do a getFieldValue('mydate')->format() the format will use UTC instead of the current timezone.
The expected value would be a format that respects the date_default_timezone_get()
For instance:
- I am in the America/Los_Angeles timezone
- From the Administration Interface (or the API) I set a DateAndTime attribute to May 4th 23:59:59 ( my timezone: America/Los_Angeles)
- eZ will store that as a timestamp ( which it's fine to me and irrelevant to the issue)
- I query the API and get my content, then I want to display the day and month of this attribute in my timezone.
- I do a
$content->getFieldValue($attr)->value->format('m-d');
- The result is 5-5
- The expected result should be : 5-4
=> why because PHP has instantiated the Datetime object in UTC (cf documentation)
Then the PR should fix the fromTimestamp but also the fromString that could be impacted depending of the string (cf documentation)
Hope it is clear!