Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/time/PhabricatorTime.php
| Show All 19 Lines | self::$stack[] = array( | ||||
| 'timezone' => $timezone, | 'timezone' => $timezone, | ||||
| ); | ); | ||||
| return new PhabricatorTimeGuard(last_key(self::$stack)); | return new PhabricatorTimeGuard(last_key(self::$stack)); | ||||
| } | } | ||||
| public static function popTime($key) { | public static function popTime($key) { | ||||
| if ($key !== last_key(self::$stack)) { | if ($key !== last_key(self::$stack)) { | ||||
| throw new Exception('PhabricatorTime::popTime with bad key.'); | throw new Exception( | ||||
| pht( | |||||
| '%s with bad key.', | |||||
| __METHOD__)); | |||||
| } | } | ||||
| array_pop(self::$stack); | array_pop(self::$stack); | ||||
| if (empty(self::$stack)) { | if (empty(self::$stack)) { | ||||
| date_default_timezone_set(self::$originalZone); | date_default_timezone_set(self::$originalZone); | ||||
| } else { | } else { | ||||
| $frame = end(self::$stack); | $frame = end(self::$stack); | ||||
| date_default_timezone_set($frame['timezone']); | date_default_timezone_set($frame['timezone']); | ||||
| } | } | ||||
| } | } | ||||
| public static function getNow() { | public static function getNow() { | ||||
| if (self::$stack) { | if (self::$stack) { | ||||
| $frame = end(self::$stack); | $frame = end(self::$stack); | ||||
| return $frame['epoch']; | return $frame['epoch']; | ||||
| } | } | ||||
| return time(); | return time(); | ||||
| } | } | ||||
| public static function parseLocalTime($time, PhabricatorUser $user) { | public static function parseLocalTime($time, PhabricatorUser $user) { | ||||
| $old_zone = date_default_timezone_get(); | $old_zone = date_default_timezone_get(); | ||||
| date_default_timezone_set($user->getTimezoneIdentifier()); | date_default_timezone_set($user->getTimezoneIdentifier()); | ||||
| $timestamp = (int)strtotime($time, PhabricatorTime::getNow()); | $timestamp = (int)strtotime($time, self::getNow()); | ||||
| if ($timestamp <= 0) { | if ($timestamp <= 0) { | ||||
| $timestamp = null; | $timestamp = null; | ||||
| } | } | ||||
| date_default_timezone_set($old_zone); | date_default_timezone_set($old_zone); | ||||
| return $timestamp; | return $timestamp; | ||||
| } | } | ||||
| Show All 12 Lines | |||||