Skip to content

Commit

Permalink
from() perserves micro-seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
olvlvl committed Aug 24, 2016
1 parent 0139b25 commit 04276e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/DateTime/Shared.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static public function from($source, $timezone = null)

if ($source instanceof \DateTimeInterface)
{
return new static($source->format(self::DB), $source->getTimezone());
return new static($source->format('Y-m-d H:i:s.u'), $source->getTimezone());
}

return new static($source, $timezone);
Expand Down
4 changes: 4 additions & 0 deletions tests/AbstractDateTimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public function test_from()
$d = $this->from('2001-01-01 01:01:01');
$this->assertEquals(date_default_timezone_get(), $d->tz->name);
$this->assertEquals('2001-01-01 01:01:01', $d->as_db);

$r = new DateTime('2001-01-01 01:01:01.012345', 'Asia/Tokyo');
$d = $this->from($r);
$this->assertSame('2001-01-01 01:01:01.012345', $d->format('Y-m-d H:i:s.u'));
}

public function test_change()
Expand Down

0 comments on commit 04276e4

Please sign in to comment.