aboutsummaryrefslogtreecommitdiffstats
path: root/npm_assets/node_modules/luxon/src/datetime.js
diff options
context:
space:
mode:
Diffstat (limited to 'npm_assets/node_modules/luxon/src/datetime.js')
-rw-r--r--npm_assets/node_modules/luxon/src/datetime.js186
1 files changed, 116 insertions, 70 deletions
diff --git a/npm_assets/node_modules/luxon/src/datetime.js b/npm_assets/node_modules/luxon/src/datetime.js
index 01532ff..61ef8b4 100644
--- a/npm_assets/node_modules/luxon/src/datetime.js
+++ b/npm_assets/node_modules/luxon/src/datetime.js
@@ -197,6 +197,7 @@ function toTechTimeFormat(
suppressSeconds = false,
suppressMilliseconds = false,
includeOffset,
+ includePrefix = false,
includeZone = false,
spaceZone = false,
format = "extended"
@@ -221,7 +222,13 @@ function toTechTimeFormat(
fmt += format === "basic" ? "ZZZ" : "ZZ";
}
- return toTechFormat(dt, fmt);
+ let str = toTechFormat(dt, fmt);
+
+ if (includePrefix) {
+ str = "T" + str;
+ }
+
+ return str;
}
// defaults for unspecified units in the supported calendars
@@ -353,7 +360,7 @@ function diffRelative(start, end, opts) {
return format(count, unit);
}
}
- return format(0, opts.units[opts.units.length - 1]);
+ return format(start > end ? -0 : 0, opts.units[opts.units.length - 1]);
}
/**
@@ -441,10 +448,21 @@ export default class DateTime {
// CONSTRUCT
/**
+ * Create a DateTime for the current instant, in the system's time zone.
+ *
+ * Use Settings to override these default values if needed.
+ * @example DateTime.now().toISO() //~> now in the ISO format
+ * @return {DateTime}
+ */
+ static now() {
+ return new DateTime({});
+ }
+
+ /**
* Create a local DateTime
* @param {number} [year] - The calendar year. If omitted (as in, call `local()` with no arguments), the current time will be used
* @param {number} [month=1] - The month, 1-indexed
- * @param {number} [day=1] - The day of the month
+ * @param {number} [day=1] - The day of the month, 1-indexed
* @param {number} [hour=0] - The hour of the day, in 24-hour time
* @param {number} [minute=0] - The minute of the hour, meaning a number between 0 and 59
* @param {number} [second=0] - The second of the minute, meaning a number between 0 and 59
@@ -461,7 +479,7 @@ export default class DateTime {
*/
static local(year, month, day, hour, minute, second, millisecond) {
if (isUndefined(year)) {
- return new DateTime({ ts: Settings.now() });
+ return DateTime.now();
} else {
return quickDT(
{
@@ -520,8 +538,8 @@ export default class DateTime {
}
/**
- * Create a DateTime from a Javascript Date object. Uses the default zone.
- * @param {Date} date - a Javascript Date object
+ * Create a DateTime from a JavaScript Date object. Uses the default zone.
+ * @param {Date} date - a JavaScript Date object
* @param {Object} options - configuration options for the DateTime
* @param {string|Zone} [options.zone='local'] - the zone to place the DateTime into
* @return {DateTime}
@@ -594,7 +612,7 @@ export default class DateTime {
}
/**
- * Create a DateTime from a Javascript object with keys like 'year' and 'hour' with reasonable defaults.
+ * Create a DateTime from a JavaScript object with keys like 'year' and 'hour' with reasonable defaults.
* @param {Object} obj - the object to create the DateTime from
* @param {number} obj.year - a year, such as 1987
* @param {number} obj.month - a month, 1-12
@@ -733,8 +751,8 @@ export default class DateTime {
* @param {string|Zone} [opts.zone='local'] - use this zone if no offset is specified in the input string itself. Will also convert the time to this zone
* @param {boolean} [opts.setZone=false] - override the zone with a fixed-offset zone specified in the string itself, if it specifies one
* @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance
- * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
- * @param {string} opts.numberingSystem - the numbering system to set on the resulting DateTime instance
+ * @param {string} [opts.outputCalendar] - the output calendar to set on the resulting DateTime instance
+ * @param {string} [opts.numberingSystem] - the numbering system to set on the resulting DateTime instance
* @example DateTime.fromISO('2016-05-25T09:08:34.123')
* @example DateTime.fromISO('2016-05-25T09:08:34.123+06:00')
* @example DateTime.fromISO('2016-05-25T09:08:34.123+06:00', {setZone: true})
@@ -1037,7 +1055,7 @@ export default class DateTime {
/**
* Get the week year
* @see https://en.wikipedia.org/wiki/ISO_week_date
- * @example DateTime.local(2014, 11, 31).weekYear //=> 2015
+ * @example DateTime.local(2014, 12, 31).weekYear //=> 2015
* @type {number}
*/
get weekYear() {
@@ -1081,7 +1099,7 @@ export default class DateTime {
* @type {string}
*/
get monthShort() {
- return this.isValid ? Info.months("short", { locale: this.locale })[this.month - 1] : null;
+ return this.isValid ? Info.months("short", { locObj: this.loc })[this.month - 1] : null;
}
/**
@@ -1091,7 +1109,7 @@ export default class DateTime {
* @type {string}
*/
get monthLong() {
- return this.isValid ? Info.months("long", { locale: this.locale })[this.month - 1] : null;
+ return this.isValid ? Info.months("long", { locObj: this.loc })[this.month - 1] : null;
}
/**
@@ -1101,7 +1119,7 @@ export default class DateTime {
* @type {string}
*/
get weekdayShort() {
- return this.isValid ? Info.weekdays("short", { locale: this.locale })[this.weekday - 1] : null;
+ return this.isValid ? Info.weekdays("short", { locObj: this.loc })[this.weekday - 1] : null;
}
/**
@@ -1111,12 +1129,12 @@ export default class DateTime {
* @type {string}
*/
get weekdayLong() {
- return this.isValid ? Info.weekdays("long", { locale: this.locale })[this.weekday - 1] : null;
+ return this.isValid ? Info.weekdays("long", { locObj: this.loc })[this.weekday - 1] : null;
}
/**
* Get the UTC offset of this DateTime in minutes
- * @example DateTime.local().offset //=> -240
+ * @example DateTime.now().offset //=> -240
* @example DateTime.utc().offset //=> 0
* @type {number}
*/
@@ -1321,7 +1339,22 @@ export default class DateTime {
settingWeekStuff =
!isUndefined(normalized.weekYear) ||
!isUndefined(normalized.weekNumber) ||
- !isUndefined(normalized.weekday);
+ !isUndefined(normalized.weekday),
+ containsOrdinal = !isUndefined(normalized.ordinal),
+ containsGregorYear = !isUndefined(normalized.year),
+ containsGregorMD = !isUndefined(normalized.month) || !isUndefined(normalized.day),
+ containsGregor = containsGregorYear || containsGregorMD,
+ definiteWeekDef = normalized.weekYear || normalized.weekNumber;
+
+ if ((containsGregor || containsOrdinal) && definiteWeekDef) {
+ throw new ConflictingSpecificationError(
+ "Can't mix weekYear/weekNumber units with year/month/day or ordinals"
+ );
+ }
+
+ if (containsGregorMD && containsOrdinal) {
+ throw new ConflictingSpecificationError("Can't mix ordinal dates with month/day");
+ }
let mixed;
if (settingWeekStuff) {
@@ -1347,12 +1380,12 @@ export default class DateTime {
*
* Adding hours, minutes, seconds, or milliseconds increases the timestamp by the right number of milliseconds. Adding days, months, or years shifts the calendar, accounting for DSTs and leap years along the way. Thus, `dt.plus({ hours: 24 })` may result in a different time than `dt.plus({ days: 1 })` if there's a DST shift in between.
* @param {Duration|Object|number} duration - The amount to add. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
- * @example DateTime.local().plus(123) //~> in 123 milliseconds
- * @example DateTime.local().plus({ minutes: 15 }) //~> in 15 minutes
- * @example DateTime.local().plus({ days: 1 }) //~> this time tomorrow
- * @example DateTime.local().plus({ days: -1 }) //~> this time yesterday
- * @example DateTime.local().plus({ hours: 3, minutes: 13 }) //~> in 3 hr, 13 min
- * @example DateTime.local().plus(Duration.fromObject({ hours: 3, minutes: 13 })) //~> in 3 hr, 13 min
+ * @example DateTime.now().plus(123) //~> in 123 milliseconds
+ * @example DateTime.now().plus({ minutes: 15 }) //~> in 15 minutes
+ * @example DateTime.now().plus({ days: 1 }) //~> this time tomorrow
+ * @example DateTime.now().plus({ days: -1 }) //~> this time yesterday
+ * @example DateTime.now().plus({ hours: 3, minutes: 13 }) //~> in 3 hr, 13 min
+ * @example DateTime.now().plus(Duration.fromObject({ hours: 3, minutes: 13 })) //~> in 3 hr, 13 min
* @return {DateTime}
*/
plus(duration) {
@@ -1378,6 +1411,7 @@ export default class DateTime {
* @param {string} unit - The unit to go to the beginning of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
* @example DateTime.local(2014, 3, 3).startOf('month').toISODate(); //=> '2014-03-01'
* @example DateTime.local(2014, 3, 3).startOf('year').toISODate(); //=> '2014-01-01'
+ * @example DateTime.local(2014, 3, 3).startOf('week').toISODate(); //=> '2014-03-03', weeks always start on Mondays
* @example DateTime.local(2014, 3, 3, 5, 30).startOf('day').toISOTime(); //=> '00:00.000-05:00'
* @example DateTime.local(2014, 3, 3, 5, 30).startOf('hour').toISOTime(); //=> '05:00:00.000-05:00'
* @return {DateTime}
@@ -1426,9 +1460,10 @@ export default class DateTime {
/**
* "Set" this DateTime to the end (meaning the last millisecond) of a unit of time
- * @param {string} unit - The unit to go to the end of. Can be 'year', 'month', 'day', 'hour', 'minute', 'second', or 'millisecond'.
+ * @param {string} unit - The unit to go to the end of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
* @example DateTime.local(2014, 3, 3).endOf('month').toISO(); //=> '2014-03-31T23:59:59.999-05:00'
* @example DateTime.local(2014, 3, 3).endOf('year').toISO(); //=> '2014-12-31T23:59:59.999-05:00'
+ * @example DateTime.local(2014, 3, 3).endOf('week').toISO(); // => '2014-03-09T23:59:59.999-05:00', weeks start on Mondays
* @example DateTime.local(2014, 3, 3, 5, 30).endOf('day').toISO(); //=> '2014-03-03T23:59:59.999-05:00'
* @example DateTime.local(2014, 3, 3, 5, 30).endOf('hour').toISO(); //=> '2014-03-03T05:59:59.999-05:00'
* @return {DateTime}
@@ -1450,10 +1485,10 @@ export default class DateTime {
* @see https://moment.github.io/luxon/docs/manual/formatting.html#table-of-tokens
* @param {string} fmt - the format string
* @param {Object} opts - opts to override the configuration options
- * @example DateTime.local().toFormat('yyyy LLL dd') //=> '2017 Apr 22'
- * @example DateTime.local().setLocale('fr').toFormat('yyyy LLL dd') //=> '2017 avr. 22'
- * @example DateTime.local().toFormat('yyyy LLL dd', { locale: "fr" }) //=> '2017 avr. 22'
- * @example DateTime.local().toFormat("HH 'hours and' mm 'minutes'") //=> '20 hours and 55 minutes'
+ * @example DateTime.now().toFormat('yyyy LLL dd') //=> '2017 Apr 22'
+ * @example DateTime.now().setLocale('fr').toFormat('yyyy LLL dd') //=> '2017 avr. 22'
+ * @example DateTime.now().toFormat('yyyy LLL dd', { locale: "fr" }) //=> '2017 avr. 22'
+ * @example DateTime.now().toFormat("HH 'hours and' mm 'minutes'") //=> '20 hours and 55 minutes'
* @return {string}
*/
toFormat(fmt, opts = {}) {
@@ -1469,15 +1504,15 @@ export default class DateTime {
* Defaults to the system's locale if no locale has been specified
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
* @param opts {Object} - Intl.DateTimeFormat constructor options and configuration options
- * @example DateTime.local().toLocaleString(); //=> 4/20/2017
- * @example DateTime.local().setLocale('en-gb').toLocaleString(); //=> '20/04/2017'
- * @example DateTime.local().toLocaleString({ locale: 'en-gb' }); //=> '20/04/2017'
- * @example DateTime.local().toLocaleString(DateTime.DATE_FULL); //=> 'April 20, 2017'
- * @example DateTime.local().toLocaleString(DateTime.TIME_SIMPLE); //=> '11:32 AM'
- * @example DateTime.local().toLocaleString(DateTime.DATETIME_SHORT); //=> '4/20/2017, 11:32 AM'
- * @example DateTime.local().toLocaleString({ weekday: 'long', month: 'long', day: '2-digit' }); //=> 'Thursday, April 20'
- * @example DateTime.local().toLocaleString({ weekday: 'short', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' }); //=> 'Thu, Apr 20, 11:27 AM'
- * @example DateTime.local().toLocaleString({ hour: '2-digit', minute: '2-digit', hour12: false }); //=> '11:32'
+ * @example DateTime.now().toLocaleString(); //=> 4/20/2017
+ * @example DateTime.now().setLocale('en-gb').toLocaleString(); //=> '20/04/2017'
+ * @example DateTime.now().toLocaleString({ locale: 'en-gb' }); //=> '20/04/2017'
+ * @example DateTime.now().toLocaleString(DateTime.DATE_FULL); //=> 'April 20, 2017'
+ * @example DateTime.now().toLocaleString(DateTime.TIME_SIMPLE); //=> '11:32 AM'
+ * @example DateTime.now().toLocaleString(DateTime.DATETIME_SHORT); //=> '4/20/2017, 11:32 AM'
+ * @example DateTime.now().toLocaleString({ weekday: 'long', month: 'long', day: '2-digit' }); //=> 'Thursday, April 20'
+ * @example DateTime.now().toLocaleString({ weekday: 'short', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' }); //=> 'Thu, Apr 20, 11:27 AM'
+ * @example DateTime.now().toLocaleString({ hour: '2-digit', minute: '2-digit', hour12: false }); //=> '11:32'
* @return {string}
*/
toLocaleString(opts = Formats.DATE_SHORT) {
@@ -1491,7 +1526,7 @@ export default class DateTime {
* Defaults to the system's locale if no locale has been specified
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts
* @param opts {Object} - Intl.DateTimeFormat constructor options, same as `toLocaleString`.
- * @example DateTime.local().toLocaleParts(); //=> [
+ * @example DateTime.now().toLocaleParts(); //=> [
* //=> { type: 'day', value: '25' },
* //=> { type: 'literal', value: '/' },
* //=> { type: 'month', value: '05' },
@@ -1513,9 +1548,9 @@ export default class DateTime {
* @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
* @param {string} [opts.format='extended'] - choose between the basic and extended format
* @example DateTime.utc(1982, 5, 25).toISO() //=> '1982-05-25T00:00:00.000Z'
- * @example DateTime.local().toISO() //=> '2017-04-22T20:47:05.335-04:00'
- * @example DateTime.local().toISO({ includeOffset: false }) //=> '2017-04-22T20:47:05.335'
- * @example DateTime.local().toISO({ format: 'basic' }) //=> '20170422T204705.335-0400'
+ * @example DateTime.now().toISO() //=> '2017-04-22T20:47:05.335-04:00'
+ * @example DateTime.now().toISO({ includeOffset: false }) //=> '2017-04-22T20:47:05.335'
+ * @example DateTime.now().toISO({ format: 'basic' }) //=> '20170422T204705.335-0400'
* @return {string}
*/
toISO(opts = {}) {
@@ -1558,22 +1593,26 @@ export default class DateTime {
* @param {boolean} [opts.suppressMilliseconds=false] - exclude milliseconds from the format if they're 0
* @param {boolean} [opts.suppressSeconds=false] - exclude seconds from the format if they're 0
* @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
+ * @param {boolean} [opts.includePrefix=false] - include the `T` prefix
* @param {string} [opts.format='extended'] - choose between the basic and extended format
* @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime() //=> '07:34:19.361Z'
* @example DateTime.utc().set({ hour: 7, minute: 34, seconds: 0, milliseconds: 0 }).toISOTime({ suppressSeconds: true }) //=> '07:34Z'
* @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ format: 'basic' }) //=> '073419.361Z'
+ * @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ includePrefix: true }) //=> 'T07:34:19.361Z'
* @return {string}
*/
toISOTime({
suppressMilliseconds = false,
suppressSeconds = false,
includeOffset = true,
+ includePrefix = false,
format = "extended"
} = {}) {
return toTechTimeFormat(this, {
suppressSeconds,
suppressMilliseconds,
includeOffset,
+ includePrefix,
format
});
}
@@ -1615,9 +1654,9 @@ export default class DateTime {
* @param {boolean} [opts.includeZone=false] - include the zone, such as 'America/New_York'. Overrides includeOffset.
* @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00'
* @example DateTime.utc().toSQL() //=> '05:15:16.345'
- * @example DateTime.local().toSQL() //=> '05:15:16.345 -04:00'
- * @example DateTime.local().toSQL({ includeOffset: false }) //=> '05:15:16.345'
- * @example DateTime.local().toSQL({ includeZone: false }) //=> '05:15:16.345 America/New_York'
+ * @example DateTime.now().toSQL() //=> '05:15:16.345 -04:00'
+ * @example DateTime.now().toSQL({ includeOffset: false }) //=> '05:15:16.345'
+ * @example DateTime.now().toSQL({ includeZone: false }) //=> '05:15:16.345 America/New_York'
* @return {string}
*/
toSQLTime({ includeOffset = true, includeZone = false } = {}) {
@@ -1696,10 +1735,10 @@ export default class DateTime {
}
/**
- * Returns a Javascript object with this DateTime's year, month, day, and so on.
+ * Returns a JavaScript object with this DateTime's year, month, day, and so on.
* @param opts - options for generating the object
* @param {boolean} [opts.includeConfig=false] - include configuration attributes in the output
- * @example DateTime.local().toObject() //=> { year: 2017, month: 4, day: 22, hour: 20, minute: 49, second: 42, millisecond: 268 }
+ * @example DateTime.now().toObject() //=> { year: 2017, month: 4, day: 22, hour: 20, minute: 49, second: 42, millisecond: 268 }
* @return {Object}
*/
toObject(opts = {}) {
@@ -1716,7 +1755,7 @@ export default class DateTime {
}
/**
- * Returns a Javascript Date equivalent to this DateTime.
+ * Returns a JavaScript Date equivalent to this DateTime.
* @return {Date}
*/
toJSDate() {
@@ -1771,7 +1810,7 @@ export default class DateTime {
* @return {Duration}
*/
diffNow(unit = "milliseconds", opts = {}) {
- return this.diff(DateTime.local(), unit, opts);
+ return this.diff(DateTime.now(), unit, opts);
}
/**
@@ -1784,20 +1823,20 @@ export default class DateTime {
}
/**
- * Return whether this DateTime is in the same unit of time as another DateTime
+ * Return whether this DateTime is in the same unit of time as another DateTime.
+ * Higher-order units must also be identical for this function to return `true`.
+ * Note that time zones are **ignored** in this comparison, which compares the **local** calendar time. Use {@link setZone} to convert one of the dates if needed.
* @param {DateTime} otherDateTime - the other DateTime
* @param {string} unit - the unit of time to check sameness on
- * @example DateTime.local().hasSame(otherDT, 'day'); //~> true if both the same calendar day
+ * @example DateTime.now().hasSame(otherDT, 'day'); //~> true if otherDT is in the same current calendar day
* @return {boolean}
*/
hasSame(otherDateTime, unit) {
if (!this.isValid) return false;
- if (unit === "millisecond") {
- return this.valueOf() === otherDateTime.valueOf();
- } else {
- const inputMs = otherDateTime.valueOf();
- return this.startOf(unit) <= inputMs && inputMs <= this.endOf(unit);
- }
+
+ const inputMs = otherDateTime.valueOf();
+ const otherZoneDateTime = this.setZone(otherDateTime.zone, { keepLocalTime: true });
+ return otherZoneDateTime.startOf(unit) <= inputMs && inputMs <= otherZoneDateTime.endOf(unit);
}
/**
@@ -1821,30 +1860,37 @@ export default class DateTime {
* Returns a string representation of a this time relative to now, such as "in two days". Can only internationalize if your
* platform supports Intl.RelativeTimeFormat. Rounds down by default.
* @param {Object} options - options that affect the output
- * @param {DateTime} [options.base=DateTime.local()] - the DateTime to use as the basis to which this time is compared. Defaults to now.
+ * @param {DateTime} [options.base=DateTime.now()] - the DateTime to use as the basis to which this time is compared. Defaults to now.
* @param {string} [options.style="long"] - the style of units, must be "long", "short", or "narrow"
- * @param {string} options.unit - use a specific unit; if omitted, the method will pick the unit. Use one of "years", "quarters", "months", "weeks", "days", "hours", "minutes", or "seconds"
+ * @param {string|string[]} options.unit - use a specific unit or array of units; if omitted, or an array, the method will pick the best unit. Use an array or one of "years", "quarters", "months", "weeks", "days", "hours", "minutes", or "seconds"
* @param {boolean} [options.round=true] - whether to round the numbers in the output.
- * @param {boolean} [options.padding=0] - padding in milliseconds. This allows you to round up the result if it fits inside the threshold. Don't use in combination with {round: false} because the decimal output will include the padding.
+ * @param {number} [options.padding=0] - padding in milliseconds. This allows you to round up the result if it fits inside the threshold. Don't use in combination with {round: false} because the decimal output will include the padding.
* @param {string} options.locale - override the locale of this DateTime
* @param {string} options.numberingSystem - override the numberingSystem of this DateTime. The Intl system may choose not to honor this
- * @example DateTime.local().plus({ days: 1 }).toRelative() //=> "in 1 day"
- * @example DateTime.local().setLocale("es").toRelative({ days: 1 }) //=> "dentro de 1 día"
- * @example DateTime.local().plus({ days: 1 }).toRelative({ locale: "fr" }) //=> "dans 23 heures"
- * @example DateTime.local().minus({ days: 2 }).toRelative() //=> "2 days ago"
- * @example DateTime.local().minus({ days: 2 }).toRelative({ unit: "hours" }) //=> "48 hours ago"
- * @example DateTime.local().minus({ hours: 36 }).toRelative({ round: false }) //=> "1.5 days ago"
+ * @example DateTime.now().plus({ days: 1 }).toRelative() //=> "in 1 day"
+ * @example DateTime.now().setLocale("es").toRelative({ days: 1 }) //=> "dentro de 1 día"
+ * @example DateTime.now().plus({ days: 1 }).toRelative({ locale: "fr" }) //=> "dans 23 heures"
+ * @example DateTime.now().minus({ days: 2 }).toRelative() //=> "2 days ago"
+ * @example DateTime.now().minus({ days: 2 }).toRelative({ unit: "hours" }) //=> "48 hours ago"
+ * @example DateTime.now().minus({ hours: 36 }).toRelative({ round: false }) //=> "1.5 days ago"
*/
toRelative(options = {}) {
if (!this.isValid) return null;
const base = options.base || DateTime.fromObject({ zone: this.zone }),
padding = options.padding ? (this < base ? -options.padding : options.padding) : 0;
+ let units = ["years", "months", "days", "hours", "minutes", "seconds"];
+ let unit = options.unit;
+ if (Array.isArray(options.unit)) {
+ units = options.unit;
+ unit = undefined;
+ }
return diffRelative(
base,
this.plus(padding),
Object.assign(options, {
numeric: "always",
- units: ["years", "months", "days", "hours", "minutes", "seconds"]
+ units,
+ unit
})
);
}
@@ -1853,14 +1899,14 @@ export default class DateTime {
* Returns a string representation of this date relative to today, such as "yesterday" or "next month".
* Only internationalizes on platforms that supports Intl.RelativeTimeFormat.
* @param {Object} options - options that affect the output
- * @param {DateTime} [options.base=DateTime.local()] - the DateTime to use as the basis to which this time is compared. Defaults to now.
+ * @param {DateTime} [options.base=DateTime.now()] - the DateTime to use as the basis to which this time is compared. Defaults to now.
* @param {string} options.locale - override the locale of this DateTime
* @param {string} options.unit - use a specific unit; if omitted, the method will pick the unit. Use one of "years", "quarters", "months", "weeks", or "days"
* @param {string} options.numberingSystem - override the numberingSystem of this DateTime. The Intl system may choose not to honor this
- * @example DateTime.local().plus({ days: 1 }).toRelativeCalendar() //=> "tomorrow"
- * @example DateTime.local().setLocale("es").plus({ days: 1 }).toRelative() //=> ""mañana"
- * @example DateTime.local().plus({ days: 1 }).toRelativeCalendar({ locale: "fr" }) //=> "demain"
- * @example DateTime.local().minus({ days: 2 }).toRelativeCalendar() //=> "2 days ago"
+ * @example DateTime.now().plus({ days: 1 }).toRelativeCalendar() //=> "tomorrow"
+ * @example DateTime.now().setLocale("es").plus({ days: 1 }).toRelative() //=> ""mañana"
+ * @example DateTime.now().plus({ days: 1 }).toRelativeCalendar({ locale: "fr" }) //=> "demain"
+ * @example DateTime.now().minus({ days: 2 }).toRelativeCalendar() //=> "2 days ago"
*/
toRelativeCalendar(options = {}) {
if (!this.isValid) return null;