Skip to content

Instantly share code, notes, and snippets.

@nubeiro
Last active September 19, 2016 15:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nubeiro/5f754d0d80483b7eb2c8ec18231b9485 to your computer and use it in GitHub Desktop.
<?php
class timeVsDateTimeTest extends PHPUnit_Framework_TestCase
{
public function testTimeVsDateTime()
{
$timeZone = "Europe/Madrid";
ini_set('date.timezone', $timeZone); // otherwise next assertion won't pass.
date_default_timezone_set($timeZone);
$maybeUtc = time();
$this->assertEquals(
$maybeUtc,
(new DateTime("@$maybeUtc", new DateTimeZone($timeZone)))->format('U'),
'this should pass, formatting to U seems to take care of timezone diff'
);
$this->assertEquals(
date('H:i:s', $maybeUtc),
(new DateTime("@$maybeUtc", new DateTimeZone($timeZone)))->format('H:i:s'),
'this will not pass, will return different hours.'
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment