Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Use DateTime::createFromFormat #168

Merged

Conversation

chingor13
Copy link
Member

@chingor13 chingor13 commented Apr 6, 2018

Addresses: #159

Turns out DateTime::__construct behaves differently if the locale is different:

With locale default (UTF-8):

var_dump(new \DateTime("2018-04-06T14:09:00.123456"));

outputs (note that we have microseconds here):

object(DateTime)#2 (3) {
  ["date"]=>
  string(26) "2018-04-06 14:09:00.123456"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(12) "Europe/Paris"
}

But changing the locale:

setlocale(LC_ALL, 'fr_FR.UTF-8');
var_dump(new \DateTime("2018-04-06T14:09:00.123456"));

outputs (not that we lost microsecond resolution):

object(DateTime)#2 (3) {
  ["date"]=>
  string(26) "2018-04-06 14:09:00.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(12) "Europe/Paris"
}

@bogdandrutu
Copy link

This fixes #159 correct?

@chingor13
Copy link
Member Author

@bogdandrutu Yes it fixes #159, but the root cause actually feels like a bug in PHP.

@chingor13 chingor13 merged commit e7fdaa6 into census-instrumentation:master Apr 6, 2018
@chingor13 chingor13 deleted the date-create-from-format branch April 6, 2018 21:38
@chingor13 chingor13 mentioned this pull request Apr 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants