Last active
March 3, 2016 17:14
-
-
Save macghriogair/5321aa26899a866a78f1 to your computer and use it in GitHub Desktop.
custom datetime class
This file contains 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 | |
namespace Acme; | |
class DateTimeTest extends \PHPUnit_Framework_TestCase | |
{ | |
/** @test */ | |
public function it_creates_from_unix_timestamp() | |
{ | |
$unix = time(); | |
$acmeDate = new AcmeDateTime($unix); | |
$standardDate = new \DateTime("@".$unix); | |
$this->assertEquals($acmeDate, $standardDate); | |
} | |
/** @test */ | |
public function it_creates_from_datestring() | |
{ | |
$dateString = '2016/03/03'; | |
$acmeDate = new AcmeDateTime($dateString); | |
$standardDate = new \DateTime($dateString); | |
$this->assertEquals($acmeDate, $standardDate); | |
} | |
} | |
class AcmeDateTime extends \DateTime | |
{ | |
public function __construct($time = "now", DateTimeZone $timezone = null) | |
{ | |
$time = is_numeric($time) ? "@" . $time : $time; | |
parent::__construct($time, $timezone); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment