コード例 #1
0
ファイル: HttpDateFormat.php プロジェクト: trashtoy/peach2
 /**
  * HTTP-date 形式のフォーマットを Timestamp に変換します.
  * 
  * @param  string $format            HTTP-date 形式の文字列
  * @return Timestamp                 変換結果
  * @throws \InvalidArgumentException フォーマットが不正な場合
  */
 public function parseTimestamp($format)
 {
     $temp_date = array();
     if (preg_match("/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), ([0-3][0-9]) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ([0-9]{4}) ([0-2][0-9]):([0-5][0-9]):([0-5][0-9]) GMT\$/", $format, $temp_date)) {
         $date["hour"] = $temp_date[5];
         $date["minute"] = $temp_date[6];
         $date["second"] = $temp_date[7];
         $date["month"] = $this->parseMonthDescription($temp_date[3]);
         $date["day"] = $temp_date[2];
         $date["year"] = $temp_date[4];
     } else {
         if (preg_match("/^(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), ([0-3][0-9])-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-([0-9]{2}) ([0-2][0-9]):([0-5][0-9]):([0-5][0-9]) GMT\$/", $format, $temp_date)) {
             $date["hour"] = $temp_date[5];
             $date["minute"] = $temp_date[6];
             $date["second"] = $temp_date[7];
             $date["month"] = $this->parseMonthDescription($temp_date[3]);
             $date["day"] = $temp_date[2];
             $date["year"] = $this->getFullYear($temp_date[4]);
         } else {
             if (preg_match("/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ([0-3 ][0-9]) ([0-2][0-9]):([0-5][0-9]):([0-5][0-9]) ([0-9]{4})\$/", $format, $temp_date)) {
                 $date["hour"] = $temp_date[4];
                 $date["minute"] = $temp_date[5];
                 $date["second"] = $temp_date[6];
                 $date["month"] = $this->parseMonthDescription($temp_date[2]);
                 // 日が1桁の場合先、半角スペースを0に置換
                 $date["day"] = str_replace(" ", "0", $temp_date[3]);
                 // 定義済みの月の名前を数字に変換する
                 $date["year"] = $temp_date[7];
             } else {
                 $this->throwFormatException($format);
             }
         }
     }
     $parsed = new Timestamp($date["year"], $date["month"], $date["day"], $date["hour"], $date["minute"], $date["second"]);
     return $parsed->add("minute", -$this->internalOffset);
 }