@js-joda/extra
Version:
additional date-time classes that complement those in js-joda
1,230 lines (1,218 loc) • 91.6 kB
JavaScript
//! @version @js-joda/extra - 0.12.3
//! @copyright (c) 2015-present, Philipp Thürwächter, Pattrick Hüper & js-joda contributors
//! @copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
//! @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@js-joda/core')) :
typeof define === 'function' && define.amd ? define(['exports', '@js-joda/core'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSJodaExtra = {}, global.JSJoda));
})(this, (function (exports, core) { 'use strict';
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
_setPrototypeOf(subClass, superClass);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
/**
* @copyright (c) 2016, Philipp Thürwächter & Pattrick Hüper
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
*/
function assert(assertion, msg, error) {
if (!assertion) {
if (error) {
throw new error(msg);
} else {
throw new Error(msg);
}
}
}
function requireNonNull(value, parameterName) {
if (value == null) {
throw new core.NullPointerException(parameterName + " must not be null");
}
return value;
}
function requireInstance(value, _class, parameterName) {
if (!(value instanceof _class)) {
throw new core.IllegalArgumentException(parameterName + " must be an instance of " + (_class.name ? _class.name : _class) + (value && value.constructor && value.constructor.name ? ", but is " + value.constructor.name : ''));
}
return value;
}
var MathUtil$6 = core._.MathUtil;
var DayOfMonth = function (_TemporalAccessor) {
_inheritsLoose(DayOfMonth, _TemporalAccessor);
DayOfMonth.now = function now(zoneIdOrClock) {
switch (arguments.length) {
case 0:
return DayOfMonth._now0();
case 1:
requireNonNull(zoneIdOrClock, 'clockOrZone');
if (zoneIdOrClock instanceof core.ZoneId) {
return DayOfMonth._nowZoneId(zoneIdOrClock);
}
if (zoneIdOrClock instanceof core.Clock) {
return DayOfMonth._nowClock(zoneIdOrClock);
}
throw new core.IllegalArgumentException("zoneIdOrClock must be an instance of ZoneId or Clock, but is " + zoneIdOrClock.constructor.name);
default:
throw new core.IllegalArgumentException("Invalid number of arguments: " + arguments.length);
}
};
DayOfMonth._now0 = function _now0() {
return this.now(core.Clock.systemDefaultZone());
};
DayOfMonth._nowZoneId = function _nowZoneId(zone) {
return this.now(core.Clock.system(zone));
};
DayOfMonth._nowClock = function _nowClock(clock) {
var now = core.LocalDate.now(clock);
return DayOfMonth.of(now.dayOfMonth());
};
DayOfMonth.of = function of(dayOfMonth) {
if (1 <= dayOfMonth && dayOfMonth <= 31) {
return DayOfMonth.VALUES[dayOfMonth - 1];
} else {
throw new core.DateTimeException("Invalid value for DayOfMonth: " + dayOfMonth);
}
};
DayOfMonth.from = function from(temporal) {
if (temporal instanceof DayOfMonth) {
return temporal;
}
requireNonNull(temporal, 'temporal');
try {
return DayOfMonth.of(temporal.get(core.ChronoField.DAY_OF_MONTH));
} catch (ex) {
throw new core.DateTimeException("Unable to obtain DayOfMonth from TemporalAccessor: " + temporal + " of type " + temporal.constructor.name, ex);
}
};
function DayOfMonth(dayOfMonth) {
var _this;
_this = _TemporalAccessor.call(this) || this;
_this._day = MathUtil$6.safeToInt(dayOfMonth);
return _this;
}
var _proto = DayOfMonth.prototype;
_proto.value = function value() {
return this._day;
};
_proto.isSupported = function isSupported(field) {
if (field instanceof core.ChronoField) {
return field === core.ChronoField.DAY_OF_MONTH;
}
return field != null && field.isSupportedBy(this);
};
_proto.range = function range(field) {
requireNonNull(field, 'field');
if (field === core.ChronoField.DAY_OF_MONTH) {
return field.range();
}
return _TemporalAccessor.prototype.range.call(this, field);
};
_proto.get = function get(field) {
return this.range(field).checkValidIntValue(this.getLong(field), field);
};
_proto.getLong = function getLong(field) {
requireNonNull(field, 'field');
if (field === core.ChronoField.DAY_OF_MONTH) {
return this._day;
} else if (field instanceof core.ChronoField) {
throw new core.UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.getFrom(this);
};
_proto.isValidYearMonth = function isValidYearMonth(yearMonth) {
return yearMonth != null && yearMonth.isValidDay(this._day);
};
_proto.query = function query(_query) {
requireNonNull(_query, 'query');
requireInstance(_query, core.TemporalQuery, 'query');
if (_query === core.TemporalQueries.chronology()) {
return core.IsoChronology.INSTANCE;
}
return _TemporalAccessor.prototype.query.call(this, _query);
};
_proto.adjustInto = function adjustInto(temporal) {
requireNonNull(temporal, 'temporal');
return temporal.with(core.ChronoField.DAY_OF_MONTH, this._day);
};
_proto.atMonth = function atMonth(month) {
requireNonNull(month, 'month');
if (month instanceof core.Month) {
return core.MonthDay.of(month, Math.min(this._day, month.maxLength()));
} else {
return core.MonthDay.of(month, Math.min(this._day, core.Month.of(month).maxLength()));
}
};
_proto.atYearMonth = function atYearMonth(yearMonth) {
requireNonNull(yearMonth, 'yearMonth');
return yearMonth.atDay(Math.min(this._day, yearMonth.lengthOfMonth()));
};
_proto.compareTo = function compareTo(other) {
requireNonNull(other, 'other');
requireInstance(other, DayOfMonth, 'other');
return this._day - other._day;
};
_proto.equals = function equals(obj) {
if (this === obj) {
return true;
}
if (obj instanceof DayOfMonth) {
return this._day === obj._day;
}
return false;
};
_proto.hashCode = function hashCode() {
return this._day;
};
_proto.toString = function toString() {
return "DayOfMonth:" + this._day;
};
return DayOfMonth;
}(core.TemporalAccessor);
function _init$8() {
DayOfMonth.VALUES = new Array(31);
for (var i = 0; i < 31; i++) {
DayOfMonth.VALUES[i] = new DayOfMonth(i + 1);
}
}
var MathUtil$5 = core._.MathUtil;
var DayOfYear = function (_TemporalAccessor) {
_inheritsLoose(DayOfYear, _TemporalAccessor);
DayOfYear.now = function now(zoneIdOrClock) {
switch (arguments.length) {
case 0:
return DayOfYear._now0();
case 1:
requireNonNull(zoneIdOrClock, 'clockOrZone');
if (zoneIdOrClock instanceof core.ZoneId) {
return DayOfYear._nowZoneId(zoneIdOrClock);
}
if (zoneIdOrClock instanceof core.Clock) {
return DayOfYear._nowClock(zoneIdOrClock);
}
throw new core.IllegalArgumentException("zoneIdOrClock must be an instance of ZoneId or Clock, but is " + zoneIdOrClock.constructor.name);
default:
throw new core.IllegalArgumentException("Invalid number of arguments: " + arguments.length);
}
};
DayOfYear._now0 = function _now0() {
return DayOfYear.now(core.Clock.systemDefaultZone());
};
DayOfYear._nowZoneId = function _nowZoneId(zone) {
return DayOfYear.now(core.Clock.system(zone));
};
DayOfYear._nowClock = function _nowClock(clock) {
var now = core.LocalDate.now(clock);
return DayOfYear.of(now.dayOfYear());
};
DayOfYear.of = function of(dayOfYear) {
if (1 <= dayOfYear && dayOfYear <= 366) {
return DayOfYear.VALUES[dayOfYear - 1];
} else {
throw new core.DateTimeException("Invalid value for DayOfYear: " + dayOfYear);
}
};
DayOfYear.from = function from(temporal) {
requireNonNull(temporal, 'temporal');
requireInstance(temporal, core.TemporalAccessor, 'temporal');
if (temporal instanceof DayOfYear) {
return temporal;
}
try {
return DayOfYear.of(temporal.get(core.ChronoField.DAY_OF_YEAR));
} catch (ex) {
throw new core.DateTimeException("Unable to obtain DayOfYear from TemporalAccessor: " + temporal + " of type " + temporal.constructor.name, ex);
}
};
function DayOfYear(dayOfYear) {
var _this;
_this = _TemporalAccessor.call(this) || this;
_this._day = MathUtil$5.safeToInt(dayOfYear);
return _this;
}
var _proto = DayOfYear.prototype;
_proto.value = function value() {
return this._day;
};
_proto.isSupported = function isSupported(field) {
if (field instanceof core.ChronoField) {
return field === core.ChronoField.DAY_OF_YEAR;
}
return field != null && field.isSupportedBy(this);
};
_proto.range = function range(field) {
requireNonNull(field, 'field');
if (field === core.ChronoField.DAY_OF_YEAR) {
return field.range();
}
return _TemporalAccessor.prototype.range.call(this, field);
};
_proto.get = function get(field) {
return this.range(field).checkValidIntValue(this.getLong(field), field);
};
_proto.getLong = function getLong(field) {
requireNonNull(field, 'field');
if (field === core.ChronoField.DAY_OF_YEAR) {
return this._day;
} else if (field instanceof core.ChronoField) {
throw new core.UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return field.getFrom(this);
};
_proto.isValidYear = function isValidYear(year) {
return this._day < 366 || core.Year.isLeap(year);
};
_proto.query = function query(_query) {
requireNonNull(_query, 'query');
requireInstance(_query, core.TemporalQuery, 'query');
if (_query === core.TemporalQueries.chronology()) {
return core.IsoChronology.INSTANCE;
}
return _TemporalAccessor.prototype.query.call(this, _query);
};
_proto.adjustInto = function adjustInto(temporal) {
requireNonNull(temporal, 'temporal');
return temporal.with(core.ChronoField.DAY_OF_YEAR, this._day);
};
_proto.atYear = function atYear(year) {
requireNonNull(year, 'year');
if (year instanceof core.Year) {
return year.atDay(this._day);
} else {
return core.LocalDate.ofYearDay(year, this._day);
}
};
_proto.compareTo = function compareTo(other) {
requireNonNull(other, 'other');
requireInstance(other, DayOfYear, 'other');
return this._day - other._day;
};
_proto.equals = function equals(obj) {
if (this === obj) {
return true;
}
if (obj instanceof DayOfYear) {
return this._day === obj._day;
}
return false;
};
_proto.hashCode = function hashCode() {
return this._day;
};
_proto.toString = function toString() {
return "DayOfYear:" + this._day;
};
return DayOfYear;
}(core.TemporalAccessor);
function _init$7() {
DayOfYear.VALUES = new Array(366);
for (var i = 0; i < 366; i++) {
DayOfYear.VALUES[i] = new DayOfYear(i + 1);
}
}
/*
* @copyright (c) 2016, Philipp Thürwächter & Pattrick Hüper
* @copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
*/
var Interval = function () {
Interval.of = function of(startInstant, endInstantOrDuration) {
if (endInstantOrDuration instanceof core.Duration) {
return Interval.ofInstantDuration(startInstant, endInstantOrDuration);
} else {
return Interval.ofInstantInstant(startInstant, endInstantOrDuration);
}
};
Interval.ofInstantInstant = function ofInstantInstant(startInclusive, endExclusive) {
requireNonNull(startInclusive, 'startInclusive');
requireNonNull(endExclusive, 'endExclusive');
requireInstance(startInclusive, core.Instant, 'startInclusive');
requireInstance(endExclusive, core.Instant, 'endExclusive');
if (endExclusive.isBefore(startInclusive)) {
throw new core.DateTimeException('End instant must on or after start instant');
}
return new Interval(startInclusive, endExclusive);
};
Interval.ofInstantDuration = function ofInstantDuration(startInclusive, duration) {
requireNonNull(startInclusive, 'startInclusive');
requireNonNull(duration, 'duration');
requireInstance(startInclusive, core.Instant, 'startInclusive');
requireInstance(duration, core.Duration, 'duration');
if (duration.isNegative()) {
throw new core.DateTimeException('Duration must not be zero or negative');
}
return new Interval(startInclusive, startInclusive.plus(duration));
};
Interval.parse = function parse(text) {
requireNonNull(text, 'text');
if (!(typeof text === 'string')) {
throw new core.IllegalArgumentException("text must be a string, but is " + text.constructor.name);
}
for (var i = 0; i < text.length; i += 1) {
if (text.charAt(i) === '/') {
var firstChar = text.charAt(0);
if (firstChar === 'P' || firstChar === 'p') {
var duration = core.Duration.parse(text.substring(0, i));
var end = core.ZonedDateTime.parse(text.substring(i + 1, text.length)).toInstant();
return Interval.of(end.minus(duration), end);
} else {
var start = core.ZonedDateTime.parse(text.substring(0, i)).toInstant();
if (i + 1 < text.length) {
var c = text.charAt(i + 1);
if (c === 'P' || c === 'p') {
var _duration = core.Duration.parse(text.substring(i + 1, text.length));
return Interval.of(start, start.plus(_duration));
}
}
var _end = core.ZonedDateTime.parse(text.substring(i + 1, text.length)).toInstant();
return Interval.of(start, _end);
}
}
}
throw new core.DateTimeParseException('Interval cannot be parsed, no forward slash found', text, 0);
};
function Interval(startInclusive, endExclusive) {
this._start = startInclusive;
this._end = endExclusive;
}
var _proto = Interval.prototype;
_proto.start = function start() {
return this._start;
};
_proto.end = function end() {
return this._end;
};
_proto.isEmpty = function isEmpty() {
return this._start.equals(this._end);
};
_proto.isUnboundedStart = function isUnboundedStart() {
return this._start.equals(core.Instant.MIN);
};
_proto.isUnboundedEnd = function isUnboundedEnd() {
return this._end.equals(core.Instant.MAX);
};
_proto.withStart = function withStart(start) {
return Interval.of(start, this._end);
};
_proto.withEnd = function withEnd(end) {
return Interval.of(this._start, end);
};
_proto.contains = function contains(instant) {
requireNonNull(instant, 'instant');
requireInstance(instant, core.Instant, 'instant');
return this._start.compareTo(instant) <= 0 && (instant.compareTo(this._end) < 0 || this.isUnboundedEnd());
};
_proto.encloses = function encloses(other) {
requireNonNull(other, 'other');
requireInstance(other, Interval, 'other');
return this._start.compareTo(other.start()) <= 0 && other.end().compareTo(this._end) <= 0;
};
_proto.abuts = function abuts(other) {
requireNonNull(other, 'other');
requireInstance(other, Interval, 'other');
return !this._end.equals(other.start()) !== !this._start.equals(other.end());
};
_proto.isConnected = function isConnected(other) {
requireNonNull(other, 'other');
requireInstance(other, Interval, 'other');
return this.equals(other) || this._start.compareTo(other.end()) <= 0 && other.start().compareTo(this._end) <= 0;
};
_proto.overlaps = function overlaps(other) {
requireNonNull(other, 'other');
requireInstance(other, Interval, 'other');
return other.equals(this) || this._start.compareTo(other.end()) < 0 && other.start().compareTo(this._end) < 0;
};
_proto.intersection = function intersection(other) {
requireNonNull(other, 'other');
requireInstance(other, Interval, 'other');
if (this.isConnected(other) === false) {
throw new core.DateTimeException("Intervals do not connect: " + this + " and " + other);
}
var cmpStart = this._start.compareTo(other.start());
var cmpEnd = this._end.compareTo(other.end());
if (cmpStart >= 0 && cmpEnd <= 0) {
return this;
} else if (cmpStart <= 0 && cmpEnd >= 0) {
return other;
} else {
var newStart = cmpStart >= 0 ? this._start : other.start();
var newEnd = cmpEnd <= 0 ? this._end : other.end();
return Interval.of(newStart, newEnd);
}
};
_proto.union = function union(other) {
requireNonNull(other, 'other');
requireInstance(other, Interval, 'other');
if (this.isConnected(other) === false) {
throw new core.DateTimeException("Intervals do not connect: " + this + " and " + other);
}
var cmpStart = this._start.compareTo(other.start());
var cmpEnd = this._end.compareTo(other.end());
if (cmpStart >= 0 && cmpEnd <= 0) {
return other;
} else if (cmpStart <= 0 && cmpEnd >= 0) {
return this;
} else {
var newStart = cmpStart >= 0 ? other.start() : this._start;
var newEnd = cmpEnd <= 0 ? other.end() : this._end;
return Interval.of(newStart, newEnd);
}
};
_proto.span = function span(other) {
requireNonNull(other, 'other');
requireInstance(other, Interval, 'other');
var cmpStart = this._start.compareTo(other.start());
var cmpEnd = this._end.compareTo(other.end());
var newStart = cmpStart >= 0 ? other.start() : this._start;
var newEnd = cmpEnd <= 0 ? other.end() : this._end;
return Interval.of(newStart, newEnd);
};
_proto.isAfter = function isAfter(instantOrInterval) {
if (instantOrInterval instanceof core.Instant) {
return this.isAfterInstant(instantOrInterval);
} else {
return this.isAfterInterval(instantOrInterval);
}
};
_proto.isBefore = function isBefore(instantOrInterval) {
if (instantOrInterval instanceof core.Instant) {
return this.isBeforeInstant(instantOrInterval);
} else {
return this.isBeforeInterval(instantOrInterval);
}
};
_proto.isAfterInstant = function isAfterInstant(instant) {
return this._start.compareTo(instant) > 0;
};
_proto.isBeforeInstant = function isBeforeInstant(instant) {
return this._end.compareTo(instant) <= 0 && this._start.compareTo(instant) < 0;
};
_proto.isAfterInterval = function isAfterInterval(interval) {
return this._start.compareTo(interval.end()) >= 0 && !interval.equals(this);
};
_proto.isBeforeInterval = function isBeforeInterval(interval) {
return this._end.compareTo(interval.start()) <= 0 && !interval.equals(this);
};
_proto.toDuration = function toDuration() {
return core.Duration.between(this._start, this._end);
};
_proto.equals = function equals(obj) {
if (this === obj) {
return true;
}
if (obj instanceof Interval) {
return this._start.equals(obj.start()) && this._end.equals(obj.end());
}
return false;
};
_proto.hashCode = function hashCode() {
return this._start.hashCode() ^ this._end.hashCode();
};
_proto.toString = function toString() {
return this._start.toString() + "/" + this._end.toString();
};
return Interval;
}();
function _init$6() {
Interval.ALL = Interval.of(core.Instant.MIN, core.Instant.MAX);
}
/**
* @copyright (c) 2016, Philipp Thürwächter & Pattrick Hüper & Michał Sobkiewicz
* @copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
*/
var MINP1 = core.LocalDate.MIN.plusDays(1);
var MAXM1 = core.LocalDate.MAX.minusDays(1);
var LocalDateRange = function () {
LocalDateRange.of = function of(startInclusive, endExclusiveOrPeriod) {
if (startInclusive instanceof core.LocalDate && endExclusiveOrPeriod instanceof core.LocalDate) {
return LocalDateRange._ofLocalDateLocalDate(startInclusive, endExclusiveOrPeriod);
}
if (startInclusive instanceof core.LocalDate && endExclusiveOrPeriod instanceof core.Period) {
return LocalDateRange._ofLocalDatePeriod(startInclusive, endExclusiveOrPeriod);
}
var messageParts = [];
if (!(startInclusive instanceof core.LocalDate)) {
messageParts.push("startInclusive must be an instance of LocalDate but is " + startInclusive.constructor.name);
}
if (!(endExclusiveOrPeriod instanceof core.LocalDate || endExclusiveOrPeriod instanceof core.Period)) {
messageParts.push("endExclusiveOrPeriod must be an instance of LocalDate or Period but is " + endExclusiveOrPeriod.constructor.name);
}
throw new core.IllegalArgumentException(messageParts.join(' and '));
};
LocalDateRange._ofLocalDateLocalDate = function _ofLocalDateLocalDate(startInclusive, endExclusive) {
requireNonNull(startInclusive, 'startInclusive');
requireNonNull(endExclusive, 'endExclusive');
requireInstance(startInclusive, core.LocalDate, 'startInclusive');
requireInstance(endExclusive, core.LocalDate, 'endExclusive');
return new LocalDateRange(startInclusive, endExclusive);
};
LocalDateRange._ofLocalDatePeriod = function _ofLocalDatePeriod(startInclusive, period) {
requireNonNull(startInclusive, 'startInclusive');
requireNonNull(period, 'period');
requireInstance(startInclusive, core.LocalDate, 'startInclusive');
requireInstance(period, core.Period, 'period');
if (period.isNegative()) {
throw new core.DateTimeException('Period must not be zero or negative');
}
return new LocalDateRange(startInclusive, startInclusive.plus(period));
};
LocalDateRange.ofClosed = function ofClosed(startInclusive, endInclusive) {
requireNonNull(startInclusive, 'startInclusive');
requireNonNull(endInclusive, 'endInclusive');
requireInstance(startInclusive, core.LocalDate, 'startInclusive');
requireInstance(endInclusive, core.LocalDate, 'endInclusive');
if (endInclusive.isBefore(startInclusive)) {
throw new core.DateTimeException('Start date must be on or before end date');
}
var end = endInclusive.equals(core.LocalDate.MAX) ? core.LocalDate.MAX : endInclusive.plusDays(1);
return new LocalDateRange(startInclusive, end);
};
LocalDateRange.ofEmpty = function ofEmpty(date) {
requireNonNull(date, 'date');
requireInstance(date, core.LocalDate, 'date');
return new LocalDateRange(date, date);
};
LocalDateRange.ofUnbounded = function ofUnbounded() {
return LocalDateRange.ALL;
};
LocalDateRange.ofUnboundedStart = function ofUnboundedStart(endExclusive) {
requireNonNull(endExclusive, 'endExclusive');
requireInstance(endExclusive, core.LocalDate, 'endExclusive');
return LocalDateRange.of(core.LocalDate.MIN, endExclusive);
};
LocalDateRange.ofUnboundedEnd = function ofUnboundedEnd(startInclusive) {
return LocalDateRange.of(startInclusive, core.LocalDate.MAX);
};
LocalDateRange.parse = function parse(text) {
requireNonNull(text, 'text');
for (var i = 0; i < text.length; i++) {
if (text[i] === '/') {
var firstChar = text.charAt(0);
if (firstChar === 'P' || firstChar === 'p') {
var duration = core.Period.parse(text.slice(0, i));
var end = core.LocalDate.parse(text.slice(i + 1, text.length));
return LocalDateRange.of(end.minus(duration), end);
} else {
var start = core.LocalDate.parse(text.slice(0, i));
if (i + 1 < text.length) {
var c = text[i + 1];
if (c === 'P' || c === 'p') {
var _duration = core.Period.parse(text.slice(i + 1, text.length));
return LocalDateRange.of(start, start.plus(_duration));
}
}
var _end = core.LocalDate.parse(text.slice(i + 1, text.length));
return LocalDateRange.of(start, _end);
}
}
}
throw new core.DateTimeParseException('LocalDateRange cannot be parsed, no forward slash found', text, 0);
};
function LocalDateRange(startInclusive, endExclusive) {
requireNonNull(startInclusive, 'startInclusive');
requireNonNull(endExclusive, 'endExclusive');
requireInstance(startInclusive, core.LocalDate, 'startInclusive');
requireInstance(endExclusive, core.LocalDate, 'endExclusive');
if (endExclusive.isBefore(startInclusive)) {
throw new core.DateTimeException('End date must be on or after start date');
}
if (startInclusive.equals(MAXM1)) {
throw new core.DateTimeException('Range must not start at LocalDate.MAX.minusDays(1)');
}
if (endExclusive.equals(MINP1)) {
throw new core.DateTimeException('Range must not end at LocalDate.MIN.plusDays(1)');
}
if (endExclusive.equals(core.LocalDate.MIN) || startInclusive.equals(core.LocalDate.MAX)) {
throw new core.DateTimeException('Empty range must not be at LocalDate.MIN or LocalDate.MAX');
}
this._start = startInclusive;
this._end = endExclusive;
}
var _proto = LocalDateRange.prototype;
_proto.start = function start() {
return this._start;
};
_proto.end = function end() {
return this._end;
};
_proto.endInclusive = function endInclusive() {
if (this.isUnboundedEnd()) {
return core.LocalDate.MAX;
}
return this._end.minusDays(1);
};
_proto.isEmpty = function isEmpty() {
return this._start.equals(this._end);
};
_proto.isUnboundedStart = function isUnboundedStart() {
return this._start.equals(core.LocalDate.MIN);
};
_proto.isUnboundedEnd = function isUnboundedEnd() {
return this._end.equals(core.LocalDate.MAX);
};
_proto.withStart = function withStart(adjuster) {
return LocalDateRange.of(this._start.with(adjuster), this._end);
};
_proto.withEnd = function withEnd(adjuster) {
return LocalDateRange.of(this._start, this._end.with(adjuster));
};
_proto.contains = function contains(date) {
requireNonNull(date, 'date');
return this._start.compareTo(date) <= 0 && (date.compareTo(this._end) < 0 || this.isUnboundedEnd());
};
_proto.encloses = function encloses(other) {
requireNonNull(other, 'other');
return this._start.compareTo(other._start) <= 0 && other._end.compareTo(this._end) <= 0;
};
_proto.abuts = function abuts(other) {
requireNonNull(other, 'other');
return this._end.equals(other._start) !== this._start.equals(other._end);
};
_proto.isConnected = function isConnected(other) {
requireNonNull(other, 'other');
return this.equals(other) || this._start.compareTo(other._end) <= 0 && other._start.compareTo(this._end) <= 0;
};
_proto.overlaps = function overlaps(other) {
requireNonNull(other, 'other');
return other.equals(this) || this._start.compareTo(other._end) < 0 && other._start.compareTo(this._end) < 0;
};
_proto.intersection = function intersection(other) {
requireNonNull(other, 'other');
if (this.isConnected(other) === false) {
throw new core.DateTimeException("Ranges do not connect: " + this + " and " + other);
}
var cmpStart = this._start.compareTo(other._start);
var cmpEnd = this._end.compareTo(other._end);
if (cmpStart >= 0 && cmpEnd <= 0) {
return this;
} else if (cmpStart <= 0 && cmpEnd >= 0) {
return other;
} else {
var newStart = cmpStart >= 0 ? this._start : other._start;
var newEnd = cmpEnd <= 0 ? this._end : other._end;
return LocalDateRange.of(newStart, newEnd);
}
};
_proto.union = function union(other) {
requireNonNull(other, 'other');
if (this.isConnected(other) === false) {
throw new core.DateTimeException("Ranges do not connect: " + this + " and " + other);
}
var cmpStart = this._start.compareTo(other._start);
var cmpEnd = this._end.compareTo(other._end);
if (cmpStart >= 0 && cmpEnd <= 0) {
return other;
} else if (cmpStart <= 0 && cmpEnd >= 0) {
return this;
} else {
var newStart = cmpStart >= 0 ? other._start : this._start;
var newEnd = cmpEnd <= 0 ? other._end : this._end;
return LocalDateRange.of(newStart, newEnd);
}
};
_proto.span = function span(other) {
requireNonNull(other, 'other');
var cmpStart = this._start.compareTo(other._start);
var cmpEnd = this._end.compareTo(other._end);
var newStart = cmpStart >= 0 ? other._start : this._start;
var newEnd = cmpEnd <= 0 ? other._end : this._end;
return LocalDateRange.of(newStart, newEnd);
};
_proto.isAfter = function isAfter(localDateOrLocalDateRange) {
if (localDateOrLocalDateRange instanceof core.LocalDate) {
return this._isAfterLocalDate(localDateOrLocalDateRange);
}
if (localDateOrLocalDateRange instanceof LocalDateRange) {
return this._isAfterLocalDateRange(localDateOrLocalDateRange);
}
throw new core.IllegalArgumentException("localDateOrLocalDateRange must be an instance of LocalDate or LocalDateRange but is " + localDateOrLocalDateRange.constructor.name);
};
_proto.isBefore = function isBefore(localDateOrLocalDateRange) {
if (localDateOrLocalDateRange instanceof core.LocalDate) {
return this._isBeforeLocalDate(localDateOrLocalDateRange);
}
if (localDateOrLocalDateRange instanceof LocalDateRange) {
return this._isBeforeLocalDateRange(localDateOrLocalDateRange);
}
throw new core.IllegalArgumentException("localDateOrLocalDateRange must be an instance of LocalDate or LocalDateRange but is " + localDateOrLocalDateRange.constructor.name);
};
_proto._isAfterLocalDate = function _isAfterLocalDate(date) {
return this._start.compareTo(date) > 0;
};
_proto._isBeforeLocalDate = function _isBeforeLocalDate(date) {
return this._end.compareTo(date) <= 0 && this._start.compareTo(date) < 0;
};
_proto._isAfterLocalDateRange = function _isAfterLocalDateRange(other) {
return this._start.compareTo(other._end) >= 0 && !other.equals(this);
};
_proto._isBeforeLocalDateRange = function _isBeforeLocalDateRange(range) {
return this._end.compareTo(range._start) <= 0 && !range.equals(this);
};
_proto.lengthInDays = function lengthInDays() {
if (this.isUnboundedStart() || this.isUnboundedEnd()) {
return Number.POSITIVE_INFINITY;
}
return this._end.toEpochDay() - this._start.toEpochDay();
};
_proto.toPeriod = function toPeriod() {
if (this.isUnboundedStart() || this.isUnboundedEnd()) {
throw new core.ArithmeticException('Unbounded range cannot be converted to a Period');
}
return core.Period.between(this._start, this._end);
};
_proto.equals = function equals(obj) {
if (this === obj) {
return true;
}
if (obj instanceof LocalDateRange) {
var other = obj;
return this._start.equals(other._start) && this._end.equals(other._end);
}
return false;
};
_proto.hashCode = function hashCode() {
return this._start.hashCode() ^ this._end.hashCode();
};
_proto.toString = function toString() {
return this._start.toString() + "/" + this._end.toString();
};
return LocalDateRange;
}();
function _init$5() {
LocalDateRange.ALL = new LocalDateRange(core.LocalDate.MIN, core.LocalDate.MAX);
}
var MathUtil$4 = core._.MathUtil;
var SECONDS_PER_DAY = 86400;
var OffsetDate = function (_Temporal) {
_inheritsLoose(OffsetDate, _Temporal);
OffsetDate.now = function now(zoneIdOrClock) {
if (arguments.length === 0) {
return OffsetDate._now0();
} else if (arguments.length === 1 && zoneIdOrClock instanceof core.ZoneId) {
return OffsetDate._nowZoneId(zoneIdOrClock);
} else {
return OffsetDate._nowClock(zoneIdOrClock);
}
};
OffsetDate._now0 = function _now0() {
return OffsetDate.now(core.Clock.systemDefaultZone());
};
OffsetDate._nowZoneId = function _nowZoneId(zone) {
return OffsetDate.now(core.Clock.system(zone));
};
OffsetDate._nowClock = function _nowClock(clock) {
requireNonNull(clock, 'clock');
var now = clock.instant();
return OffsetDate.ofInstant(now, clock.zone().rules().offset(now));
};
OffsetDate.of = function of() {
switch (arguments.length) {
case 2:
return OffsetDate._ofLocalDateZoneOffset.apply(OffsetDate, arguments);
case 4:
return OffsetDate._ofIntIntIntZoneOffset.apply(OffsetDate, arguments);
default:
throw new core.IllegalArgumentException('Illegal number of arguments');
}
};
OffsetDate._ofLocalDateZoneOffset = function _ofLocalDateZoneOffset(date, offset) {
return new OffsetDate(date, offset);
};
OffsetDate._ofIntIntIntZoneOffset = function _ofIntIntIntZoneOffset(year, month, dayOfMonth, offset) {
var d = core.LocalDate.of(year, month, dayOfMonth);
return new OffsetDate(d, offset);
};
OffsetDate.ofInstant = function ofInstant(instant, zone) {
requireNonNull(instant, 'instant');
requireNonNull(zone, 'zone');
var rules = zone.rules();
var offset = rules.offset(instant);
var epochSec = instant.epochSecond() + offset.totalSeconds();
var epochDay = MathUtil$4.floorDiv(epochSec, SECONDS_PER_DAY);
var date = core.LocalDate.ofEpochDay(epochDay);
return new OffsetDate(date, offset);
};
OffsetDate.from = function from(temporal) {
if (temporal instanceof OffsetDate) {
return temporal;
}
requireNonNull(temporal, 'temporal');
try {
var date = core.LocalDate.from(temporal);
var offset = core.ZoneOffset.from(temporal);
return new OffsetDate(date, offset);
} catch (ex) {
throw new core.DateTimeException("Unable to obtain OffsetDate from TemporalAccessor: " + temporal.constructor.name, ex);
}
};
OffsetDate.parse = function parse(text, formatter) {
if (formatter === void 0) {
formatter = core.DateTimeFormatter.ISO_OFFSET_DATE;
}
requireNonNull(formatter, 'formatter');
return formatter.parse(text, OffsetDate.FROM);
};
function OffsetDate(date, offset) {
var _this;
_this = _Temporal.call(this) || this;
_this._date = requireNonNull(date, 'date');
_this._offset = requireNonNull(offset, 'offset');
return _this;
}
var _proto = OffsetDate.prototype;
_proto._with = function _with(date, offset) {
if (this._date === date && this._offset.equals(offset)) {
return this;
}
return new OffsetDate(date, offset);
};
_proto.isSupported = function isSupported(fieldOrUnit) {
if (fieldOrUnit instanceof core.TemporalField) {
return this._isSupportedField(fieldOrUnit);
}
if (fieldOrUnit instanceof core.TemporalUnit) {
return this._isSupportedUnit(fieldOrUnit);
}
if (fieldOrUnit == null) {
return false;
}
throw new core.IllegalArgumentException("fieldOrUnit must be an instance of TemporalField or TemporalUnit, but is " + fieldOrUnit.constructor.name);
};
_proto._isSupportedField = function _isSupportedField(field) {
if (field instanceof core.ChronoField) {
return field.isDateBased() || field === core.ChronoField.OFFSET_SECONDS;
}
return field != null && field.isSupportedBy(this);
};
_proto._isSupportedUnit = function _isSupportedUnit(unit) {
if (unit instanceof core.ChronoUnit) {
return unit.isDateBased();
}
return unit != null && unit.isSupportedBy(this);
};
_proto.range = function range(field) {
requireNonNull(field, 'field');
requireInstance(field, core.TemporalField, 'field');
if (field instanceof core.ChronoField) {
if (field === core.ChronoField.OFFSET_SECONDS) {
return field.range();
}
return this._date.range(field);
}
return field.rangeRefinedBy(this);
};
_proto.get = function get(field) {
requireNonNull(field, 'field');
requireInstance(field, core.TemporalField, 'field');
return this.range(field).checkValidIntValue(this.getLong(field), field);
};
_proto.getLong = function getLong(field) {
requireNonNull(field, 'field');
requireInstance(field, core.TemporalField, 'field');
if (field instanceof core.ChronoField) {
if (field === core.ChronoField.OFFSET_SECONDS) {
return this.offset().totalSeconds();
}
return this._date.getLong(field);
}
return field.getFrom(this);
};
_proto.offset = function offset() {
return this._offset;
};
_proto.withOffsetSameLocal = function withOffsetSameLocal(offset) {
requireNonNull(offset, 'offset');
return this._with(this._date, offset);
};
_proto.toLocalDate = function toLocalDate() {
return this._date;
};
_proto.year = function year() {
return this._date.year();
};
_proto.monthValue = function monthValue() {
return this._date.monthValue();
};
_proto.month = function month() {
return this._date.month();
};
_proto.dayOfMonth = function dayOfMonth() {
return this._date.dayOfMonth();
};
_proto.dayOfYear = function dayOfYear() {
return this._date.dayOfYear();
};
_proto.dayOfWeek = function dayOfWeek() {
return this._date.dayOfWeek();
};
_proto._withAdjuster = function _withAdjuster(adjuster) {
if (adjuster instanceof core.LocalDate) {
return this._with(adjuster, this._offset);
} else if (adjuster instanceof core.ZoneOffset) {
return this._with(this._date, adjuster);
} else if (adjuster instanceof OffsetDate) {
return adjuster;
}
return _Temporal.prototype._withAdjuster.call(this, adjuster);
};
_proto._withField = function _withField(field, newValue) {
requireNonNull(field, 'field');
requireInstance(field, core.TemporalField, 'field');
if (field instanceof core.ChronoField) {
if (field === core.ChronoField.OFFSET_SECONDS) {
var f = field;
return this._with(this._date, core.ZoneOffset.ofTotalSeconds(f.checkValidIntValue(newValue)));
}
return this._with(this._date.with(field, newValue), this._offset);
}
return field.adjustInto(this, newValue);
};
_proto.withYear = function withYear(year) {
return this._with(this._date.withYear(year), this._offset);
};
_proto.withMonth = function withMonth(month) {
return this._with(this._date.withMonth(month), this._offset);
};
_proto.withDayOfMonth = function withDayOfMonth(dayOfMonth) {
return this._with(this._date.withDayOfMonth(dayOfMonth), this._offset);
};
_proto.withDayOfYear = function withDayOfYear(dayOfYear) {
return this._with(this._date.withDayOfYear(dayOfYear), this._offset);
};
_proto._plusUnit = function _plusUnit(amountToAdd, unit) {
if (unit instanceof core.ChronoUnit) {
return this._with(this._date.plus(amountToAdd, unit), this._offset);
}
return unit.addTo(this, amountToAdd);
};
_proto.plusYears = function plusYears(years) {
return this._with(this._date.plusYears(years), this._offset);
};
_proto.plusMonths = function plusMonths(months) {
return this._with(this._date.plusMonths(months), this._offset);
};
_proto.plusWeeks = function plusWeeks(weeks) {
return this._with(this._date.plusWeeks(weeks), this._offset);
};
_proto.plusDays = function plusDays(days) {
return this._with(this._date.plusDays(days), this._offset);
};
_proto.minusYears = function minusYears(years) {
return this._with(this._date.minusYears(years), this._offset);
};
_proto.minusMonths = function minusMonths(months) {
return this._with(this._date.minusMonths(months), this._offset);
};
_proto.minusWeeks = function minusWeeks(weeks) {
return this._with(this._date.minusWeeks(weeks), this._offset);
};
_proto.minusDays = function minusDays(days) {
return this._with(this._date.minusDays(days), this._offset);
};
_proto.query = function query(_query) {
requireNonNull(_query, 'query');
requireInstance(_query, core.TemporalQuery, 'query');
if (_query === core.TemporalQueries.chronology()) {
return core.IsoChronology.INSTANCE;
} else if (_query === core.TemporalQueries.precision()) {
return core.ChronoUnit.DAYS;
} else if (_query === core.TemporalQueries.offset() || _query === core.TemporalQueries.zone()) {
return this.offset();
}
return _Temporal.prototype.query.call(this, _query);
};
_proto.adjustInto = function adjustInto(temporal) {
return temporal.with(core.ChronoField.OFFSET_SECONDS, this.offset().totalSeconds()).with(core.ChronoField.EPOCH_DAY, this.toLocalDate().toEpochDay());
};
_proto.until = function until(endExclusive, unit) {
var end = OffsetDate.from(endExclusive);
if (unit instanceof core.ChronoUnit) {
var offsetDiff = end._offset.totalSeconds() - this._offset.totalSeconds();
var endLocal = end._date.plusDays(MathUtil$4.intDiv(-offsetDiff, SECONDS_PER_DAY));
return this._date.until(endLocal, unit);
}
return unit.between(this, end);
};
_proto.format = function format(formatter) {
requireNonNull(formatter, 'formatter');
return formatter.format(this);
};
_proto.atTime = function atTime(time) {
return core.OffsetDateTime.of(this._date, time, this._offset);
};
_proto._toEpochSecond = function _toEpochSecond() {
var epochDay = this._date.toEpochDay();
var secs = epochDay * SECONDS_PER_DAY;
return secs - this._offset.totalSeconds();
};
_proto.toEpochSecond = function toEpochSecond(time) {
requireNonNull(time, 'time');
return this._toEpochSecond() + time.toSecondOfDay();
};
_proto.compareTo = function compareTo(other) {
requireNonNull(other, 'other');
requireInstance(other, OffsetDate, 'other');
if (this._offset.equals(other._offset)) {
return this._date.compareTo(other._date);
}
var compare = this._toEpochSecond() - other._toEpochSecond();
if (compare === 0) {
compare = this._date.compareTo(other._date);
}
return compare;
};
_proto.isAfter = function isAfter(other) {
requireNonNull(other, 'other');
requireInstance(other, OffsetDate, 'other');
return this._toEpochSecond() > other._toEpochSecond();
};
_proto.isBefore = function isBefore(other) {
requireNonNull(other, 'other');
requireInstance(other, OffsetDate, 'other');
return this._toEpochSecond() < other._toEpochSecond();
};
_proto.isEqual = function isEqual(other) {
requireNonNull(other, 'other');
requireInstance(other, OffsetDate, 'other');
return this._toEpochSecond() === other._toEpochSecond();
};
_proto.equals = function equals(obj) {
if (this === obj) {
return true;
}
if (obj instanceof OffsetDate) {
var other = obj;
return this._date.equals(other._date) && this._offset.equals(other._offset);
}
return false;
};
_proto.hashCode = function hashCode() {
return this._date.hashCode() ^ this._offset.hashCode();
};
_proto.toString = function toString() {
return this._date.toString() + this._offset.toString();
};
return OffsetDate;
}(core.Temporal);
function _init$4() {
OffsetDate.MIN = OffsetDate.of(core.LocalDate.MIN, core.ZoneOffset.MAX);
OffsetDate.MAX = OffsetDate.of(core.LocalDate.MAX, core.ZoneOffset.MIN);
OffsetDate.FROM = createTemporalQuery$3('OffsetDate.FROM', function (temporal) {
return OffsetDate.from(temporal);
});
}
function createTemporalQuery$3(name, queryFromFunction) {
var ExtendedTemporalQuery = function (_TemporalQuery) {
_inheritsLoose(ExtendedTemporalQuery, _TemporalQuery);
function ExtendedTemporalQuery() {
return _TemporalQuery.apply(this, arguments) || this;
}
return ExtendedTemporalQuery;
}(core.TemporalQuery);
ExtendedTemporalQuery.prototype.queryFrom = queryFromFunction;
return new ExtendedTemporalQuery(name);
}
var MathUtil$3 = core._.MathUtil;
var Quarter = function (_TemporalAccessor) {
_inheritsLoose(Quarter, _TemporalAccessor);
Quarter.valueOf = function valueOf(name) {
requireNonNull(name, 'name');
switch (name) {
case 'Q1':
return Quarter.Q1;
case 'Q2':
return Quarter.Q2;
case 'Q3':
return Quarter.Q3;
case 'Q4':
return Quarter.Q4;
}
throw new core.IllegalArgumentException("No enum constant Quarter." + name);
};
Quarter.values = function values() {
return QUARTERS.slice();
};
Quarter.of = function of(quarterOfYear) {
requireNonNull(quarterOfYear, 'quarterOfYear');
switch (quarterOfYear) {
case 1:
return Quarter.Q1;
case 2:
return Quarter.Q2;
case 3:
return Quarter.Q3;
case 4:
return Quarter.Q4;
default:
throw new core.DateTimeException("Invalid value for Quarter: " + quarterOfYear);
}
};
Quarter.ofMonth = function ofMonth(monthOfYear) {
requireNonNull(monthOfYear, 'monthOfYear');
core.ChronoField.MONTH_OF_YEAR.range().checkValidValue(monthOfYear, core.ChronoField.MONTH_OF_YEAR);
return Quarter.of(MathUtil$3.intDiv(monthOfYear - 1, 3) + 1);
};
Quarter.from = function from(temporal) {
if (temporal instanceof Quarter) {
return temporal;
} else if (temporal instanceof core.Month) {
var month = temporal;
return Quarter.of(MathUtil$3.intDiv(month.ordinal(), 3) + 1);
}
try {
var qoy = MathUtil$3.safeToInt(temporal.getLong(core.IsoFields.QUARTER_OF_YEAR));
return Quarter.of(qoy);
} catch (ex) {
throw new core.DateTimeException("Unable to obtain Quarter from TemporalAccessor: '" + temporal + "' of type '" + (temporal && temporal.constructor.name) + "'", ex);
}
};
function Quarter(value, name) {
var _this;
_this = _TemporalAccessor.call(this) || this;
_this._value = MathUtil$3.safeToInt(value);
_this._name = name;
return _this;
}
var _proto = Quarter.prototype;
_proto.value = function value() {
return this._value;
};
_proto.displayName = function displayName(style, locale) {
throw new core.IllegalArgumentException('Pattern using (localized) text not implemented yet!');
};
_proto.isSupported = function isSupported(field) {
if (field === core.IsoFields.QUARTER_OF_YEAR) {
return true;
} else if (field instanceof core.ChronoField) {
return false;
}
return field != null && field.isSupportedBy(this);
};
_proto.range = function range(field) {
requireNonNull(field, 'field');
if (field === core.IsoFields.QUARTER_OF_YEAR) {
return field.range();
} else if (field instanceof core.ChronoField) {
throw new core.UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return _TemporalAccessor.prototype.range.call(this, field);
};
_proto.get = function get(field) {
requireNonNull(field, 'field');
requireInstance(field, core.TemporalField, 'field');
return this.range(field).checkValidIntValue(this.getLong(field), field);
};
_proto.getLong = function getLong(field) {
requireNonNull(field, 'field');
if (field === core.IsoFields.QUARTER_OF_YEAR) {
return this.value();
} else if (field instanceof core.ChronoField) {
throw new core.UnsupportedTemporalTypeException("Unsupported field: " + field);