Skip to content

Commit

Permalink
php date parse functions fixed milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
insky committed Jun 5, 2018
1 parent efbde36 commit 9b26353
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions php/Exchange.php
Expand Up @@ -512,6 +512,9 @@ public static function parse8601 ($timestamp) {
if ($time === false)
return null;
$time *= 1000;
if (preg_match ('/\.(?<milliseconds>[0-9]{1,3})/', $timestamp, $match)) {
$time += (int) str_pad($match['milliseconds'], 3, '0', STR_PAD_RIGHT);
}
return $time;
}

Expand Down
1 change: 1 addition & 0 deletions php/test/ExchangeTest.php
Expand Up @@ -180,5 +180,6 @@ public function testDatetimeFunctions () {
$this->assertSame (514848227000, Exchange::parse_date ('1986-04-26T01:23:47+04:00'));
$this->assertSame (514848227000, Exchange::parse_date ('25 Apr 1986 21:23:47 GMT'));
$this->assertSame (514862627000, Exchange::parse_date ('1986-04-26T01:23:47.000Z'));
$this->assertSame (514862627123, Exchange::parse_date ('1986-04-26T01:23:47.123Z'));
}
}

0 comments on commit 9b26353

Please sign in to comment.