Socket
Socket
Sign inDemoInstall

@js-joda/core

Package Overview
Dependencies
0
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.2.0 to 4.0.0

16

CHANGELOG.md

@@ -6,2 +6,18 @@ Changelog

### 4.0.0
Even this is a major release, there are no real breaking changes.
The release contains typescript definition cleanup and some
"private" methods have been prefixed with "_". These methods are intended for internal use only.
If you used the threeten API in the intended way, there shouldn't be any breaking changes.
If you used internal methods before, there is an replacement eg instead of `minusAmountUnit` use `minus`.
* cleanup TS Typings in #456 by @InExtremaRes
* cleanup private methods and Temporal class in #460 by @InExtremaRes
* remove TS definitions from core, moved to locale TS definitions in #389 by @InExtremaRes
* make .equals a type predicate in the TS typings in #457 by @InExtremaRes
* add some ISO formatters in #455 by @akonior
* several dependabot updates
### 3.2.0

@@ -8,0 +24,0 @@

6

package.json
{
"name": "@js-joda/core",
"version": "3.2.0",
"version": "4.0.0",
"description": "a date and time library for javascript",

@@ -45,3 +45,3 @@ "repository": {

"devDependencies": {
"@babel/cli": "^7.7.4",
"@babel/cli": "^7.14.8",
"@babel/core": "^7.7.4",

@@ -55,3 +55,3 @@ "@babel/preset-env": "^7.7.4",

"chai": "^4.2.0",
"coveralls": "^3.0.8",
"coveralls": "^3.1.1",
"karma": "^4.4.1",

@@ -58,0 +58,0 @@ "karma-chai-plugins": "^0.9.0",

@@ -127,5 +127,2 @@ # @js-joda/core

- Cleanup documentation (ongoing task)
- Improve static factory API design and make it more JavaScript style. One idea is to remove static factory methods like parse, from, of and unify it to one factory method per domain. E.g. localDate(isoDate: string), localDate(year: number, month: number, dayOfMonth: number)
- Merge methods get and getLong (difference between `int` and `long` values makes no sense with JavaScript)
- Simplify temporal adjusters (amount, etc) by using functions instead of classes or objects

@@ -132,0 +129,0 @@ ## Contributing

@@ -13,3 +13,3 @@ /*

import {TemporalQueries} from '../temporal/TemporalQueries';
import {DefaultInterfaceTemporal} from '../temporal/DefaultInterfaceTemporal';
import {Temporal} from '../temporal/Temporal';

@@ -184,3 +184,3 @@ import {LocalDate} from '../LocalDate';

*/
export class ChronoLocalDate extends DefaultInterfaceTemporal {
export class ChronoLocalDate extends Temporal {

@@ -187,0 +187,0 @@ isSupported(fieldOrUnit) {

@@ -15,3 +15,3 @@ /*

import {ChronoField} from '../temporal/ChronoField';
import {DefaultInterfaceTemporal} from '../temporal/DefaultInterfaceTemporal';
import {Temporal} from '../temporal/Temporal';
import {TemporalQueries} from '../temporal/TemporalQueries';

@@ -53,3 +53,3 @@

*/
export class ChronoLocalDateTime extends DefaultInterfaceTemporal {
export class ChronoLocalDateTime extends Temporal {
/* <D extends ChronoLocalDate>

@@ -56,0 +56,0 @@ extends DefaultInterfaceTemporal

@@ -13,6 +13,6 @@ /*

import {ChronoUnit} from '../temporal/ChronoUnit';
import {DefaultInterfaceTemporal} from '../temporal/DefaultInterfaceTemporal';
import {Temporal} from '../temporal/Temporal';
import {TemporalQueries} from '../temporal/TemporalQueries';
export class ChronoZonedDateTime extends DefaultInterfaceTemporal {
export class ChronoZonedDateTime extends Temporal {
query(query) {

@@ -19,0 +19,0 @@ if (query === TemporalQueries.zoneId() || query === TemporalQueries.zone()) {

@@ -706,6 +706,27 @@ /**

DateTimeFormatter.ISO_DATE = new DateTimeFormatterBuilder()
.parseCaseInsensitive()
.append(DateTimeFormatter.ISO_LOCAL_DATE)
.optionalStart()
.appendOffsetId()
.optionalEnd()
.toFormatter(ResolverStyle.STRICT).withChronology(IsoChronology.INSTANCE);
DateTimeFormatter.ISO_TIME = new DateTimeFormatterBuilder()
.parseCaseInsensitive()
.append(DateTimeFormatter.ISO_LOCAL_TIME)
.optionalStart()
.appendOffsetId()
.optionalEnd()
.toFormatter(ResolverStyle.STRICT);
DateTimeFormatter.ISO_DATE_TIME = new DateTimeFormatterBuilder()
.append(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
.optionalStart()
.appendOffsetId()
.optionalEnd()
.toFormatter(ResolverStyle.STRICT).withChronology(IsoChronology.INSTANCE);
// TODO:
// ISO_DATE - https://www.threeten.org/threetenbp/apidocs/org/threeten/bp/format/DateTimeFormatter.html#ISO_DATE
// ISO_TIME - https://www.threeten.org/threetenbp/apidocs/org/threeten/bp/format/DateTimeFormatter.html#ISO_TIME
// ISO_DATE_TIME - https://www.threeten.org/threetenbp/apidocs/org/threeten/bp/format/DateTimeFormatter.html#ISO_DATE_TIME
// RFC_1123_DATE_TIME - https://www.threeten.org/threetenbp/apidocs/org/threeten/bp/format/DateTimeFormatter.html#RFC_1123_DATE_TIME

@@ -712,0 +733,0 @@ DateTimeFormatter.PARSED_EXCESS_DAYS = createTemporalQuery('PARSED_EXCESS_DAYS', (temporal) => {

@@ -408,27 +408,4 @@ /**

//-------------------------------------------------------------------------
//-----------------------------------------------------------------------
/**
* Returns an adjusted copy of this instant.
*
* This returns a new {@link Instant}, based on this one, with the date adjusted.
* The adjustment takes place using the specified adjuster strategy object.
* Read the documentation of the adjuster to understand what adjustment will be made.
*
* The result of this method is obtained by invoking the
* {@link TemporalAdjuster#adjustInto} method on the
* specified adjuster passing `this` as the argument.
*
* This instance is immutable and unaffected by this method call.
*
* @param {!TemporalAdjuster} adjuster - the adjuster to use, not null
* @return {Instant} an {@link Instant} based on `this` with the adjustment made, not null
* @throws DateTimeException if the adjustment cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
withAdjuster(adjuster) {
requireNonNull(adjuster, 'adjuster');
return adjuster.adjustInto(this);
}
/**
* Returns a copy of this instant with the specified field set to a new value.

@@ -476,3 +453,3 @@ *

*/
withFieldValue(field, newValue) {
_withField(field, newValue) {
requireNonNull(field, 'field');

@@ -539,15 +516,3 @@ if (field instanceof ChronoField) {

//-----------------------------------------------------------------------
/**
* @param {!TemporalAmount} amount
* @return {Instant}
* @throws DateTimeException
* @throws ArithmeticException
*/
plusAmount(amount) {
requireNonNull(amount, 'amount');
return amount.addTo(this);
}
/**
* @param {!number} amountToAdd

@@ -559,3 +524,3 @@ * @param {!TemporalUnit} unit

*/
plusAmountUnit(amountToAdd, unit) {
_plusUnit(amountToAdd, unit) {
requireNonNull(amountToAdd, 'amountToAdd');

@@ -643,13 +608,2 @@ requireNonNull(unit, 'unit');

/**
* @param {!TemporalAmount} amount
* @return {Instant}
* @throws DateTimeException
* @throws ArithmeticException
*/
minusAmount(amount) {
requireNonNull(amount, 'amount');
return amount.subtractFrom(this);
}
/**
* @param {!number} amountToSubtract

@@ -661,4 +615,4 @@ * @param {!TemporalUnit} unit

*/
minusAmountUnit(amountToSubtract, unit) {
return this.plusAmountUnit(-1 * amountToSubtract, unit);
_minusUnit(amountToSubtract, unit) {
return this._plusUnit(-1 * amountToSubtract, unit);
}

@@ -817,3 +771,3 @@

case ChronoUnit.NANOS: return this._nanosUntil(end);
case ChronoUnit.MICROS: return MathUtil.intDiv(this._nanosUntil(end), 1000);
case ChronoUnit.MICROS: return this._microsUntil(end);
case ChronoUnit.MILLIS: return MathUtil.safeSubtract(end.toEpochMilli(), this.toEpochMilli());

@@ -837,2 +791,14 @@ case ChronoUnit.SECONDS: return this._secondsUntil(end);

*/
_microsUntil(end) {
const secsDiff = MathUtil.safeSubtract(end.epochSecond(), this.epochSecond());
const totalMicros = MathUtil.safeMultiply(secsDiff, 1000000);
return MathUtil.safeAdd(totalMicros, MathUtil.intDiv(end.nano() - this.nano(), 1000));
}
/**
*
* @param {Temporal} end
* @returns {number}
* @private
*/
_nanosUntil(end) {

@@ -839,0 +805,0 @@ const secsDiff = MathUtil.safeSubtract(end.epochSecond(), this.epochSecond());

@@ -9,4 +9,4 @@ /**

import {MathUtil} from './MathUtil';
import {assert, requireNonNull, requireInstance} from './assert';
import {DateTimeException, UnsupportedTemporalTypeException, IllegalArgumentException} from './errors';
import {requireNonNull, requireInstance} from './assert';
import {DateTimeException, UnsupportedTemporalTypeException} from './errors';

@@ -16,2 +16,3 @@ import {Clock} from './Clock';

import {ZoneId} from './ZoneId';
import {OffsetTime} from './OffsetTime';

@@ -526,3 +527,3 @@ import {DateTimeFormatter} from './format/DateTimeFormatter';

*/
withAdjuster(adjuster) {
_withAdjuster(adjuster) {
requireNonNull(adjuster, 'adjuster');

@@ -533,4 +534,3 @@ // optimizations

}
assert(typeof adjuster.adjustInto === 'function', 'adjuster', IllegalArgumentException);
return adjuster.adjustInto(this);
return super._withAdjuster(adjuster);
}

@@ -618,3 +618,3 @@

*/
withFieldValue(field, newValue) {
_withField(field, newValue) {
requireNonNull(field, 'field');

@@ -751,23 +751,2 @@ requireInstance(field, TemporalField, 'field');

/**
* Returns a copy of this date with the specified period added.
*
* This method returns a new time based on this time with the specified period added.
* The amount is typically {@link Period} but may be any other type implementing
* the {@link TemporalAmount} interface.
* The calculation is delegated to the specified adjuster, which typically calls
* back to {@link plus}.
*
* This instance is immutable and unaffected by this method call.
*
* @param {TemporalAmount} amount - the amount to add, not null
* @return {LocalTime} a {@link LocalTime} based on this time with the addition made, not null
* @throws {DateTimeException} if the addition cannot be made
* @throws {ArithmeticException} if numeric overflow occurs
*/
plusAmount(amount) {
requireNonNull(amount, 'amount');
return amount.addTo(this);
}
/**
* Returns a copy of this time with the specified period added.

@@ -787,3 +766,3 @@ *

*/
plusAmountUnit(amountToAdd, unit) {
_plusUnit(amountToAdd, unit) {
requireNonNull(unit, 'unit');

@@ -911,24 +890,2 @@ if (unit instanceof ChronoUnit) {

* This method returns a new time based on this time with the specified period subtracted.
* The amount is typically {@link Period} but may be any other type implementing
* the {@link TemporalAmount} interface.
* The calculation is delegated to the specified adjuster, which typically calls
* back to {@link minus}.
*
* This instance is immutable and unaffected by this method call.
*
* @param {TemporalAmount} amount - the amount to subtract, not null
* @return {LocalTime} a {@link LocalTime} based on this time with the subtraction made, not null
* @throws {DateTimeException} if the subtraction cannot be made
* @throws {ArithmeticException} if numeric overflow occurs
*/
minusAmount(amount) {
requireNonNull(amount, 'amount');
return amount.subtractFrom(this);
}
/**
* Returns a copy of this time with the specified period subtracted.
*
* This method returns a new time based on this time with the specified period subtracted.
* This can be used to subtract any period that is defined by a unit, for example to subtract hours, minutes or seconds.

@@ -945,5 +902,5 @@ * The unit is responsible for the details of the calculation, including the resolution

*/
minusAmountUnit(amountToSubtract, unit) {
_minusUnit(amountToSubtract, unit) {
requireNonNull(unit, 'unit');
return this.plusAmountUnit(-1 * amountToSubtract, unit);
return this._plusUnit(-1 * amountToSubtract, unit);
}

@@ -1160,7 +1117,5 @@

*/
/*
atOffset(offset) {
return OffsetTime.of(this, offset);
}
*/

@@ -1167,0 +1122,0 @@ //-----------------------------------------------------------------------

@@ -9,5 +9,5 @@ /**

import {ChronoUnit} from './temporal/ChronoUnit';
import {Temporal} from './temporal/Temporal';
import {Clock} from './Clock';
import {DateTimeFormatter} from './format/DateTimeFormatter';
import {DefaultInterfaceTemporal} from './temporal/DefaultInterfaceTemporal';
import {Instant} from './Instant';

@@ -33,3 +33,3 @@ import {IsoChronology} from './chrono/IsoChronology';

*/
export class OffsetDateTime extends DefaultInterfaceTemporal {
export class OffsetDateTime extends Temporal {
/**

@@ -378,3 +378,3 @@ * @param {TemporaroAccessor} temporal

withAdjuster(adjuster) {
_withAdjuster(adjuster) {
requireNonNull(adjuster);

@@ -394,3 +394,3 @@ // optimizations

withFieldValue(field, newValue) {
_withField(field, newValue) {
requireNonNull(field);

@@ -512,3 +512,3 @@ if (field instanceof ChronoField) {

plusAmount(amount) {
_plusAmount(amount) {
requireNonNull(amount, 'amount');

@@ -518,3 +518,3 @@ return amount.addTo(this);

plusAmountUnit(amountToAdd, unit) {
_plusUnit(amountToAdd, unit) {
if (unit instanceof ChronoUnit) {

@@ -590,3 +590,3 @@ return this._withDateTimeOffset(this._dateTime.plus(amountToAdd, unit), this._offset);

minusAmount(amount) {
_minusAmount(amount) {
requireNonNull(amount);

@@ -596,3 +596,3 @@ return amount.subtractFrom(this);

minusAmountUnit(amountToSubtract, unit) {
_minusUnit(amountToSubtract, unit) {
return this.plus(-1 * amountToSubtract, unit);

@@ -599,0 +599,0 @@ }

@@ -9,6 +9,6 @@ /**

import {ChronoUnit} from './temporal/ChronoUnit';
import {Temporal} from './temporal/Temporal';
import {Clock} from './Clock';
import {DateTimeException, UnsupportedTemporalTypeException} from './errors';
import {DateTimeFormatter} from './format/DateTimeFormatter';
import {DefaultInterfaceTemporal} from './temporal/DefaultInterfaceTemporal';
import {Instant, LocalTime} from './js-joda';

@@ -27,3 +27,3 @@ import {MathUtil} from './MathUtil';

*/
export class OffsetTime extends DefaultInterfaceTemporal {
export class OffsetTime extends Temporal {
/**

@@ -323,3 +323,3 @@ * @param {!TemporalAccessor} temporal

minusAmount(amount) {
_minusAmount(amount) {
requireNonNull(amount);

@@ -329,7 +329,7 @@ return amount.subtractFrom(this);

minusAmountUnit(amountToSubtract, unit) {
_minusUnit(amountToSubtract, unit) {
return this.plus(-1 * amountToSubtract, unit);
}
plusAmount(amount) {
_plusAmount(amount) {
requireNonNull(amount);

@@ -345,3 +345,3 @@ return amount.addTo(this);

*/
plusAmountUnit(amountToAdd, unit) {
_plusUnit(amountToAdd, unit) {
if (unit instanceof ChronoUnit) {

@@ -523,3 +523,3 @@ return this._withLocalTimeOffset(this._time.plus(amountToAdd, unit), this._offset);

withAdjuster(adjuster) {
_withAdjuster(adjuster) {
requireNonNull(adjuster, 'adjuster');

@@ -537,3 +537,3 @@ // optimizations

withFieldValue(field, newValue) {
_withField(field, newValue) {
requireNonNull(field, 'field');

@@ -540,0 +540,0 @@ if (field instanceof ChronoField) {

@@ -7,4 +7,8 @@ /*

import {assert, abstractMethodFail, requireInstance, requireNonNull} from '../assert';
import {IllegalArgumentException} from '../errors';
import {MAX_SAFE_INTEGER, MIN_SAFE_INTEGER} from '../MathUtil';
import {TemporalAccessor} from './TemporalAccessor';
import { abstractMethodFail } from '../assert';
import {TemporalAmount} from './TemporalAmount';
import {TemporalUnit} from './TemporalUnit';

@@ -76,7 +80,7 @@ /**

* @param {TemporalUnit} unit - the unit to check, null returns false
* @param {TemporalUnit} fieldOrUnit - the unit to check, null returns false
* @return {boolean} true if this date-time can be queried for the unit, false if not
*/
// eslint-disable-next-line no-unused-vars
isSupported(unit) {
isSupported(fieldOrUnit) {
abstractMethodFail('isSupported');

@@ -92,12 +96,11 @@ }

*
* @param {!(TemporalAmount|number)} p1
* @param {TemporalUnit} p2
* @param {!(TemporalAmount|number)} amount
* @param {TemporalUnit} unit
* @return {Temporal}
*/
// eslint-disable-next-line no-unused-vars
minus(p1, p2) {
minus(amount, unit) {
if (arguments.length < 2) {
return this.minusAmount(p1);
return this._minusAmount(amount);
} else {
return this.minusAmountUnit(p1, p2);
return this._minusUnit(amount, unit);
}

@@ -131,5 +134,6 @@ }

*/
// eslint-disable-next-line no-unused-vars
minusAmount(amount) {
abstractMethodFail('minusAmount');
_minusAmount(amount) {
requireNonNull(amount, 'amount');
requireInstance(amount, TemporalAmount, 'amount');
return amount.subtractFrom(this);
}

@@ -155,5 +159,9 @@

*/
// eslint-disable-next-line no-unused-vars
minusAmountUnit(amountToSubtract, unit) {
abstractMethodFail('minusAmountUnit');
_minusUnit(amountToSubtract, unit) {
requireNonNull(amountToSubtract, 'amountToSubtract');
requireNonNull(unit, 'unit');
requireInstance(unit, TemporalUnit, 'unit');
return (amountToSubtract === MIN_SAFE_INTEGER
? this._plusUnit(MAX_SAFE_INTEGER, unit)._plusUnit(1, unit)
: this._plusUnit(-amountToSubtract, unit));
}

@@ -168,12 +176,11 @@

*
* @param {!(TemporalAmount|number)} p1
* @param {TemporalUnit} p2
* @param {!(TemporalAmount|number)} amount
* @param {TemporalUnit} unit
* @return {Temporal}
*/
// eslint-disable-next-line no-unused-vars
plus(p1, p2) {
plus(amount, unit) {
if (arguments.length < 2) {
return this.plusAmount(p1);
return this._plusAmount(amount);
} else {
return this.plusAmountUnit(p1, p2);
return this._plusUnit(amount, unit);
}

@@ -204,5 +211,6 @@ }

*/
// eslint-disable-next-line no-unused-vars
plusAmount(amount) {
abstractMethodFail('plusAmount');
_plusAmount(amount) {
requireNonNull(amount, 'amount');
requireInstance(amount, TemporalAmount, 'amount');
return amount.addTo(this);
}

@@ -231,4 +239,4 @@

// eslint-disable-next-line no-unused-vars
plusAmountUnit(amountToAdd, unit) {
abstractMethodFail('plusAmountUnit');
_plusUnit(amountToAdd, unit) {
abstractMethodFail('_plusUnit');
}

@@ -294,12 +302,11 @@

*
* @param {!(TemporalAdjuster|TemporalField)} p1
* @param {number} p2
* @param {!(TemporalAdjuster|TemporalField)} adjusterOrField
* @param {number} newValue
* @return {Temporal}
*/
// eslint-disable-next-line no-unused-vars
with(p1, p2) {
with(adjusterOrField, newValue) {
if (arguments.length < 2) {
return this.withAdjuster(p1);
return this._withAdjuster(adjusterOrField);
} else {
return this.withFieldValue(p1, p2);
return this._withField(adjusterOrField, newValue);
}

@@ -328,5 +335,8 @@ }

*/
// eslint-disable-next-line no-unused-vars
withAdjuster(adjuster) {
abstractMethodFail('withAdjuster');
_withAdjuster(adjuster) {
requireNonNull(adjuster, 'adjuster');
assert(typeof adjuster.adjustInto === 'function',
'adjuster must be a TemporalAdjuster',
IllegalArgumentException);
return adjuster.adjustInto(this);
}

@@ -353,5 +363,5 @@

// eslint-disable-next-line no-unused-vars
withFieldValue(field, newValue) {
abstractMethodFail('withFieldValue');
_withField(field, newValue) {
abstractMethodFail('_withField');
}
}

@@ -8,2 +8,3 @@ /**

import {UnsupportedTemporalTypeException} from '../errors';
import {abstractMethodFail} from '../assert';

@@ -87,2 +88,7 @@ import {ChronoField} from './ChronoField';

// eslint-disable-next-line no-unused-vars
getLong(field) {
abstractMethodFail('getLong');
}
/**

@@ -127,2 +133,6 @@ * Gets the range of valid values for the specified field.

// eslint-disable-next-line no-unused-vars
isSupported(field) {
abstractMethodFail('isSupported');
}
}

@@ -23,3 +23,2 @@ /**

import {TemporalAccessor} from './temporal/TemporalAccessor';
import {TemporalAmount} from './temporal/TemporalAmount';
import {TemporalField} from './temporal/TemporalField';

@@ -469,25 +468,2 @@ import {TemporalQueries} from './temporal/TemporalQueries';

/**
* Returns an adjusted copy of this year.
*
* This returns a new {@link Year}, based on this one, with the year adjusted.
* The adjustment takes place using the specified adjuster strategy object.
* Read the documentation of the adjuster to understand what adjustment will be made.
*
* The result of this method is obtained by invoking the
* {@link TemporalAdjuster#adjustInto} method on the
* specified adjuster passing `this` as the argument.
*
* This instance is immutable and unaffected by this method call.
*
* @param {TemporalAdjuster} adjuster the adjuster to use, not null
* @returns {Year} based on `this` with the adjustment made, not null
* @throws DateTimeException if the adjustment cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
withAdjuster(adjuster) {
requireNonNull(adjuster, 'adjuster');
return adjuster.adjustInto(this);
}
/**
* Returns a copy of this year with the specified field set to a new value.

@@ -531,3 +507,3 @@ *

*/
withFieldValue(field, newValue) {
_withField(field, newValue) {
requireNonNull(field, 'field');

@@ -551,24 +527,2 @@ requireInstance(field, TemporalField, 'field');

/**
* Returns a copy of this year with the specified period added.
*
* This method returns a new year based on this year with the specified period added.
* The adder is typically {@link Period} but may be any other type implementing
* the {@link TemporalAmount} interface.
* The calculation is delegated to the specified adjuster, which typically calls
* back to {@link plus}.
*
* This instance is immutable and unaffected by this method call.
*
* @param {TemporalAmount} amount the amount to add, not null
* @return {Year} based on this year with the addition made, not null
* @throws DateTimeException if the addition cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
plusAmount(amount) {
requireNonNull(amount, 'amount');
requireInstance(amount, TemporalAmount, 'amount');
return amount.addTo(this);
}
/**
* @param {number} amountToAdd

@@ -580,3 +534,3 @@ * @param {TemporalUnit} unit

*/
plusAmountUnit(amountToAdd, unit) {
_plusUnit(amountToAdd, unit) {
requireNonNull(amountToAdd, 'amountToAdd');

@@ -617,38 +571,2 @@ requireNonNull(unit, 'unit');

/**
* Returns a copy of this year with the specified period subtracted.
*
* This method returns a new year based on this year with the specified period subtracted.
* The subtractor is typically {@link Period} but may be any other type implementing
* the {@link TemporalAmount} interface.
* The calculation is delegated to the specified adjuster, which typically calls
* back to {@link minus}.
*
* This instance is immutable and unaffected by this method call.
*
* @param {TemporalAmount} amount the amount to subtract, not null
* @return {Year} based on this year with the subtraction made, not null
* @throws DateTimeException if the subtraction cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
minusAmount(amount) {
requireNonNull(amount, 'amount');
requireInstance(amount, TemporalAmount, 'amount');
return amount.subtractFrom(this);
}
/**
* @param {number} amountToSubtract the amount to subtract, not null
* @param {TemporalUnit} unit
* @return {Year} based on this year with the subtraction made, not null
* @throws DateTimeException if the subtraction cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
minusAmountUnit(amountToSubtract, unit) {
requireNonNull(amountToSubtract, 'amountToSubtract');
requireNonNull(unit, 'unit');
requireInstance(unit, TemporalUnit, 'unit');
return (amountToSubtract === MathUtil.MIN_SAFE_INTEGER ? this.plus(MathUtil.MAX_SAFE_INTEGER, unit).plus(1, unit) : this.plus(-amountToSubtract, unit));
}
/**
* Returns a copy of this year with the specified number of years subtracted.

@@ -655,0 +573,0 @@ *

@@ -19,3 +19,2 @@ /*

import {Temporal} from './temporal/Temporal';
import {TemporalAmount} from './temporal/TemporalAmount';
import {TemporalField} from './temporal/TemporalField';

@@ -544,5 +543,5 @@ import {TemporalQueries} from './temporal/TemporalQueries';

if (arguments.length === 1) {
return this.withAdjuster(adjusterOrField);
return this._withAdjuster(adjusterOrField);
} else {
return this.withFieldValue(adjusterOrField, value);
return this._withField(adjusterOrField, value);
}

@@ -552,29 +551,2 @@ }

/**
* Returns an adjusted copy of this year-month.
*
* This returns a new {@link YearMonth}, based on this one, with the year-month adjusted.
* The adjustment takes place using the specified adjuster strategy object.
* Read the documentation of the adjuster to understand what adjustment will be made.
*
* A simple adjuster might simply set the one of the fields, such as the year field.
* A more complex adjuster might set the year-month to the next month that
* Halley's comet will pass the Earth.
*
* The result of this method is obtained by invoking the
* {@link TemporalAdjuster#adjustInto} method on the
* specified adjuster passing `this` as the argument.
*
* This instance is immutable and unaffected by this method call.
*
* @param {TemporalAdjuster} adjuster the adjuster to use, not null
* @return {YearMonth} based on `this` with the adjustment made, not null
* @throws DateTimeException if the adjustment cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
withAdjuster(adjuster) {
requireNonNull(adjuster, 'adjuster');
return adjuster.adjustInto(this);
}
/**
* Returns a copy of this year-month with the specified field set to a new value.

@@ -625,3 +597,3 @@ *

*/
withFieldValue(field, newValue) {
_withField(field, newValue) {
requireNonNull(field, 'field');

@@ -676,24 +648,2 @@ requireInstance(field, TemporalField, 'field');

/**
* Returns a copy of this year-month with the specified period added.
*
* This method returns a new year-month based on this year-month with the specified period added.
* The adder is typically {@link Period} but may be any other type implementing
* the {@link TemporalAmount} interface.
* The calculation is delegated to the specified adjuster, which typically calls
* back to {@link plus}.
*
* This instance is immutable and unaffected by this method call.
*
* @param {TemporalAmount} amount the amount to add, not null
* @return {YearMonth} based on this year-month with the addition made, not null
* @throws DateTimeException if the addition cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
plusAmount(amount) {
requireNonNull(amount, 'amount');
requireInstance(amount, TemporalAmount, 'amount');
return amount.addTo(this);
}
/**
* @param {number} amountToAdd

@@ -705,3 +655,3 @@ * @param {TemporalUnit} unit

*/
plusAmountUnit(amountToAdd, unit) {
_plusUnit(amountToAdd, unit) {
requireNonNull(unit, 'unit');

@@ -763,34 +713,2 @@ requireInstance(unit, TemporalUnit, 'unit');

/**
* Returns a copy of this year-month with the specified period subtracted.
*
* This method returns a new year-month based on this year-month with the specified period subtracted.
* The subtractor is typically {@link Period} but may be any other type implementing
* the {@link TemporalAmount} interface.
* The calculation is delegated to the specified adjuster, which typically calls
* back to {@link minus}.
*
* This instance is immutable and unaffected by this method call.
*
* @param {TemporalAmount} amount the amount to subtract, not null
* @return {YearMonth} based on this year-month with the subtraction made, not null
* @throws DateTimeException if the subtraction cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
minusAmount(amount) {
requireNonNull(amount, 'amount');
return amount.subtractFrom(this);
}
/**
* @param {number} amountToSubtract the amount to subtract, not null
* @param {TemporalUnit} unit
* @return {YearMonth} based on this year-month with the subtraction made, not null
* @throws DateTimeException if the subtraction cannot be made
* @throws ArithmeticException if numeric overflow occurs
*/
minusAmountUnit(amountToSubtract, unit) {
return (amountToSubtract === MathUtil.MIN_SAFE_INTEGER ? this.plusAmountUnit(MathUtil.MAX_SAFE_INTEGER, unit).plusAmountUnit(1, unit) : this.plusAmountUnit(-amountToSubtract, unit));
}
/**
* Returns a copy of this year-month with the specified period in years subtracted.

@@ -797,0 +715,0 @@ *

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc