Bug #44997

JsonView outputs unreliable DateTime representation

Added by Adrian Föder over 8 years ago. Updated over 8 years ago.

Status:
Resolved
Priority:
Must have
Assignee:
Category:
MVC
Start date:
2013-01-31
Due date:
% Done:

100%

Estimated time:
PHP Version:
5.3
Has patch:
Yes
Complexity:

Description

Currently, the JsonView just outputs Y-m-d H:i:s as string when it comes to a DateTime object. This is incorrect since it doesn't care about time zones / offsets.

Error case:
  • it's 15:13 GMT, a record is created
  • the record is stored in 14:13 UTC
  • after Hydration, the DateTime object represents 14:13 UTC
  • JsonView's H:i:s makes "14:13" of it
  • (maybe) the string is directly given to JavaScript's new Date() constructor, resulting (due to GMT local time) in 14:13 GMT which is obviously wrong.

Solution: add a timezone offset as in ISO 8601 which is also directly accepted by JavaScript's Date() constructor and probably any other "magical" datetime parser.

Also available in: Atom PDF