Пример #1
0
 public function testMake()
 {
     $time = new CTime(0);
     $this->assertTrue($time->toStringUtc(CTime::PATTERN_MYSQL)->equals("1970-01-01 00:00:00"));
     $time = new CTime(1234567890);
     $this->assertTrue($time->toStringUtc(CTime::PATTERN_MYSQL)->equals("2009-02-13 23:31:30"));
     $time = new CTime(-1234567890);
     $this->assertTrue($time->toStringUtc(CTime::PATTERN_MYSQL)->equals("1930-11-18 00:28:30"));
     $time = new CTime(1234567890, 250);
     $this->assertTrue($time->toStringUtc(CTime::PATTERN_MYSQL)->equals("2009-02-13 23:31:30") && $time->FTime() === 1234567890.25 && $time->UTime() === 1234567890 && $time->MTime() === 250);
     $time = new CTime(-1234567890, -250);
     $this->assertTrue($time->toStringUtc(CTime::PATTERN_MYSQL)->equals("1930-11-18 00:28:30") && $time->FTime() === -1234567890.25 && $time->UTime() === -1234567890 && $time->MTime() === -250);
 }
Пример #2
0
 protected static function shiftTimeInTimeZone(CTime $time, $timeUnit, $quantity, $timeZone)
 {
     $units;
     switch ($timeUnit) {
         case self::SECOND:
             $units = "seconds";
             break;
         case self::MINUTE:
             $units = "minutes";
             break;
         case self::HOUR:
             $units = "hours";
             break;
         case self::DAY:
             $units = "days";
             break;
         case self::WEEK:
             $units = "weeks";
             break;
         case self::MONTH:
             $units = "months";
             break;
         case self::YEAR:
             $units = "years";
             break;
         default:
             assert('false', vs(isset($this), get_defined_vars()));
             break;
     }
     $dt = new DateTime();
     $dt->setTimestamp($time->UTime());
     $dt->setTimezone(is_cstring($timeZone) ? new DateTimeZone($timeZone) : $timeZone->DTimeZone());
     $sign = $quantity < 0 ? "-" : "+";
     $absQty = CString::fromInt(CMathi::abs($quantity));
     $dt->modify("{$sign}{$absQty} {$units}");
     $UTime = $dt->getTimestamp();
     $MTime = $time->MTime();
     if ($UTime != 0 && $MTime != 0 && CMathi::sign($UTime) != CMathi::sign($MTime)) {
         if ($UTime < 0) {
             // $MTime > 0
             $UTime++;
             $MTime -= 1000;
         } else {
             // $MTime < 0
             $UTime--;
             $MTime += 1000;
         }
     }
     return new self($UTime, $MTime);
 }
Пример #3
0
 /**
  * Sets the declarative time when a message was sent.
  *
  * @param  CTime $time The point in time to be declared as the moment of the message's dispatching.
  *
  * @return void
  */
 public function setTime(CTime $time)
 {
     assert('isset($this->m_swiftMessage)', vs(isset($this), get_defined_vars()));
     $this->m_swiftMessage->setDate($time->UTime());
 }
Пример #4
0
 /**
  * Formats a point in time as a string in a specified time zone according to a specified pattern and the formatting
  * rules used in the default or some other locale and returns the formatted string.
  *
  * The formatting patterns that you can use to format a point in time with this method are described in
  * [Date Format Patterns](http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns) of the Unicode
  * Technical Standard #35.
  *
  * @param  CTime $time The point in time to be formatted.
  * @param  CTimeZone $timeZone The time zone in which the components in the resulting string are to appear.
  * @param  string $pattern The formatting pattern.
  * @param  CULocale $inLocale **OPTIONAL. Default is** *the application's default locale*. The locale in which the
  * point in time is to be formatted.
  *
  * @return CUStringObject A string with the formatted point in time.
  */
 public static function timeWithPattern(CTime $time, CTimeZone $timeZone, $pattern, CULocale $inLocale = null)
 {
     assert('is_cstring($pattern)', vs(isset($this), get_defined_vars()));
     $locale = isset($inLocale) ? $inLocale->name() : CULocale::defaultLocaleName();
     $intlDateFormatter = new IntlDateFormatter($locale, IntlDateFormatter::FULL, IntlDateFormatter::FULL, $timeZone->ITimeZone(), null, $pattern);
     $strTime = $intlDateFormatter->format($time->UTime());
     if (is_cstring($strTime)) {
         return $strTime;
     } else {
         assert('false', vs(isset($this), get_defined_vars()));
         return "";
     }
 }
Пример #5
0
 /**
  * Sets the point in time after which a cookie should be considered expired, as a known moment.
  *
  * @param  CTime $time The point in time when the cookie should expire.
  *
  * @return void
  */
 public function setExpireTime(CTime $time)
 {
     $this->m_expireUTime = $time->UTime();
 }