Ejemplo n.º 1
0
 /**
  * この時間と指定された時間を比較します.
  *
  * この型の時間フィールドと引数の型の時間フィールドのうち,
  * 共通しているフィールド同士を比較します.
  * 
  * 引数が Peach_DT_Date を継承したオブジェクトではない場合,
  * 引数のオブジェクトに対して get("year"), get("month"), get("date") の返り値を比較対象のフィールドとします.
  * 
  * @param  Time 比較対象の時間
  * @return int  この時間のほうが過去の場合は負の値, 未来の場合は正の値, 等しい場合は 0
  * @ignore
  */
 protected function compareFields(Time $time)
 {
     $className = __CLASS__;
     if ($time instanceof $className) {
         if ($this->year !== $time->year) {
             return $this->year - $time->year;
         }
         if ($this->month !== $time->month) {
             return $this->month - $time->month;
         }
         if ($this->date !== $time->date) {
             return $this->date - $time->date;
         }
         return 0;
     } else {
         $y = $time->get("year");
         $m = $time->get("month");
         $d = $time->get("date");
         if ($this->year !== $y) {
             return isset($y) ? $this->year - $y : 0;
         }
         if ($this->month !== $m) {
             return isset($m) ? $this->month - $m : 0;
         }
         if ($this->date !== $d) {
             return isset($d) ? $this->date - $d : 0;
         }
         return 0;
     }
 }
Ejemplo n.º 2
0
 /**
  * 2つの時間オブジェクトを比較します. 一つめの引数のほうが後 (未来) の場合は正の値,
  * 前 (過去) の場合は負の値, 同じ場合は 0 を返します.
  * 
  * このメソッドは, 一つ目の時間オブジェクトの {@link Time::compareTo} メソッドを呼び出し
  * 二つ目の時間オブジェクトと比較した結果を返します.
  *
  * @param  Time $time1 1つ目の時間
  * @param  Time $time2 2つ目の時間
  * @return int         1つ目の時間を2つ目の時間と比較した結果
  * @see    Time::compareTo()
  */
 public static function compareTime(Time $time1, Time $time2)
 {
     return $time1->compareTo($time2);
 }
Ejemplo n.º 3
0
 /**
  * ラップ対象のオブジェクトの __toString メソッドを実行します.
  * @param  Time $time
  * @return string
  */
 public function __toString()
 {
     return $this->original->__toString();
 }
Ejemplo n.º 4
0
 /**
  * 指定されたパターン文字を, 対応するフィールドの値に変換します.
  * 
  * @param  Time   $d   変換対象の時間オブジェクト
  * @param  string $key パターン文字 ("Y", "m", "d" など)
  * @return int         変換結果
  * @throws \Exception  不正なパターン文字が指定された場合
  */
 private function formatKey(Time $d, $key)
 {
     $year = $d->get("year");
     $month = $d->get("month");
     $date = $d->get("date");
     $hour = $d->get("hour");
     $min = $d->get("minute");
     $sec = $d->get("second");
     switch ($key) {
         case "Y":
             return str_pad($year, 4, "0", STR_PAD_LEFT);
         case "m":
             return str_pad($month, 2, "0", STR_PAD_LEFT);
         case "n":
             return $month;
         case "d":
             return str_pad($date, 2, "0", STR_PAD_LEFT);
         case "j":
             return $date;
         case "H":
             return str_pad($hour, 2, "0", STR_PAD_LEFT);
         case "G":
             return $hour;
         case "i":
             return str_pad($min, 2, "0", STR_PAD_LEFT);
         case "f":
             return $min;
         case "s":
             return str_pad($sec, 2, "0", STR_PAD_LEFT);
         case "b":
             return $sec;
         case "E":
             return $this->dayList[$d->getDay()];
     }
     // @codeCoverageIgnoreStart
     throw new \Exception("Illegal pattern: " . $key);
     // @codeCoverageIgnoreEnd
 }