3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 class CRM_Utils_Time
{
25 * the seconds offset from the real world time
27 static private $_delta = 0;
32 * @param string $returnFormat
33 * Format in which date is to be retrieved.
37 public static function getTime($returnFormat = 'YmdHis') {
38 return date($returnFormat, self
::getTimeRaw());
47 public static function getTimeRaw() {
48 return time() + self
::$_delta;
54 * @param string $newDateTime
55 * A date formatted with strtotime.
56 * @param string $returnFormat
57 * Format in which date is to be retrieved.
61 public static function setTime($newDateTime, $returnFormat = 'YmdHis') {
62 self
::$_delta = strtotime($newDateTime) - time();
63 return self
::getTime($returnFormat);
67 * Remove any time overrides.
69 public static function resetTime() {
74 * Approximate time-comparison. $a and $b are considered equal if they
75 * are within $threshold seconds of each other.
78 * Time which can be parsed by strtotime.
80 * Time which can be parsed by strtotime.
81 * @param int $threshold
82 * Maximum allowed difference (in seconds).
85 public static function isEqual($a, $b, $threshold = 0) {
86 $diff = strtotime($b) - strtotime($a);
87 return (abs($diff) <= $threshold);