-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
There seems to be no way of serializing an ISO 8601 date to YAML format so that it would be re-interpreted as date when parsed again. Consider the following simple tests:
use Symfony\Component\Yaml\Yaml;
print_r(Yaml::parse('date: 2015-12-21T22:30:00'));
// Array
// (
// [date] => 1450737000
// )
echo Yaml::dump(['date' => 1450737000]);
// date: 1450737000
echo Yaml::dump(['date' => new \DateTime('2015-12-21T22:30:00')]);
// date: null
echo Yaml::dump(['date' => new \DateTime('@1450737000')]);
// date: null
echo Yaml::dump(['date' => '2015-12-21T22:30:00']);
// date: '2015-12-21T22:30:00'
print_r(Yaml::parse('date: \'2015-12-21T22:30:00\''));
// Array
// (
// [date] => 2015-12-21T22:30:00
// )
Parsing an unquoted ISO 8601 date will correctly result in a UNIX timestamp (btw. why not a DateTime
object at all? At least as an option this should be available IMHO). Now try to do it the other way round:
- Passing in a UNIX timestamp will result in an integer
- Passing in a
DateTime
object will result innull
- Passing in an ISO 8601 string will result in a quoted string
But re-parsing the quoted string won't convert it back to a UNIX timestamp (because of the quotes).