/** * 引数のフィールドを, $amount だけ増加 (負の場合は減少) させます. * @param string $field 対象のフィールド * @param int $amount 加算する量. マイナスの場合は過去方向に移動する. * @return Time 設定後の時間オブジェクト */ public final function add($field, $amount) { $newFields = new ArrayMap($this->fields); $key = $this->getFieldIndex($field); $current = $this->fields->get($key); $newFields->put($key, $current + $amount); return $this->newInstance($newFields); }
/** * 指定された値の繰り下がり処理を行います. * この関数は Time::adjust() から呼び出されます. * * @param Map $fields 調整対象のフィールド一覧 * @ignore */ public function moveDown(Map $fields) { $key = $this->key; $upperKey = $this->upperKey; $max = $this->max; $min = $this->min; $field = $fields->get($key); $upperField = $fields->get($upperKey); $range = $max - $min + 1; $amount = intval(($min - $field - 1) / $range) + 1; $fields->put($upperKey, $upperField - $amount); $fields->put($key, $max - ($min - $field - 1) % $range); }
/** * (non-PHPdoc) * @return Date * @see Time::newInstance * @ignore */ protected function newInstance(Map $fields) { $year = $fields->get(self::$YEAR); $month = $fields->get(self::$MONTH); $date = $fields->get(self::$DATE); return new self($year, $month, $date); }
/** * 指定された属性の値を返します. * 属性が存在しないか, 値の省略された属性の場合は NULL を返します. * 属性が存在しているかどうかを調べる場合は * {@link Element::hasAttribute()} * を使用してください. * * @param string $name 属性名 * @return string 属性の値. 存在しないか, 値の省略された属性の場合は NULL */ public function getAttribute($name) { return $this->attributes->get($name); }
/** * (non-PHPdoc) * @see Time::newInstance() * @ignore */ protected function newInstance(Map $fields) { $year = $fields->get(self::$YEAR); $month = $fields->get(self::$MONTH); $date = $fields->get(self::$DATE); $hour = $fields->get(self::$HOUR); $min = $fields->get(self::$MINUTE); $sec = $fields->get(self::$SECOND); return new self($year, $month, $date, $hour, $min, $sec); }