Skip to content

Support parsing YAML timestamps as DateTime #11838

Closed
@stof

Description

@stof

Currently, YAML timestamps are pased into integers representing a Unix timestamp:

case preg_match(self::getTimestampRegex(), $scalar):

however, this is not very handy:

  • it does not allow knowing that a YAML timestamp was provided (as it parses the same than an integer)
  • dumping again the parsed data would not generate the same data (it will dump an integer, not a timestamp).

Dumping a YAML timestamp is actually impossible currently (if you format it as a YAML timestamp manually in a PHP string, it will be dumped as a string because the dumper knows that the string needs to be escaped).

So here is my proposal:

  • make the dumper accept DateTimeInterface objects and dumping them as Yaml timestamps (they are currently dumped as PHP objects like other objects, or more likely throwing an exception as the object dumping is forbidden by default)
  • add an option in the parser to parse timestamps as DateTime objects rather than integers. this option would be disabled by default for BC reasons, but I suggest that 3.0 could change it to become enabled by default.

What do you think about it ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions