/*[deutsch]
<p>Konvertiert ein beliebiges Datumsintervall zu einem Intervall dieses Typs. </p>

@param   interval    any kind of date interval
@return  DateInterval
@since   3.28/4.24
5002
public static DateInterval from(ChronoInterval<PlainDate> interval) {

        if (interval instanceof DateInterval) {
            return DateInterval.class.cast(interval);
        } else {
            return new DateInterval(interval.getStart(), interval.getEnd());
        }

    }
1155235
private function get_interval(string $interval = '')
  {
    if ( !empty($interval) ){
      $this->interval = new \DateInterval($interval);
      return $this->interval;
    }
    else {
      return $this->interval;
    }
  }
806432
public Interval intervalTo(TrieNode toNode) {
    return new Interval(toNode.getCursorIndex() - this.getCursorIndex(),
      toNode.getCursorCount(), this.getCursorCount());
  }
1036669
public int getIntervalDays( HexaDate other )
	{
		long interval = other.getJavaDate().getTime() - getJavaDate().getTime();
		int res = (int) (interval / 86400000);
		return res;
	}
963945
public static CalendarInterval fromDayTimeString(String s) throws IllegalArgumentException {
    CalendarInterval result = null;
    if (s == null) {
      throw new IllegalArgumentException("Interval day-time string was null");
    }
    s = s.trim();
    Matcher m = dayTimePattern.matcher(s);
    if (!m.matches()) {
      throw new IllegalArgumentException(
        "Interval string does not match day-time format of 'd h:m:s.n': " + s);
    } else {
      try {
        int sign = m.group(1) != null && m.group(1).equals("-") ? -1 : 1;
        long days = toLongWithRange("day", m.group(2), 0, Integer.MAX_VALUE);
        long hours = toLongWithRange("hour", m.group(3), 0, 23);
        long minutes = toLongWithRange("minute", m.group(4), 0, 59);
        long seconds = toLongWithRange("second", m.group(5), 0, 59);
        // Hive allow nanosecond precision interval
        long nanos = toLongWithRange("nanosecond", m.group(7), 0L, 999999999L);
        result = new CalendarInterval(0, sign * (
          days * MICROS_PER_DAY + hours * MICROS_PER_HOUR + minutes * MICROS_PER_MINUTE +
          seconds * MICROS_PER_SECOND + nanos / 1000L));
      } catch (Exception e) {
        throw new IllegalArgumentException(
          "Error parsing interval day-time string: " + e.getMessage(), e);
      }
    }
    return result;
  }
835047
public Interval withStartDateTime(LocalDateTime dateTime) {
        requireNonNull(dateTime);
        return new Interval(dateTime.toLocalDate(), dateTime.toLocalTime(), endDate, endTime);
    }
258422
public String interval(Date target) {
		double unit = 1000.0D;
		double dayUnit = DAY / unit;
		double hourUnit = HOUR / unit;
		double minUnit = MINUTE / unit;
		double interval = sinceMillis(target) / unit;
		IntervalDesc desc = theIntervalDesc.get();
		
		if (interval >= 0.0D) {
			if (interval / (12 * 30 * dayUnit) > 1.0D) {
				return asText(target);
			}
			if (interval / (30 * dayUnit) > 1.0D) {
				return String.format("%s%s", (int) (interval / (30 * dayUnit)), desc.getMonthAgo());
			}
			if (interval / (7 * dayUnit) > 1.0D) {
				return String.format("7%s", desc.getDayAgo());
			}
			if ((interval / (7 * dayUnit) <= 1.0D) && (interval / dayUnit >= 1.0D)) {
				return String.format("%s%s", (int) (interval / dayUnit), desc.getDayAgo());
			}
			if ((interval / dayUnit < 1.0D) && (interval / hourUnit >= 1.0D)) {
				return String.format("%s%s", (int) (interval / hourUnit), desc.getHourAgo());
			}
			if ((interval < hourUnit) && (interval >= minUnit)) {
				return String.format("%s%s", (int) (interval / minUnit), desc.getMinuteAgo());
			}
			
			return desc.getJustNow();
		}
		
		return asText(target);
	}
1138768
protected function dateIntervalToSeconds($interval): int
    {
        $now = time();
        $dt = new \DateTime();
        $dt->add($interval);
        $ts = $dt->getTimestamp();
        $diff = $ts - $now;
        return $diff;
    }
1050846
public Interval withEndDate(LocalDate date) {
        requireNonNull(date);
        return new Interval(startDate, startTime, date, endTime, zoneId);
    }
380861
public static function totalSeconds(DateInterval $interval)
    {
        $sYears = 31536000 * $interval->y;
        $sMonths = 30 * 24 * 3600 * $interval->m;
        $sDays = 24 * 3600 * $interval->d;
        $sHours = 3600 * $interval->h;
        $sMinutes = 60 * $interval->i;
        $sSeconds = $interval->s;

        $total = $sYears + $sMonths + $sDays + $sHours + $sMinutes + $sSeconds;

        return ($interval->invert === 1) ? $total * -1 : $total;
    }
499788
public static Interval reverseOrder(Interval i) {
		return new Interval(i.getLabel(), i.getQuality(), (byte) -i.getDirection());
	}
989474
public Interval toInterval() {
        DateTimeField field = getField();
        long start = field.roundFloor(getMillis());
        long end = field.add(start, 1);
        Interval interval = new Interval(start, end, getChronology());
        return interval;
    }
25562
public static function getSecondsFromInterval(DateInterval $interval)
    {
        $map   = [31536000, 2592000, 86400, 3600, 60, 1];
        $parts = explode('.', $interval->format('%y.%m.%d.%h.%i.%s'));
        $value = 0;

        foreach ($parts as $key => $val) {
            $value+= $val * $map[$key];
        }

        return $value;
    }
1256377
private function parseDateInterval($interval)
    {
        try {
            if (!$this->isInstanceOf($interval, 'DateInterval')) {
                $interval = new StringObject($interval);
                if ($interval->startsWith('P')) {
                    $interval = new \DateInterval($interval);
                } else {
                    $interval = \DateInterval::createFromDateString($interval);
                }
            }
        } catch (\Exception $e) {
            throw new DateTimeObjectException(DateTimeObjectException::MSG_INVALID_DATE_INTERVAL, [$interval]);
        }

        return $interval;
    }
104304
function convertIntervalToCronTime(interval) {
  const intervalIsEmpty = interval.length === 0;
  const intervalIsTooBig = interval.length > 6;

  if (intervalIsEmpty){
    throw new Error(`The interval can not be empty`);
  } else if (intervalIsTooBig) {
    throw new Error('The interval can not contain more than 6 ranges');
  }

  const timeArray = fillInterval(interval);

  try {
    timeArray[0] = getSecond(timeArray[0]);
    timeArray[1] = getMinute(timeArray[1]);
    timeArray[2] = getHour(timeArray[2], timeArray[1]);
    timeArray[3] = getDayOfMonth(timeArray[3]);
    timeArray[4] = getMonth(timeArray[4]);
    timeArray[5] = getDayOfWeek(timeArray[5]);
  } catch (error){
    throw error;
  }

  const cronTime = `${timeArray[0]} ${timeArray[1]} ${timeArray[2]} ${timeArray[3]} ${timeArray[4]} ${timeArray[5]}`;
  return cronTime;
}
1171701
public static TimestampInterval from(ChronoInterval<PlainTimestamp> interval) {

        if (interval instanceof TimestampInterval) {
            return TimestampInterval.class.cast(interval);
        } else {
            return new TimestampInterval(interval.getStart(), interval.getEnd());
        }

    }
1280199
public static function instance(DateInterval $di)
    {
        if (self::wasCreatedFromDiff($di)) {
            throw new InvalidArgumentException('Can not instance a Interval object created from DateTime::diff().');
        }

        $instance = new static($di->y, $di->m, 0, $di->d, $di->h, $di->i, $di->s);
        $instance->invert = $di->invert;
        $instance->days = $di->days;

        return $instance;
    }