Use DateTime::createFromFormat by chingor13 · Pull Request #168 · census-instrumentation/opencensus-php · GitHub
Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Use DateTime::createFromFormat#168

Merged
chingor13 merged 1 commit into
census-instrumentation:masterfrom
chingor13:date-create-from-format
Apr 6, 2018
Merged

Use DateTime::createFromFormat#168
chingor13 merged 1 commit into
census-instrumentation:masterfrom
chingor13:date-create-from-format

Conversation

@chingor13

@chingor13 chingor13 commented Apr 6, 2018

Copy link
Copy Markdown
Member

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
Copy Markdown

@chingor13

Copy link
Copy Markdown
Member Author

@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