Last active
September 19, 2016 15:02
-
-
Save nubeiro/5f754d0d80483b7eb2c8ec18231b9485 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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