Skip to content

date-time from Docker does not conform to format #4

@Rid

Description

@Rid

$object->setStart(\DateTime::createFromFormat('Y-m-d\\TH:i:sP', $data['Start']));

Here docker outputs:

      "Health": {
        "Status": "healthy",
        "FailingStreak": 0,
        "Log": [
          {
            "Start": "2023-02-14T16:56:23.106704411+01:00",
            "End": "2023-02-14T16:56:23.446917777+01:00",
            "ExitCode": 0,
            "Output": "somelog"
            },
         ]
       }

Notice the microseconds has 9 digits.

Even parsing this with "Y-m-d\TH:i:s.uP" gives false as u in php can only have a max of 6 digits.

php > var_dump(\DateTime::createFromFormat('Y-m-d\TH:i:s.uP', "2023-02-14T17:00:29.14396576+01:00"));
php shell code:1:
bool(false)

To make it work we could parse it with uu, but of course it's not correct, but it does dismiss the errors:

php > var_dump(\DateTime::createFromFormat('Y-m-d\TH:i:s.uuP', "2023-02-14T17:00:29.14396576+01:00"));
php shell code:1:
class DateTime#1 (3) {
  public $date =>
  string(26) "2023-02-14 17:00:29.760000"
  public $timezone_type =>
  int(1)
  public $timezone =>
  string(6) "+01:00"
}

I know this is generated by janephp, but it's a very specific case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions