X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;ds=sidebyside;f=CRM%2FUtils%2FTime.php;h=a70ad242676ea86fb0dfe454b935b4216ce5f7b2;hb=01fc73a5788aff9892383186d4dbb674a006dbc8;hp=41aee4c25fb94069f9c31764117e1552017128e2;hpb=6643a63b47c9607cdc5f14a739cf7c7cfe55d726;p=civicrm-core.git diff --git a/CRM/Utils/Time.php b/CRM/Utils/Time.php index 41aee4c25f..a70ad24267 100644 --- a/CRM/Utils/Time.php +++ b/CRM/Utils/Time.php @@ -86,5 +86,19 @@ class CRM_Utils_Time { static function resetTime() { self::$_delta = 0; } + + /** + * Approximate time-comparison. $a and $b are considered equal if they + * are within $threshold seconds of each other. + * + * @param string $a time which can be parsed by strtotime + * @param string $b time which can be parsed by strtotime + * @param int $threshold maximum allowed difference (in seconds) + * @return bool + */ + static function isEqual($a, $b, $threshold = 0) { + $diff = strtotime($b) - strtotime($a); + return (abs($diff) <= $threshold); + } }