/** * 年・月・日・時・分・秒の各フィールドからハッシュ値を算出します. * * @param mixed $var * @return int ハッシュ値 * @throws \InvalidArgumentException 引数が Time インスタンスでなかった場合 */ public function hashCode($var) { if (!$var instanceof Time) { $type = Values::getType($var); throw new \InvalidArgumentException("The value must be Time instance.({$type})"); } return $var->get("year") + $var->get("month") * 31 + $var->get("date") * 961 + $var->get("hour") * 29791 + $var->get("minute") * 923521 + $var->get("second") * 28629151; // 31^5 }
/** * この時間オブジェクトの複数のフィールドを一度に上書きします. * 引数には, * <code> * array("year" => 2010, "month" => 8, "date" => 31) * </code> * などの配列か, または同様の Map オブジェクトを指定してください. * * @param Map|array $subject フィールドと値の一覧 * @return Time 設定後の時間オブジェクト * @throws \InvalidArgumentException 引数の型が不正な場合 */ public final function setAll($subject) { if (is_array($subject)) { $subject = new ArrayMap($subject); } if (!$subject instanceof Map) { throw new \InvalidArgumentException("Argument (" . Values::getType($subject) . ") must be array or \\Peach\\Util\\Map"); } $newFields = new ArrayMap($this->fields); $entryList = $subject->entryList(); foreach ($entryList as $entry) { $index = $this->getFieldIndex($entry->getKey()); $newFields->put($index, $entry->getValue()); } return $this->newInstance($newFields); }