-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Yaml] Support parsing YAML timestamps as DateTime #14420
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
238589d
3daae64
9db5c6f
663a9ca
41c5f12
dd4798e
1f4269e
028f2d7
5d75dd0
72abdee
1b970f3
422d838
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,7 +110,7 @@ public static function dump($value, $exceptionOnInvalidType = false, $objectSupp | |
case is_object($value): | ||
if ($value instanceof \DateTime || $value instanceof \DateTimeImmutable) { | ||
if ($value->getTimezone()->getName() === date_default_timezone_get()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about this. The code parsing the date might have a different default timezone. It is better to always include all info IMO There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, if the TimeZone has been intentionally defined as for exemple +1 (in the YAML file parsed or in the PHP datas), it dumps it (because the server server timestamp is for example Europe/Paris and not +1). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if it was explicitly defined as UTC and the server default timezone is also UTC ? You have no way to know whether the UTC timezone was explicitly chosen or no. But even worse, you have no idea how this will be parsed. So IMO, you should not drop information when dumping, assuming that the server parsing your YAML will have the same config There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. |
||
if (0 === (int) $value->format('His')) { | ||
if ('000000' === $value->format('His')) { | ||
return $value->format('Y-m-d'); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use
DateTimeInterface
rather thanDateTimeImmutable
. This way, the DateTimeInterface check covers all supported cases for PHP 5.5+ (and we can drop the DateTime check in 3.0 when dropping the PHP 5.4 support)