@param DateTimeOfDay $end
@param Duration $duration

@return static
517703
public static function createFromEndAndDuration(DateTimeOfDay $end, Duration $duration)
    {
        return static::create($end->sub($duration), $end);
    }
1092075
public static DayDuration valueOf(String duration) {
		int spacePos = duration.indexOf(' ');
		if(spacePos == -1) throw new IllegalArgumentException("Space not found in duration: " + duration);
		return getInstance(
			Integer.parseInt(duration.substring(0, spacePos)),
			Unit.valueOfUnit(duration.substring(spacePos + 1))
		);
	}
802286
public function calcDurationBasedOnEndDateTime($end)
    {
        $startDate = strtotime($this->StartDateTime);
        $endDate = strtotime($end);

        $duration = $endDate - $startDate;
        $secsInDay = 60 * 60 * 24;
        if ($duration > $secsInDay) {
            //Duration cannot be more than 24h
            return false;
        }

        //info on this calculation here:
        //http://stackoverflow.com/questions/3856293/how-to-convert-seconds-to-time-format
        $formatDate = gmdate("H:i", $duration);

        return $formatDate;
    }
318093
public function setDuration($duration)
    {
        if (is_null($duration)) {
            unset($this->_headers['content-duration']);
        } else {
            if (!($hdr = $this->_headers['content-duration'])) {
                $hdr = new Horde_Mime_Headers_Element_Single(
                    'Content-Duration',
                    ''
                );
                $this->_headers->addHeaderOb($hdr);
            }
            $hdr->setValue($duration);
        }
    }
405352
public function setDates($start, $end)
    {
        $this->setStartDate($start);
        $this->setEndDate($end);

        return $this;
    }
984115
public function setDateEnd(\DateTime $date_end = null)
    {
        $this->date_end = $date_end ? clone $date_end : null;

        return $this;
    }
243082
public function getTodayActivityTotal($duration = null)
    {
        $total = User::getDb()->cache(function ($db) {
            return User::find()->joinWith(['extend' => function (ActiveQuery $query) {
                $query->where(['between', '{{%user_extend}}.login_at', DateHelper::todayFirstSecond(), DateHelper::todayLastSecond()]);
            }])->count();
        }, $duration);
        return $total;
    }
1276422
public static DateValue add(DateValue date, DateValue duration) {
		DTBuilder db = new DTBuilder(date);
		db.year += duration.year();
		db.month += duration.month();
		db.day += duration.day();
		if (duration instanceof TimeValue) {
			TimeValue tdur = (TimeValue) duration;
			db.hour += tdur.hour();
			db.minute += tdur.minute();
			db.second += tdur.second();
			return db.toDateTime();
		}
		return (date instanceof TimeValue) ? db.toDateTime() : db.toDate();
	}
941956
protected function getMinutes($duration)
    {
        if ($duration instanceof DateTime) {
            $duration = (time()-$duration->getTimestamp()) / 60;
        }

        return (int) ($duration * 60) > 0 ? $duration : null;
    }
1027636
public function endOfWeek(\DateTime $datetime)
	{
		$diffInDays = 7 - intval($datetime->format('N'));
		$intervalSpec = sprintf('P%sD', $diffInDays);

		$datetime->add(new \DateInterval($intervalSpec));
	}
639480
public function intervalDays($end = null)
    {
        $start    = $this->createDateUTC($this->toDateString());
        $end      = $this->createDateUTC($end ? $end->toDateString() : date(static::DATE_STR));
        $interval = $start->diff($end);

        return $interval->format('%r%a');
    }
554575
public function Sub( $duration )
	{
		if ( ! $duration instanceof DurationValue )
		{
			throw new \InvalidArgumentException();
		}

		$duration->Value->invert = ! $duration->Value->invert;
		$this->Add( $duration );

		// // Finally convert $multipliedInterval into a normalized interval
		// /**
		//  * @var \DateTime $dt
		//  */
		// $dt = new \DateTimeImmutable( "2017-06-07" );
		// /**
		//  * @var \DateTime $added
		//  */
		// $added = $dt->add( $this->Value );
		// $duration->Value->invert = ! $duration->Value->invert;
		// /**
		//  * @var \DateTime $subtracted
		//  */
		// $subtracted = $added->add( $duration->Value );
		// /**
		//  * @var \DateInterval $diff
		//  */
		// $diff = $subtracted->diff( $dt );
		// $diff->invert = $diff->days == 0 ? false : ! $diff->invert;
        //
		// $this->Value = $diff;
	}
58564
public function withDuration($duration)
    {
        Assertion::integer($duration);
        Assertion::greaterThan($duration, VideoInterface::DURATION_LOWER_LIMIT);
        Assertion::lessThan($duration, VideoInterface::DURATION_UPPER_LIMIT);

        $instance = clone $this;

        $instance->duration = $duration;

        return $instance;
    }
433458
public TimerType<T> end(java.util.Date end)
   {
      if (end != null)
      {
         childNode.getOrCreate("end").text(XMLDate.toXMLFormat(end));
         return this;
      }
      return null;
   }
236719
public function between(DateTime $start, DateTime $end) {
        $this->start($start)
                ->end($end);

        return $this;
    }
115345
public function Add( $duration )
	{
		if ( ! $duration instanceof DurationValue )
		{
			throw new \InvalidArgumentException();
		}

		$thisSeconds = $this->getTotalSeconds();
		$durationSeconds = $duration->getTotalSeconds();

		/**
		 * @var DecimalValue $interval
		 */
		$interval = $thisSeconds->Add( $durationSeconds );
		$hasValue = 0 > $interval->CompareTo( 0 ) != 0;
		$invert = 0 > $interval->CompareTo( 0 ) == -1;

		if ( ! $hasValue )
		{
			$di = new \DateInterval( $this->ZeroStringValue() );
			$di->hasValue = false;
			$di->microseconds = 0;
			return $di;
		}

		$di = new \DateInterval( "PT{$interval->getAbs()->getIntegerPart()}S" );

		// Normalize
		$dt = new \DateTimeImmutable();
		$diff = $dt->add( $di );
		$diff = $diff->diff( $dt );
		$diff->hasValue = true;
		$diff->invert = $invert;
		$diff->microseconds = $interval->getDecimalPart() + 0;
		// if ( $hasValue ) $this->type = XPATH20_DURATION_TYPE_DAYTIME;
		$this->Value = $diff;
	}
1071847
public static function createFromStartEndDuration(CalendarDate $start, CalendarDate $end, Duration $duration)
    {
        return static::create($start, $end, $duration, null);
    }