Merge pull request #4552 from giant-rabbit/preprocess-hook
[civicrm-core.git] / CRM / Utils / Time.php
index c424fb942e0ced1706d3bb8c51728bbaa2f68995..a70ad242676ea86fb0dfe454b935b4216ce5f7b2 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -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);
+  }
 }