value) { // Keep the duration in seconds as there is generally no valid way to // convert it to days, months or years. return new \DateInterval('PT' . $this->value . 'S'); } } /** * {@inheritdoc} */ public function setDuration(\DateInterval $duration, $notify = TRUE) { // Note that this applies the assumption of 12 month's a 30 days and // each year having 365 days. There is no accurate conversion for time spans // exceeding a day. $this->value = ($duration->y * 365 * 24 * 60 * 60) + ($duration->m * 30 * 24 * 60 * 60) + ($duration->d * 24 * 60 * 60) + ($duration->h * 60 * 60) + ($duration->i * 60) + $duration->s; // Notify the parent of any changes. if ($notify && isset($this->parent)) { $this->parent->onChange($this->name); } } }