Skip to content

Instantly share code, notes, and snippets.

@marijn
Created April 8, 2012 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marijn/2340257 to your computer and use it in GitHub Desktop.
Save marijn/2340257 to your computer and use it in GitHub Desktop.
<?php
class DateTimeTest extends PHPUnit_Framework_TestCase
{
private $dateTimeZone;
public function setUp()
{
$this->dateTimeZone = new DateTimeZone("UTC");
}
public function tearDown()
{
$this->dateTimeZone = null;
}
public function testCreateDateTimeForNowWithMilliSeconds()
{
$microtime = sprintf('%.f', microtime(true));
$composed = DateTime::createFromFormat('U.u', $microtime, $this->dateTimeZone);
$expected = new DateTime('now', $this->dateTimeZone);
foreach (array('Y', 'm', 'd', 'H', 'i', 's') as $modifier) {
$this->assertEquals($expected->format($modifier), $composed->format($modifier));
}
$this->assertEquals($composed->format('U.u'), $microtime);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment