Created
March 19, 2014 16:18
-
-
Save h4cc/9645320 to your computer and use it in GitHub Desktop.
PHPUnit assertDatesAreEqual assertion.
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 | |
/** | |
* Check if two dates are "almost" equal. | |
* | |
* @param \DateTime $date1 | |
* @param \DateTime $date2 | |
* @param int $maxDiffSeconds | |
*/ | |
public function assertDatesAreEqual(\DateTime $date1, \DateTime $date2, $maxDiffSeconds=59) | |
{ | |
$interval = $date1->getTimestamp() - $date2->getTimestamp(); | |
$this->assertLessThanOrEqual($maxDiffSeconds, abs($interval), "Dates differ by $interval seconds."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment