Created
September 13, 2012 21:53
-
-
Save sarahhenkens/3717980 to your computer and use it in GitHub Desktop.
Assert to test that 2 time's are equal to each other within a margin of x seconds
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
/** | |
* Assert that 2 datetime strings are equal within a margin | |
* | |
* @param string $expected | |
* @param string $result | |
* @param integer $margin The margin in seconds | |
* @param string $message optional message | |
* @return boolean | |
*/ | |
public function assertDateEquals($expected, $result, $margin = 1, $message = '') { | |
$expectedTime = strtotime($expected); | |
$resultTime = strtotime($result); | |
$upper = $expectedTime + $margin; | |
$lower = $expectedTime - $margin; | |
if (!$message) { | |
$message = sprintf('Failed asserting that %s is equal to %s within a margin of %d seconds', $result, $expected, $margin); | |
} | |
return self::assertTrue((($resultTime <= $upper) && ($resultTime >= $lower)), $message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment