Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let date = LocalDate.of(year, 1, 1); // TODO: chrono.date(year, 1, 1);
let days;
if (resolverStyle === ResolverStyle.LENIENT) {
const dateDow = this._localizedDayOfWeek(date, sow);
const weeks = value - this._localizedWeekOfYear(date, dateDow);
days = weeks * 7 + (dow - dateDow);
} else {
const dateDow = this._localizedDayOfWeek(date, sow);
const woy = this._range.checkValidIntValue(value, this);
const weeks = woy - this._localizedWeekOfYear(date, dateDow);
days = weeks * 7 + (dow - dateDow);
}
date = date.plus(days, ChronoUnit.DAYS);
if (resolverStyle === ResolverStyle.STRICT) {
if (date.getLong(ChronoField.YEAR) !== fieldValues.get(ChronoField.YEAR)) {
throw new DateTimeException('Strict mode rejected date parsed to a different year');
}
}
fieldValues.remove(this);
fieldValues.remove(ChronoField.YEAR);
fieldValues.remove(ChronoField.DAY_OF_WEEK);
return date;
} else {
throw new IllegalStateException('unreachable');
}
}
date = date.plus(month - 1, ChronoUnit.MONTHS);
const dateDow = this._localizedDayOfWeek(date, sow);
const weeks = value - this._localizedWeekOfMonth(date, dateDow);
days = weeks * 7 + (dow - dateDow);
} else {
const month = ChronoField.MONTH_OF_YEAR.checkValidIntValue(fieldValues.get(ChronoField.MONTH_OF_YEAR));
date = LocalDate.of(year, month, 8); // TODO: chrono.date(year, month, 8);
const dateDow = this._localizedDayOfWeek(date, sow);
const wom = this._range.checkValidIntValue(value, this);
const weeks = wom - this._localizedWeekOfMonth(date, dateDow);
days = weeks * 7 + (dow - dateDow);
}
date = date.plus(days, ChronoUnit.DAYS);
if (resolverStyle === ResolverStyle.STRICT) {
if (date.getLong(ChronoField.MONTH_OF_YEAR) !== fieldValues.get(ChronoField.MONTH_OF_YEAR)) {
throw new DateTimeException('Strict mode rejected date parsed to a different month');
}
}
fieldValues.remove(this);
fieldValues.remove(ChronoField.YEAR);
fieldValues.remove(ChronoField.MONTH_OF_YEAR);
fieldValues.remove(ChronoField.DAY_OF_WEEK);
return date;
} else if (this._rangeUnit === ChronoUnit.YEARS) { // week-of-year
const value = fieldValues.remove(this);
let date = LocalDate.of(year, 1, 1); // TODO: chrono.date(year, 1, 1);
let days;
if (resolverStyle === ResolverStyle.LENIENT) {
const dateDow = this._localizedDayOfWeek(date, sow);
const weeks = value - this._localizedWeekOfYear(date, dateDow);
days = weeks * 7 + (dow - dateDow);
} else {
static ofInstantInstant(startInclusive, endExclusive) {
requireNonNull(startInclusive, 'startInclusive');
requireNonNull(endExclusive, 'endExclusive');
requireInstance(startInclusive, Instant, 'startInclusive');
requireInstance(endExclusive, Instant, 'endExclusive');
if (endExclusive.isBefore(startInclusive)) {
throw new DateTimeException('End instant must on or after start instant');
}
return new Interval(startInclusive, endExclusive);
}
intersection(other) {
requireNonNull(other, 'other');
requireInstance(other, Interval, 'other');
if (this.isConnected(other) === false) {
throw new DateTimeException(`Intervals do not connect: ${this} and ${other}`);
}
const cmpStart = this._start.compareTo(other.start());
const cmpEnd = this._end.compareTo(other.end());
if (cmpStart >= 0 && cmpEnd <= 0) {
return this;
} else if (cmpStart <= 0 && cmpEnd >= 0) {
return other;
} else {
const newStart = (cmpStart >= 0 ? this._start : other.start());
const newEnd = (cmpEnd <= 0 ? this._end : other.end());
return Interval.of(newStart, newEnd);
}
}
union(other) {
requireNonNull(other, 'other');
requireInstance(other, Interval, 'other');
if (this.isConnected(other) === false) {
throw new DateTimeException(`Intervals do not connect: ${this} and ${other}`);
}
const cmpStart = this._start.compareTo(other.start());
const cmpEnd = this._end.compareTo(other.end());
if (cmpStart >= 0 && cmpEnd <= 0) {
return other;
} else if (cmpStart <= 0 && cmpEnd >= 0) {
return this;
} else {
const newStart = (cmpStart >= 0 ? other.start() : this._start);
const newEnd = (cmpEnd <= 0 ? other.end() : this._end);
return Interval.of(newStart, newEnd);
}
}
static ofInstantDuration(startInclusive, duration) {
requireNonNull(startInclusive, 'startInclusive');
requireNonNull(duration, 'duration');
requireInstance(startInclusive, Instant, 'startInclusive');
requireInstance(duration, Duration, 'duration');
if (duration.isNegative()) {
throw new DateTimeException('Duration must not be zero or negative');
}
return new Interval(startInclusive, startInclusive.plus(duration));
}