Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

luxon

Package Overview
Dependencies
Maintainers
1
Versions
145
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

luxon - npm Package Compare versions

Comparing version 1.27.0 to 2.0.0

build/es6/luxon.js

67

package.json
{
"name": "luxon",
"version": "1.27.0",
"version": "2.0.0",
"description": "Immutable date wrapper",

@@ -17,16 +17,11 @@ "author": "Isaac Cambron",

"test": "jest --coverage",
"docs": "esdoc -c docs/index.js",
"site": "cp -r site/** build/",
"lint": "eslint --quiet src test benchmarks",
"lint!": "npm run format && npm run lint",
"api-docs": "mkdir -p build && documentation build src/luxon.js -f html -o build/api-docs",
"copy-site": "mkdir -p build && rsync -a docs/ build/docs && rsync -a site/ build",
"site": "npm run api-docs && npm run copy-site",
"format": "prettier --write 'src/**/*.js' 'test/**/*.js' 'benchmarks/*.js'",
"format-check": "prettier --check 'src/**/*.js' 'test/**/*.js' 'benchmarks/*.js'",
"benchmark": "babel-node benchmarks/index.js",
"codecov": "codecov",
"check-doc-coverage": "babel-node tasks/docCoverage"
"prepare": "husky install"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {

@@ -38,37 +33,21 @@ "*.{js,json}": [

"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/node": "^7.8.7",
"@babel/plugin-external-helpers": "^7.8.3",
"@babel/preset-env": "^7.9.5",
"@rollup/plugin-commonjs": "^11.1.0",
"@rollup/plugin-node-resolve": "^7.1.3",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "latest",
"@babel/core": "^7.14.6",
"@babel/node": "^7.14.7",
"@babel/plugin-external-helpers": "^7.14.5",
"@babel/preset-env": "^7.14.7",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"babel-jest": "^25.3.0",
"benchmark": "latest",
"codecov": ">= 3.6.5",
"core-js": "^3.6.5",
"esdoc": "^1.1.0",
"esdoc-standard-plugin": "latest",
"eslint": "6.4.0",
"eslint-config-defaults": "latest",
"eslint-config-prettier": "6.3.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-babel": "latest",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "10.0.0",
"eslint-plugin-prettier": "3.1.1",
"eslint-plugin-promise": "latest",
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-standard": "^4.0.1",
"codecov": "latest",
"documentation": "latest",
"fs-extra": "^6.0.1",
"full-icu": "^1.3.1",
"husky": "^4.2.5",
"jest": "^25.3.0",
"lint-staged": "^10.1.3",
"prettier": "1.14.3",
"rollup": "^1.32.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-babel-minify": "^6.2.0",
"uglify-es": "^3.3.9"
"husky": "^7.0.0",
"jest": "^27.0.6",
"lint-staged": "^11.0.0",
"prettier": "^2.3.2",
"rollup": "^2.52.7",
"rollup-plugin-terser": "^7.0.2",
"uglify-js": "^3.13.10"
},

@@ -94,2 +73,4 @@ "main": "build/node/luxon.js",

"build/global/luxon.min.js.map",
"build/es6/luxon.js",
"build/es6/luxon.js.map",
"src"

@@ -96,0 +77,0 @@ ],

# Luxon
[![MIT License][license-image]][license] [![Build Status][travis-image]][travis-url] [![NPM version][npm-version-image]][npm-url] [![Coverage Status][test-coverage-image]][test-coverage-url] [![Doc coverage][doc-coverage-image]][doc-url] [![PRs welcome][contributing-image]][contributing-url]
[![MIT License][license-image]][license] [![Build Status][github-action-image]][github-action-url] [![NPM version][npm-version-image]][npm-url] [![Coverage Status][test-coverage-image]][test-coverage-url] [![PRs welcome][contributing-image]][contributing-url]

@@ -11,2 +11,6 @@ Luxon is a library for working with dates and times in JavaScript.

## Upgrading to 2.0
[Guide](https://moment.github.io/luxon/#upgrading)
## Features

@@ -20,11 +24,11 @@ * DateTime, Duration, and Interval types.

[Download/install instructions](https://moment.github.io/luxon/docs/manual/install.html)
[Download/install instructions](https://moment.github.io/luxon/#/install)
## Documentation
* [General documentation][doc-url]
* [API docs](https://moment.github.io/luxon/docs/identifiers.html)
* [Quick tour](https://moment.github.io/luxon/docs/manual/tour.html)
* [For Moment users](https://moment.github.io/luxon/docs/manual/moment.html)
* [Why does Luxon exist?](https://moment.github.io/luxon/docs/manual/why.html)
* [General documentation](https://moment.github.io/luxon/#/?id=luxon)
* [API docs](https://moment.github.io/luxon/api-docs/index.html)
* [Quick tour](https://moment.github.io/luxon/#/tour)
* [For Moment users](https://moment.github.io/luxon/#/moment)
* [Why does Luxon exist?](https://moment.github.io/luxon/#/why)
* [A quick demo](https://moment.github.io/luxon/demo/global.html)

@@ -34,3 +38,3 @@

See [contributing](contributing.md).
See [contributing](CONTRIBUTING.md).

@@ -40,6 +44,6 @@ ![Phasers to stun][phasers-image]

[license-image]: http://img.shields.io/badge/license-MIT-blue.svg
[license]: license.md
[license]: LICENSE.md
[travis-url]: http://travis-ci.org/moment/luxon
[travis-image]: https://api.travis-ci.org/moment/luxon.svg?branch=master
[github-action-image]: https://github.com/moment/luxon/actions/workflows/test.yml/badge.svg
[github-action-url]: https://github.com/moment/luxon/actions/workflows/test.yml

@@ -49,11 +53,8 @@ [npm-url]: https://npmjs.org/package/luxon

[doc-url]: https://moment.github.io/luxon/docs/
[doc-coverage-image]: https://moment.github.io/luxon/docs/badge.svg
[test-coverage-url]: https://codecov.io/gh/moment/luxon
[test-coverage-image]: https://codecov.io/gh/moment/luxon/branch/master/graph/badge.svg
[contributing-url]: https://moment.github.io/luxon/docs/manual/contributing.html
[contributing-url]: https://github.com/moment/luxon/blob/master/contributing.md
[contributing-image]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
[phasers-image]: https://img.shields.io/badge/phasers-stun-brightgreen.svg

@@ -12,3 +12,3 @@ import { InvalidArgumentError, InvalidDurationError, InvalidUnitError } from "./errors.js";

normalizeObject,
roundTo
roundTo,
} from "./impl/util.js";

@@ -26,3 +26,3 @@ import Settings from "./settings.js";

seconds: 7 * 24 * 60 * 60,
milliseconds: 7 * 24 * 60 * 60 * 1000
milliseconds: 7 * 24 * 60 * 60 * 1000,
},

@@ -33,74 +33,71 @@ days: {

seconds: 24 * 60 * 60,
milliseconds: 24 * 60 * 60 * 1000
milliseconds: 24 * 60 * 60 * 1000,
},
hours: { minutes: 60, seconds: 60 * 60, milliseconds: 60 * 60 * 1000 },
minutes: { seconds: 60, milliseconds: 60 * 1000 },
seconds: { milliseconds: 1000 }
seconds: { milliseconds: 1000 },
},
casualMatrix = Object.assign(
{
years: {
quarters: 4,
months: 12,
weeks: 52,
days: 365,
hours: 365 * 24,
minutes: 365 * 24 * 60,
seconds: 365 * 24 * 60 * 60,
milliseconds: 365 * 24 * 60 * 60 * 1000
},
quarters: {
months: 3,
weeks: 13,
days: 91,
hours: 91 * 24,
minutes: 91 * 24 * 60,
seconds: 91 * 24 * 60 * 60,
milliseconds: 91 * 24 * 60 * 60 * 1000
},
months: {
weeks: 4,
days: 30,
hours: 30 * 24,
minutes: 30 * 24 * 60,
seconds: 30 * 24 * 60 * 60,
milliseconds: 30 * 24 * 60 * 60 * 1000
}
casualMatrix = {
years: {
quarters: 4,
months: 12,
weeks: 52,
days: 365,
hours: 365 * 24,
minutes: 365 * 24 * 60,
seconds: 365 * 24 * 60 * 60,
milliseconds: 365 * 24 * 60 * 60 * 1000,
},
lowOrderMatrix
),
quarters: {
months: 3,
weeks: 13,
days: 91,
hours: 91 * 24,
minutes: 91 * 24 * 60,
seconds: 91 * 24 * 60 * 60,
milliseconds: 91 * 24 * 60 * 60 * 1000,
},
months: {
weeks: 4,
days: 30,
hours: 30 * 24,
minutes: 30 * 24 * 60,
seconds: 30 * 24 * 60 * 60,
milliseconds: 30 * 24 * 60 * 60 * 1000,
},
...lowOrderMatrix,
},
daysInYearAccurate = 146097.0 / 400,
daysInMonthAccurate = 146097.0 / 4800,
accurateMatrix = Object.assign(
{
years: {
quarters: 4,
months: 12,
weeks: daysInYearAccurate / 7,
days: daysInYearAccurate,
hours: daysInYearAccurate * 24,
minutes: daysInYearAccurate * 24 * 60,
seconds: daysInYearAccurate * 24 * 60 * 60,
milliseconds: daysInYearAccurate * 24 * 60 * 60 * 1000
},
quarters: {
months: 3,
weeks: daysInYearAccurate / 28,
days: daysInYearAccurate / 4,
hours: (daysInYearAccurate * 24) / 4,
minutes: (daysInYearAccurate * 24 * 60) / 4,
seconds: (daysInYearAccurate * 24 * 60 * 60) / 4,
milliseconds: (daysInYearAccurate * 24 * 60 * 60 * 1000) / 4
},
months: {
weeks: daysInMonthAccurate / 7,
days: daysInMonthAccurate,
hours: daysInMonthAccurate * 24,
minutes: daysInMonthAccurate * 24 * 60,
seconds: daysInMonthAccurate * 24 * 60 * 60,
milliseconds: daysInMonthAccurate * 24 * 60 * 60 * 1000
}
accurateMatrix = {
years: {
quarters: 4,
months: 12,
weeks: daysInYearAccurate / 7,
days: daysInYearAccurate,
hours: daysInYearAccurate * 24,
minutes: daysInYearAccurate * 24 * 60,
seconds: daysInYearAccurate * 24 * 60 * 60,
milliseconds: daysInYearAccurate * 24 * 60 * 60 * 1000,
},
lowOrderMatrix
);
quarters: {
months: 3,
weeks: daysInYearAccurate / 28,
days: daysInYearAccurate / 4,
hours: (daysInYearAccurate * 24) / 4,
minutes: (daysInYearAccurate * 24 * 60) / 4,
seconds: (daysInYearAccurate * 24 * 60 * 60) / 4,
milliseconds: (daysInYearAccurate * 24 * 60 * 60 * 1000) / 4,
},
months: {
weeks: daysInMonthAccurate / 7,
days: daysInMonthAccurate,
hours: daysInMonthAccurate * 24,
minutes: daysInMonthAccurate * 24 * 60,
seconds: daysInMonthAccurate * 24 * 60 * 60,
milliseconds: daysInMonthAccurate * 24 * 60 * 60 * 1000,
},
...lowOrderMatrix,
};

@@ -117,3 +114,3 @@ // units ordered by size

"seconds",
"milliseconds"
"milliseconds",
];

@@ -127,5 +124,5 @@

const conf = {
values: clear ? alts.values : Object.assign({}, dur.values, alts.values || {}),
values: clear ? alts.values : { ...dur.values, ...(alts.values || {}) },
loc: dur.loc.clone(alts.loc),
conversionAccuracy: alts.conversionAccuracy || dur.conversionAccuracy
conversionAccuracy: alts.conversionAccuracy || dur.conversionAccuracy,
};

@@ -171,6 +168,6 @@ return new Duration(conf);

* * **Creation** To create a Duration, use {@link Duration.fromMillis}, {@link Duration.fromObject}, or {@link Duration.fromISO}.
* * **Unit values** See the {@link Duration.years}, {@link Duration.months}, {@link Duration.weeks}, {@link Duration.days}, {@link Duration.hours}, {@link Duration.minutes}, {@link Duration.seconds}, {@link Duration.milliseconds} accessors.
* * **Configuration** See {@link Duration.locale} and {@link Duration.numberingSystem} accessors.
* * **Transformation** To create new Durations out of old ones use {@link Duration.plus}, {@link Duration.minus}, {@link Duration.normalize}, {@link Duration.set}, {@link Duration.reconfigure}, {@link Duration.shiftTo}, and {@link Duration.negate}.
* * **Output** To convert the Duration into other representations, see {@link Duration.as}, {@link Duration.toISO}, {@link Duration.toFormat}, and {@link Duration.toJSON}
* * **Unit values** See the {@link Duration#years}, {@link Duration.months}, {@link Duration#weeks}, {@link Duration#days}, {@link Duration#hours}, {@link Duration#minutes}, {@link Duration#seconds}, {@link Duration#milliseconds} accessors.
* * **Configuration** See {@link Duration#locale} and {@link Duration#numberingSystem} accessors.
* * **Transformation** To create new Durations out of old ones use {@link Duration#plus}, {@link Duration#minus}, {@link Duration#normalize}, {@link Duration#set}, {@link Duration#reconfigure}, {@link Duration#shiftTo}, and {@link Duration#negate}.
* * **Output** To convert the Duration into other representations, see {@link Duration#as}, {@link Duration#toISO}, {@link Duration#toFormat}, and {@link Duration#toJSON}
*

@@ -221,7 +218,7 @@ * There's are more methods documented below. In addition, for more information on subtler topics like internationalization and validity, see the external documentation.

static fromMillis(count, opts) {
return Duration.fromObject(Object.assign({ milliseconds: count }, opts));
return Duration.fromObject({ milliseconds: count }, opts);
}
/**
* Create a Duration from a JavaScript object with keys like 'years' and 'hours.
* Create a Duration from a JavaScript object with keys like 'years' and 'hours'.
* If this object is empty then a zero milliseconds duration is returned.

@@ -238,8 +235,9 @@ * @param {Object} obj - the object to create the DateTime from

* @param {number} obj.milliseconds
* @param {string} [obj.locale='en-US'] - the locale to use
* @param {string} obj.numberingSystem - the numbering system to use
* @param {string} [obj.conversionAccuracy='casual'] - the conversion system to use
* @param {Object} [opts=[]] - options for creating this Duration
* @param {string} [opts.locale='en-US'] - the locale to use
* @param {string} opts.numberingSystem - the numbering system to use
* @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use
* @return {Duration}
*/
static fromObject(obj) {
static fromObject(obj, opts = {}) {
if (obj == null || typeof obj !== "object") {

@@ -253,10 +251,5 @@ throw new InvalidArgumentError(

return new Duration({
values: normalizeObject(obj, Duration.normalizeUnit, [
"locale",
"numberingSystem",
"conversionAccuracy",
"zone" // a bit of debt; it's super inconvenient internally not to be able to blindly pass this
]),
loc: Locale.fromObject(obj),
conversionAccuracy: obj.conversionAccuracy
values: normalizeObject(obj, Duration.normalizeUnit),
loc: Locale.fromObject(opts),
conversionAccuracy: opts.conversionAccuracy,
});

@@ -281,4 +274,3 @@ }

if (parsed) {
const obj = Object.assign(parsed, opts);
return Duration.fromObject(obj);
return Duration.fromObject(parsed, opts);
} else {

@@ -307,4 +299,3 @@ return Duration.invalid("unparsable", `the input "${text}" can't be parsed as ISO 8601`);

if (parsed) {
const obj = Object.assign(parsed, opts);
return Duration.fromObject(obj);
return Duration.fromObject(parsed, opts);
} else {

@@ -357,3 +348,3 @@ return Duration.invalid("unparsable", `the input "${text}" can't be parsed as ISO 8601`);

millisecond: "milliseconds",
milliseconds: "milliseconds"
milliseconds: "milliseconds",
}[unit ? unit.toLowerCase() : unit];

@@ -414,5 +405,6 @@

// reverse-compat since 1.2; we always round down now, never up, and we do it by default
const fmtOpts = Object.assign({}, opts, {
floor: opts.round !== false && opts.floor !== false
});
const fmtOpts = {
...opts,
floor: opts.round !== false && opts.floor !== false,
};
return this.isValid

@@ -425,18 +417,8 @@ ? Formatter.create(this.loc, fmtOpts).formatDurationFromString(this, fmt)

* Returns a JavaScript object with this Duration's values.
* @param opts - options for generating the object
* @param {boolean} [opts.includeConfig=false] - include configuration attributes in the output
* @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toObject() //=> { years: 1, days: 6, seconds: 2 }
* @return {Object}
*/
toObject(opts = {}) {
toObject() {
if (!this.isValid) return {};
const base = Object.assign({}, this.values);
if (opts.includeConfig) {
base.conversionAccuracy = this.conversionAccuracy;
base.numberingSystem = this.loc.numberingSystem;
base.locale = this.loc.locale;
}
return base;
return { ...this.values };
}

@@ -497,11 +479,9 @@

opts = Object.assign(
{
suppressMilliseconds: false,
suppressSeconds: false,
includePrefix: false,
format: "extended"
},
opts
);
opts = {
suppressMilliseconds: false,
suppressSeconds: false,
includePrefix: false,
format: "extended",
...opts,
};

@@ -630,3 +610,3 @@ const value = this.shiftTo("hours", "minutes", "seconds", "milliseconds");

const mixed = Object.assign(this.values, normalizeObject(values, Duration.normalizeUnit, []));
const mixed = { ...this.values, ...normalizeObject(values, Duration.normalizeUnit) };
return clone(this, { values: mixed });

@@ -688,3 +668,3 @@ }

units = units.map(u => Duration.normalizeUnit(u));
units = units.map((u) => Duration.normalizeUnit(u));

@@ -691,0 +671,0 @@ const built = {},

@@ -8,3 +8,3 @@ import {

weeksInWeekYear,
isInteger
isInteger,
} from "./util.js";

@@ -34,3 +34,3 @@ import Invalid from "./invalid.js";

const table = isLeapYear(year) ? leapLadder : nonLeapLadder,
month0 = table.findIndex(i => i < ordinal),
month0 = table.findIndex((i) => i < ordinal),
day = ordinal - table[month0];

@@ -62,3 +62,3 @@ return { month: month0 + 1, day };

return Object.assign({ weekYear, weekNumber, weekday }, timeObject(gregObj));
return { weekYear, weekNumber, weekday, ...timeObject(gregObj) };
}

@@ -85,18 +85,15 @@

const { month, day } = uncomputeOrdinal(year, ordinal);
return Object.assign({ year, month, day }, timeObject(weekData));
return { year, month, day, ...timeObject(weekData) };
}
export function gregorianToOrdinal(gregData) {
const { year, month, day } = gregData,
ordinal = computeOrdinal(year, month, day);
return Object.assign({ year, ordinal }, timeObject(gregData));
const { year, month, day } = gregData;
const ordinal = computeOrdinal(year, month, day);
return { year, ordinal, ...timeObject(gregData) };
}
export function ordinalToGregorian(ordinalData) {
const { year, ordinal } = ordinalData,
{ month, day } = uncomputeOrdinal(year, ordinal);
return Object.assign({ year, month, day }, timeObject(ordinalData));
const { year, ordinal } = ordinalData;
const { month, day } = uncomputeOrdinal(year, ordinal);
return { year, month, day, ...timeObject(ordinalData) };
}

@@ -103,0 +100,0 @@

import Duration from "../duration.js";
function dayDiff(earlier, later) {
const utcDayStart = dt =>
dt
.toUTC(0, { keepLocalTime: true })
.startOf("day")
.valueOf(),
const utcDayStart = (dt) => dt.toUTC(0, { keepLocalTime: true }).startOf("day").valueOf(),
ms = utcDayStart(later) - utcDayStart(earlier);

@@ -23,5 +19,5 @@ return Math.floor(Duration.fromMillis(ms).as("days"));

return (days - (days % 7)) / 7;
}
},
],
["days", dayDiff]
["days", dayDiff],
];

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

export default function(earlier, later, units, opts) {
export default function (earlier, later, units, opts) {
let [cursor, results, highWater, lowestOrder] = highOrderDiffs(earlier, later, units);

@@ -60,3 +56,3 @@

const lowerOrderUnits = units.filter(
u => ["hours", "minutes", "seconds", "milliseconds"].indexOf(u) >= 0
(u) => ["hours", "minutes", "seconds", "milliseconds"].indexOf(u) >= 0
);

@@ -74,3 +70,3 @@

const duration = Duration.fromObject(Object.assign(results, opts));
const duration = Duration.fromObject(results, opts);

@@ -77,0 +73,0 @@ if (lowerOrderUnits.length > 0) {

@@ -22,3 +22,3 @@ const numberingSystems = {

tibt: "[\u0F20-\u0F29]",
latn: "\\d"
latn: "\\d",
};

@@ -45,6 +45,5 @@

thai: [3664, 3673],
tibt: [3872, 3881]
tibt: [3872, 3881],
};
// eslint-disable-next-line
const hanidecChars = numberingSystems.hanidec.replace(/[\[|\]]/g, "").split("");

@@ -51,0 +50,0 @@

@@ -24,3 +24,3 @@ import * as Formats from "./formats.js";

"November",
"December"
"December",
];

@@ -40,3 +40,3 @@

"Nov",
"Dec"
"Dec",
];

@@ -70,3 +70,3 @@

"Saturday",
"Sunday"
"Sunday",
];

@@ -139,3 +139,3 @@

minutes: ["minute", "min."],
seconds: ["second", "sec."]
seconds: ["second", "sec."],
};

@@ -167,4 +167,4 @@

: singular
? units[unit][0]
: unit;
? units[unit][0]
: unit;
return isInPast ? `${fmtValue} ${fmtUnit} ago` : `in ${fmtValue} ${fmtUnit}`;

@@ -186,3 +186,3 @@ }

"timeZoneName",
"hour12"
"hourCycle",
]),

@@ -189,0 +189,0 @@ key = stringify(filtered),

@@ -12,3 +12,3 @@ /**

month: n,
day: n
day: n,
};

@@ -19,3 +19,3 @@

month: s,
day: n
day: n,
};

@@ -27,3 +27,3 @@

day: n,
weekday: s
weekday: s,
};

@@ -34,3 +34,3 @@

month: l,
day: n
day: n,
};

@@ -42,3 +42,3 @@

day: n,
weekday: l
weekday: l,
};

@@ -48,3 +48,3 @@

hour: n,
minute: n
minute: n,
};

@@ -55,3 +55,3 @@

minute: n,
second: n
second: n,
};

@@ -63,3 +63,3 @@

second: n,
timeZoneName: s
timeZoneName: s,
};

@@ -71,3 +71,3 @@

second: n,
timeZoneName: l
timeZoneName: l,
};

@@ -78,8 +78,5 @@

minute: n,
hour12: false
hourCycle: "h23",
};
/**
* {@link toLocaleString}; format like '09:30:23', always 24-hour.
*/
export const TIME_24_WITH_SECONDS = {

@@ -89,8 +86,5 @@ hour: n,

second: n,
hour12: false
hourCycle: "h23",
};
/**
* {@link toLocaleString}; format like '09:30:23 EDT', always 24-hour.
*/
export const TIME_24_WITH_SHORT_OFFSET = {

@@ -100,9 +94,6 @@ hour: n,

second: n,
hour12: false,
timeZoneName: s
hourCycle: "h23",
timeZoneName: s,
};
/**
* {@link toLocaleString}; format like '09:30:23 Eastern Daylight Time', always 24-hour.
*/
export const TIME_24_WITH_LONG_OFFSET = {

@@ -112,9 +103,6 @@ hour: n,

second: n,
hour12: false,
timeZoneName: l
hourCycle: "h23",
timeZoneName: l,
};
/**
* {@link toLocaleString}; format like '10/14/1983, 9:30 AM'. Only 12-hour if the locale is.
*/
export const DATETIME_SHORT = {

@@ -125,8 +113,5 @@ year: n,

hour: n,
minute: n
minute: n,
};
/**
* {@link toLocaleString}; format like '10/14/1983, 9:30:33 AM'. Only 12-hour if the locale is.
*/
export const DATETIME_SHORT_WITH_SECONDS = {

@@ -138,3 +123,3 @@ year: n,

minute: n,
second: n
second: n,
};

@@ -147,3 +132,3 @@

hour: n,
minute: n
minute: n,
};

@@ -157,3 +142,3 @@

minute: n,
second: n
second: n,
};

@@ -167,3 +152,3 @@

hour: n,
minute: n
minute: n,
};

@@ -177,3 +162,3 @@

minute: n,
timeZoneName: s
timeZoneName: s,
};

@@ -188,3 +173,3 @@

second: n,
timeZoneName: s
timeZoneName: s,
};

@@ -199,3 +184,3 @@

minute: n,
timeZoneName: l
timeZoneName: l,
};

@@ -211,3 +196,3 @@

second: n,
timeZoneName: l
timeZoneName: l,
};
import * as English from "./english.js";
import * as Formats from "./formats.js";
import { hasFormatToParts, padStart } from "./util.js";
import { padStart } from "./util.js";

@@ -37,3 +37,3 @@ function stringifyTokens(splits, tokenToString) {

FFF: Formats.DATETIME_FULL_WITH_SECONDS,
FFFF: Formats.DATETIME_HUGE_WITH_SECONDS
FFFF: Formats.DATETIME_HUGE_WITH_SECONDS,
};

@@ -98,3 +98,3 @@

}
const df = this.systemLoc.dtFormatter(dt, Object.assign({}, this.opts, opts));
const df = this.systemLoc.dtFormatter(dt, { ...this.opts, ...opts });
return df.format();

@@ -104,3 +104,3 @@ }

formatDateTime(dt, opts = {}) {
const df = this.loc.dtFormatter(dt, Object.assign({}, this.opts, opts));
const df = this.loc.dtFormatter(dt, { ...this.opts, ...opts });
return df.format();

@@ -110,3 +110,3 @@ }

formatDateTimeParts(dt, opts = {}) {
const df = this.loc.dtFormatter(dt, Object.assign({}, this.opts, opts));
const df = this.loc.dtFormatter(dt, { ...this.opts, ...opts });
return df.formatToParts();

@@ -116,3 +116,3 @@ }

resolvedOptions(dt, opts = {}) {
const df = this.loc.dtFormatter(dt, Object.assign({}, this.opts, opts));
const df = this.loc.dtFormatter(dt, { ...this.opts, ...opts });
return df.resolvedOptions();

@@ -127,3 +127,3 @@ }

const opts = Object.assign({}, this.opts);
const opts = { ...this.opts };

@@ -139,6 +139,5 @@ if (p > 0) {

const knownEnglish = this.loc.listingMode() === "en",
useDateTimeFormatter =
this.loc.outputCalendar && this.loc.outputCalendar !== "gregory" && hasFormatToParts(),
useDateTimeFormatter = this.loc.outputCalendar && this.loc.outputCalendar !== "gregory",
string = (opts, extract) => this.loc.extract(dt, opts, extract),
formatOffset = opts => {
formatOffset = (opts) => {
if (dt.isOffsetFixed && dt.offset === 0 && opts.allowZ) {

@@ -153,3 +152,3 @@ return "Z";

? English.meridiemForDateTime(dt)
: string({ hour: "numeric", hour12: true }, "dayperiod"),
: string({ hour: "numeric", hourCycle: "h12" }, "dayperiod"),
month = (length, standalone) =>

@@ -166,3 +165,3 @@ knownEnglish

),
maybeMacro = token => {
maybeMacro = (token) => {
const formatOpts = Formatter.macroTokenToFormatOpts(token);

@@ -175,5 +174,5 @@ if (formatOpts) {

},
era = length =>
era = (length) =>
knownEnglish ? English.eraForDateTime(dt, length) : string({ era: length }, "era"),
tokenToString = token => {
tokenToString = (token) => {
// Where possible: http://cldr.unicode.org/translation/date-time-1/date-time#TOC-Standalone-vs.-Format-Styles

@@ -360,3 +359,3 @@ switch (token) {

formatDurationFromString(dur, fmt) {
const tokenToField = token => {
const tokenToField = (token) => {
switch (token[0]) {

@@ -381,3 +380,3 @@ case "S":

},
tokenToString = lildur => token => {
tokenToString = (lildur) => (token) => {
const mapped = tokenToField(token);

@@ -395,5 +394,5 @@ if (mapped) {

),
collapsed = dur.shiftTo(...realTokens.map(tokenToField).filter(t => t));
collapsed = dur.shiftTo(...realTokens.map(tokenToField).filter((t) => t));
return stringifyTokens(tokens, tokenToString(collapsed));
}
}

@@ -1,6 +0,5 @@

import { hasFormatToParts, hasIntl, padStart, roundTo, hasRelative } from "./util.js";
import { padStart, roundTo, hasRelative } from "./util.js";
import * as English from "./english.js";
import Settings from "../settings.js";
import DateTime from "../datetime.js";
import Formatter from "./formatter.js";
import IANAZone from "../zones/IANAZone.js";

@@ -46,7 +45,2 @@

return sysLocaleCache;
} else if (hasIntl()) {
const computedSys = new Intl.DateTimeFormat().resolvedOptions().locale;
// node sometimes defaults to "und". Override that because that is dumb
sysLocaleCache = !computedSys || computedSys === "und" ? "en-US" : computedSys;
return sysLocaleCache;
} else {

@@ -86,19 +80,15 @@ sysLocaleCache = "en-US";

function intlConfigString(localeStr, numberingSystem, outputCalendar) {
if (hasIntl()) {
if (outputCalendar || numberingSystem) {
localeStr += "-u";
if (outputCalendar || numberingSystem) {
localeStr += "-u";
if (outputCalendar) {
localeStr += `-ca-${outputCalendar}`;
}
if (outputCalendar) {
localeStr += `-ca-${outputCalendar}`;
}
if (numberingSystem) {
localeStr += `-nu-${numberingSystem}`;
}
return localeStr;
} else {
return localeStr;
if (numberingSystem) {
localeStr += `-nu-${numberingSystem}`;
}
return localeStr;
} else {
return [];
return localeStr;
}

@@ -145,3 +135,3 @@ }

loc.locale.startsWith("en") ||
(hasIntl() && new Intl.DateTimeFormat(loc.intl).resolvedOptions().numberingSystem === "latn")
new Intl.DateTimeFormat(loc.intl).resolvedOptions().numberingSystem === "latn"
);

@@ -160,3 +150,3 @@ }

if (!forceSimple && hasIntl()) {
if (!forceSimple) {
const intlOpts = { useGrouping: false };

@@ -187,6 +177,5 @@ if (opts.padTo > 0) intlOpts.minimumIntegerDigits = opts.padTo;

this.opts = opts;
this.hasIntl = hasIntl();
let z;
if (dt.zone.universal && this.hasIntl) {
if (dt.zone.isUniversal) {
// UTC-8 or Etc/UTC-8 are not part of tzdata, only Etc/GMT+8 and the like.

@@ -219,3 +208,3 @@ // That is why fixed-offset TZ is set to that unless it is:

}
} else if (dt.zone.type === "local") {
} else if (dt.zone.type === "system") {
this.dt = dt;

@@ -227,41 +216,19 @@ } else {

if (this.hasIntl) {
const intlOpts = Object.assign({}, this.opts);
if (z) {
intlOpts.timeZone = z;
}
this.dtf = getCachedDTF(intl, intlOpts);
const intlOpts = { ...this.opts };
if (z) {
intlOpts.timeZone = z;
}
this.dtf = getCachedDTF(intl, intlOpts);
}
format() {
if (this.hasIntl) {
return this.dtf.format(this.dt.toJSDate());
} else {
const tokenFormat = English.formatString(this.opts),
loc = Locale.create("en-US");
return Formatter.create(loc).formatDateTimeFromString(this.dt, tokenFormat);
}
return this.dtf.format(this.dt.toJSDate());
}
formatToParts() {
if (this.hasIntl && hasFormatToParts()) {
return this.dtf.formatToParts(this.dt.toJSDate());
} else {
// This is kind of a cop out. We actually could do this for English. However, we couldn't do it for intl strings
// and IMO it's too weird to have an uncanny valley like that
return [];
}
return this.dtf.formatToParts(this.dt.toJSDate());
}
resolvedOptions() {
if (this.hasIntl) {
return this.dtf.resolvedOptions();
} else {
return {
locale: "en-US",
numberingSystem: "latn",
outputCalendar: "gregory"
};
}
return this.dtf.resolvedOptions();
}

@@ -275,3 +242,3 @@ }

constructor(intl, isEnglish, opts) {
this.opts = Object.assign({ style: "long" }, opts);
this.opts = { style: "long", ...opts };
if (!isEnglish && hasRelative()) {

@@ -354,16 +321,7 @@ this.rtf = getCachedRTF(intl, opts);

listingMode(defaultOK = true) {
const intl = hasIntl(),
hasFTP = intl && hasFormatToParts(),
isActuallyEn = this.isEnglish(),
hasNoWeirdness =
(this.numberingSystem === null || this.numberingSystem === "latn") &&
(this.outputCalendar === null || this.outputCalendar === "gregory");
if (!hasFTP && !(isActuallyEn && hasNoWeirdness) && !defaultOK) {
return "error";
} else if (!hasFTP || (isActuallyEn && hasNoWeirdness)) {
return "en";
} else {
return "intl";
}
const isActuallyEn = this.isEnglish();
const hasNoWeirdness =
(this.numberingSystem === null || this.numberingSystem === "latn") &&
(this.outputCalendar === null || this.outputCalendar === "gregory");
return isActuallyEn && hasNoWeirdness ? "en" : "intl";
}

@@ -385,7 +343,7 @@

redefaultToEN(alts = {}) {
return this.clone(Object.assign({}, alts, { defaultToEN: true }));
return this.clone({ ...alts, defaultToEN: true });
}
redefaultToSystem(alts = {}) {
return this.clone(Object.assign({}, alts, { defaultToEN: false }));
return this.clone({ ...alts, defaultToEN: false });
}

@@ -398,3 +356,3 @@

if (!this.monthsCache[formatStr][length]) {
this.monthsCache[formatStr][length] = mapMonths(dt => this.extract(dt, intl, "month"));
this.monthsCache[formatStr][length] = mapMonths((dt) => this.extract(dt, intl, "month"));
}

@@ -412,3 +370,3 @@ return this.monthsCache[formatStr][length];

if (!this.weekdaysCache[formatStr][length]) {
this.weekdaysCache[formatStr][length] = mapWeekdays(dt =>
this.weekdaysCache[formatStr][length] = mapWeekdays((dt) =>
this.extract(dt, intl, "weekday")

@@ -431,5 +389,5 @@ );

if (!this.meridiemCache) {
const intl = { hour: "numeric", hour12: true };
const intl = { hour: "numeric", hourCycle: "h12" };
this.meridiemCache = [DateTime.utc(2016, 11, 13, 9), DateTime.utc(2016, 11, 13, 19)].map(
dt => this.extract(dt, intl, "dayperiod")
(dt) => this.extract(dt, intl, "dayperiod")
);

@@ -450,3 +408,3 @@ }

if (!this.eraCache[length]) {
this.eraCache[length] = [DateTime.utc(-40, 1, 1), DateTime.utc(2017, 1, 1)].map(dt =>
this.eraCache[length] = [DateTime.utc(-40, 1, 1), DateTime.utc(2017, 1, 1)].map((dt) =>
this.extract(dt, intl, "era")

@@ -463,3 +421,3 @@ );

results = df.formatToParts(),
matching = results.find(m => m.type.toLowerCase() === field);
matching = results.find((m) => m.type.toLowerCase() === field);
return matching ? matching.value : null;

@@ -486,3 +444,3 @@ }

this.locale.toLowerCase() === "en-us" ||
(hasIntl() && new Intl.DateTimeFormat(this.intl).resolvedOptions().locale.startsWith("en-us"))
new Intl.DateTimeFormat(this.intl).resolvedOptions().locale.startsWith("en-us")
);

@@ -489,0 +447,0 @@ }

@@ -7,3 +7,3 @@ import {

ianaRegex,
isUndefined
isUndefined,
} from "./util.js";

@@ -30,3 +30,3 @@ import * as English from "./english.js";

function combineExtractors(...extractors) {
return m =>
return (m) =>
extractors

@@ -36,3 +36,3 @@ .reduce(

const [val, zone, next] = ex(m, cursor);
return [Object.assign(mergedVals, val), mergedZone || zone, next];
return [{ ...mergedVals, ...val }, mergedZone || zone, next];
},

@@ -95,3 +95,3 @@ [{}, null, 1]

month: int(match, cursor + 1, 1),
day: int(match, cursor + 2, 1)
day: int(match, cursor + 2, 1),
};

@@ -107,3 +107,3 @@

seconds: int(match, cursor + 2, 0),
milliseconds: parseMillis(match[cursor + 3])
milliseconds: parseMillis(match[cursor + 3]),
};

@@ -132,16 +132,8 @@

const isoDuration = /^-?P(?:(?:(-?\d{1,9})Y)?(?:(-?\d{1,9})M)?(?:(-?\d{1,9})W)?(?:(-?\d{1,9})D)?(?:T(?:(-?\d{1,9})H)?(?:(-?\d{1,9})M)?(?:(-?\d{1,20})(?:[.,](-?\d{1,9}))?S)?)?)$/;
const isoDuration =
/^-?P(?:(?:(-?\d{1,9})Y)?(?:(-?\d{1,9})M)?(?:(-?\d{1,9})W)?(?:(-?\d{1,9})D)?(?:T(?:(-?\d{1,9})H)?(?:(-?\d{1,9})M)?(?:(-?\d{1,20})(?:[.,](-?\d{1,9}))?S)?)?)$/;
function extractISODuration(match) {
const [
s,
yearStr,
monthStr,
weekStr,
dayStr,
hourStr,
minuteStr,
secondStr,
millisecondsStr
] = match;
const [s, yearStr, monthStr, weekStr, dayStr, hourStr, minuteStr, secondStr, millisecondsStr] =
match;

@@ -163,4 +155,4 @@ const hasNegativePrefix = s[0] === "-";

seconds: maybeNegate(parseInteger(secondStr), secondStr === "-0"),
milliseconds: maybeNegate(parseMillis(millisecondsStr), negativeSeconds)
}
milliseconds: maybeNegate(parseMillis(millisecondsStr), negativeSeconds),
},
];

@@ -181,3 +173,3 @@ }

PDT: -7 * 60,
PST: -8 * 60
PST: -8 * 60,
};

@@ -191,3 +183,3 @@

hour: parseInteger(hourStr),
minute: parseInteger(minuteStr)
minute: parseInteger(minuteStr),
};

@@ -207,3 +199,4 @@

// RFC 2822/5322
const rfc2822 = /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|(?:([+-]\d\d)(\d\d)))$/;
const rfc2822 =
/^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|(?:([+-]\d\d)(\d\d)))$/;

@@ -223,3 +216,3 @@ function extractRFC2822(match) {

offHourStr,
offMinuteStr
offMinuteStr,
] = match,

@@ -250,5 +243,8 @@ result = fromStrings(weekdayStr, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr);

const rfc1123 = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d\d) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d\d):(\d\d):(\d\d) GMT$/,
rfc850 = /^(Monday|Tuesday|Wedsday|Thursday|Friday|Saturday|Sunday), (\d\d)-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d\d) (\d\d):(\d\d):(\d\d) GMT$/,
ascii = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( \d|\d\d) (\d\d):(\d\d):(\d\d) (\d{4})$/;
const rfc1123 =
/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d\d) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d\d):(\d\d):(\d\d) GMT$/,
rfc850 =
/^(Monday|Tuesday|Wedsday|Thursday|Friday|Saturday|Sunday), (\d\d)-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d\d) (\d\d):(\d\d):(\d\d) GMT$/,
ascii =
/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( \d|\d\d) (\d\d):(\d\d):(\d\d) (\d{4})$/;

@@ -282,3 +278,7 @@ function extractRFC1123Or850(match) {

);
const extractISOOrdinalDataAndTime = combineExtractors(extractISOOrdinalData, extractISOTime);
const extractISOOrdinalDateAndTime = combineExtractors(
extractISOOrdinalData,
extractISOTime,
extractISOOffset
);
const extractISOTimeAndOffset = combineExtractors(extractISOTime, extractISOOffset);

@@ -295,3 +295,3 @@

[isoWeekWithTimeExtensionRegex, extractISOWeekTimeAndOffset],
[isoOrdinalWithTimeExtensionRegex, extractISOOrdinalDataAndTime],
[isoOrdinalWithTimeExtensionRegex, extractISOOrdinalDateAndTime],
[isoTimeCombinedRegex, extractISOTimeAndOffset]

@@ -298,0 +298,0 @@ );

@@ -11,3 +11,3 @@ import { parseMillis, isUndefined, untruncateYear, signedOffset, hasOwnProperty } from "./util.js";

function intUnit(regex, post = i => i) {
function intUnit(regex, post = (i) => i) {
return { regex, deser: ([s]) => post(parseDigits(s)) };

@@ -40,3 +40,3 @@ }

deser: ([s]) =>
strings.findIndex(i => stripInsensitivities(s) === stripInsensitivities(i)) + startIndex
strings.findIndex((i) => stripInsensitivities(s) === stripInsensitivities(i)) + startIndex,
};

@@ -55,3 +55,2 @@ }

function escapeToken(value) {
// eslint-disable-next-line no-useless-escape
return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");

@@ -72,4 +71,4 @@ }

fourToSix = digitRegex(loc, "{4,6}"),
literal = t => ({ regex: RegExp(escapeToken(t.val)), deser: ([s]) => s, literal: true }),
unitate = t => {
literal = (t) => ({ regex: RegExp(escapeToken(t.val)), deser: ([s]) => s, literal: true }),
unitate = (t) => {
if (token.literal) {

@@ -190,3 +189,3 @@ return literal(t);

const unit = unitate(token) || {
invalidReason: MISSING_FTP
invalidReason: MISSING_FTP,
};

@@ -202,3 +201,3 @@

"2-digit": "yy",
numeric: "yyyyy"
numeric: "yyyyy",
},

@@ -209,11 +208,11 @@ month: {

short: "MMM",
long: "MMMM"
long: "MMMM",
},
day: {
numeric: "d",
"2-digit": "dd"
"2-digit": "dd",
},
weekday: {
short: "EEE",
long: "EEEE"
long: "EEEE",
},

@@ -224,12 +223,12 @@ dayperiod: "a",

numeric: "h",
"2-digit": "hh"
"2-digit": "hh",
},
minute: {
numeric: "m",
"2-digit": "mm"
"2-digit": "mm",
},
second: {
numeric: "s",
"2-digit": "ss"
}
"2-digit": "ss",
},
};

@@ -243,3 +242,3 @@

literal: true,
val: value
val: value,
};

@@ -258,3 +257,3 @@ }

literal: false,
val
val,
};

@@ -267,3 +266,3 @@ }

function buildRegex(units) {
const re = units.map(u => u.regex).reduce((f, r) => `${f}(${r.source})`, "");
const re = units.map((u) => u.regex).reduce((f, r) => `${f}(${r.source})`, "");
return [`^${re}$`, units];

@@ -295,3 +294,3 @@ }

function dateTimeFromMatches(matches) {
const toField = token => {
const toField = (token) => {
switch (token) {

@@ -395,3 +394,3 @@ case "S":

const tokens = parts.map(p => tokenForPart(p, locale, formatOpts));
const tokens = parts.map((p) => tokenForPart(p, locale, formatOpts));

@@ -406,3 +405,3 @@ if (tokens.includes(undefined)) {

function expandMacroTokens(tokens, locale) {
return Array.prototype.concat(...tokens.map(t => maybeExpandMacroToken(t, locale)));
return Array.prototype.concat(...tokens.map((t) => maybeExpandMacroToken(t, locale)));
}

@@ -416,4 +415,4 @@

const tokens = expandMacroTokens(Formatter.parseFormat(format), locale),
units = tokens.map(t => unitForToken(t, locale)),
disqualifyingUnit = units.find(t => t.invalidReason);
units = tokens.map((t) => unitForToken(t, locale)),
disqualifyingUnit = units.find((t) => t.invalidReason);

@@ -420,0 +419,0 @@ if (disqualifyingUnit) {

@@ -37,14 +37,2 @@ /*

export function hasIntl() {
try {
return typeof Intl !== "undefined" && Intl.DateTimeFormat;
} catch (e) {
return false;
}
}
export function hasFormatToParts() {
return !isUndefined(Intl.DateTimeFormat.prototype.formatToParts);
}
export function hasRelative() {

@@ -204,3 +192,3 @@ try {

intlOpts = {
hour12: false,
hourCycle: "h23",
year: "numeric",

@@ -210,3 +198,3 @@ month: "2-digit",

hour: "2-digit",
minute: "2-digit"
minute: "2-digit",
};

@@ -218,20 +206,8 @@

const modified = Object.assign({ timeZoneName: offsetFormat }, intlOpts),
intl = hasIntl();
const modified = { timeZoneName: offsetFormat, ...intlOpts };
if (intl && hasFormatToParts()) {
const parsed = new Intl.DateTimeFormat(locale, modified)
.formatToParts(date)
.find(m => m.type.toLowerCase() === "timezonename");
return parsed ? parsed.value : null;
} else if (intl) {
// this probably doesn't work for all locales
const without = new Intl.DateTimeFormat(locale, intlOpts).format(date),
included = new Intl.DateTimeFormat(locale, modified).format(date),
diffed = included.substring(without.length),
trimmed = diffed.replace(/^[, \u200e]+/, "");
return trimmed;
} else {
return null;
}
const parsed = new Intl.DateTimeFormat(locale, modified)
.formatToParts(date)
.find((m) => m.type.toLowerCase() === "timezonename");
return parsed ? parsed.value : null;
}

@@ -262,7 +238,6 @@

export function normalizeObject(obj, normalizer, nonUnitKeys) {
export function normalizeObject(obj, normalizer) {
const normalized = {};
for (const u in obj) {
if (hasOwnProperty(obj, u)) {
if (nonUnitKeys.indexOf(u) >= 0) continue;
const v = obj[u];

@@ -269,0 +244,0 @@ if (v === undefined || v === null) continue;

@@ -20,3 +20,3 @@ /**

const lowered = input.toLowerCase();
if (lowered === "local") return defaultZone;
if (lowered === "local" || lowered === "system") return defaultZone;
else if (lowered === "utc" || lowered === "gmt") return FixedOffsetZone.utcInstance;

@@ -23,0 +23,0 @@ else if ((offset = IANAZone.parseGMTOffset(input)) != null) {

@@ -7,3 +7,3 @@ import DateTime from "./datetime.js";

import { hasFormatToParts, hasIntl, hasRelative } from "./impl/util.js";
import { hasRelative } from "./impl/util.js";

@@ -20,7 +20,5 @@ /**

static hasDST(zone = Settings.defaultZone) {
const proto = DateTime.now()
.setZone(zone)
.set({ month: 12 });
const proto = DateTime.now().setZone(zone).set({ month: 12 });
return !zone.universal && proto.offset !== proto.set({ month: 6 }).offset;
return !zone.isUniversal && proto.offset !== proto.set({ month: 6 }).offset;
}

@@ -70,3 +68,3 @@

* @example Info.months('long', { outputCalendar: 'islamic' })[0] //=> 'Rabiʻ I'
* @return {[string]}
* @return {Array}
*/

@@ -84,3 +82,3 @@ static months(

* changes the string.
* See {@link months}
* See {@link Info#months}
* @param {string} [length='long'] - the length of the month representation, such as "numeric", "2-digit", "narrow", "short", "long"

@@ -92,3 +90,3 @@ * @param {Object} opts - options

* @param {string} [opts.outputCalendar='gregory'] - the calendar
* @return {[string]}
* @return {Array}
*/

@@ -114,3 +112,3 @@ static monthsFormat(

* @example Info.weekdays('short', { locale: 'ar' })[0] //=> 'الاثنين'
* @return {[string]}
* @return {Array}
*/

@@ -125,4 +123,4 @@ static weekdays(length = "long", { locale = null, numberingSystem = null, locObj = null } = {}) {

* changes the string.
* See {@link weekdays}
* @param {string} [length='long'] - the length of the weekday representation, such as "narrow", "short", "long".
* See {@link Info#weekdays}
* @param {string} [length='long'] - the length of the month representation, such as "narrow", "short", "long".
* @param {Object} opts - options

@@ -132,3 +130,3 @@ * @param {string} [opts.locale=null] - the locale code

* @param {string} [opts.locObj=null] - an existing locale object to use
* @return {[string]}
* @return {Array}
*/

@@ -148,3 +146,3 @@ static weekdaysFormat(

* @example Info.meridiems({ locale: 'my' }) //=> [ 'နံနက်', 'ညနေ' ]
* @return {[string]}
* @return {Array}
*/

@@ -163,3 +161,3 @@ static meridiems({ locale = null } = {}) {

* @example Info.eras('long', { locale: 'fr' }) //=> [ 'avant Jésus-Christ', 'après Jésus-Christ' ]
* @return {[string]}
* @return {Array}
*/

@@ -182,23 +180,4 @@ static eras(length = "short", { locale = null } = {}) {

static features() {
let intl = false,
intlTokens = false,
zones = false,
relative = false;
if (hasIntl()) {
intl = true;
intlTokens = hasFormatToParts();
relative = hasRelative();
try {
zones =
new Intl.DateTimeFormat("en", { timeZone: "America/New_York" }).resolvedOptions()
.timeZone === "America/New_York";
} catch (e) {
zones = false;
}
}
return { intl, intlTokens, zones, relative };
return { relative: hasRelative() };
}
}

@@ -30,8 +30,8 @@ import DateTime, { friendlyDateTime } from "./datetime.js";

*
* * **Creation** To create an Interval, use {@link fromDateTimes}, {@link after}, {@link before}, or {@link fromISO}.
* * **Accessors** Use {@link start} and {@link end} to get the start and end.
* * **Interrogation** To analyze the Interval, use {@link count}, {@link length}, {@link hasSame}, {@link contains}, {@link isAfter}, or {@link isBefore}.
* * **Transformation** To create other Intervals out of this one, use {@link set}, {@link splitAt}, {@link splitBy}, {@link divideEqually}, {@link merge}, {@link xor}, {@link union}, {@link intersection}, or {@link difference}.
* * **Comparison** To compare this Interval to another one, use {@link equals}, {@link overlaps}, {@link abutsStart}, {@link abutsEnd}, {@link engulfs}.
* * **Output** To convert the Interval into other representations, see {@link toString}, {@link toISO}, {@link toISODate}, {@link toISOTime}, {@link toFormat}, and {@link toDuration}.
* * **Creation** To create an Interval, use {@link Interval.fromDateTimes}, {@link Interval.after}, {@link Interval.before}, or {@link Interval.fromISO}.
* * **Accessors** Use {@link Interval#start} and {@link Interval#end} to get the start and end.
* * **Interrogation** To analyze the Interval, use {@link Interval#count}, {@link Interval#length}, {@link Interval#hasSame}, {@link Interval#contains}, {@link Interval#isAfter}, or {@link Interval#isBefore}.
* * **Transformation** To create other Intervals out of this one, use {@link Interval#set}, {@link Interval#splitAt}, {@link Interval#splitBy}, {@link Interval#divideEqually}, {@link Interval#merge}, {@link Interval#xor}, {@link Interval#union}, {@link Interval#intersection}, or {@link Interval#difference}.
* * **Comparison** To compare this Interval to another one, use {@link Interval#equals}, {@link Interval#overlaps}, {@link Interval#abutsStart}, {@link Interval#abutsEnd}, {@link Interval#engulfs}
* * **Output** To convert the Interval into other representations, see {@link Interval#toString}, {@link Interval#toISO}, {@link Interval#toISODate}, {@link Interval#toISOTime}, {@link Interval#toFormat}, and {@link Interval#toDuration}.
*/

@@ -96,3 +96,3 @@ export default class Interval {

start: builtStart,
end: builtEnd
end: builtEnd,
});

@@ -234,3 +234,3 @@ } else {

* Returns the count of minutes, hours, days, months, or years included in the Interval, even in part.
* Unlike {@link length} this counts sections of the calendar, not periods of time, e.g. specifying 'day'
* Unlike {@link Interval#length} this counts sections of the calendar, not periods of time, e.g. specifying 'day'
* asks 'what dates are included in this interval?', not 'how many days long is this interval?'

@@ -308,4 +308,4 @@ * @param {string} [unit='milliseconds'] - the unit of time to count.

* Split this Interval at each of the specified DateTimes
* @param {...[DateTime]} dateTimes - the unit of time to count.
* @return {[Interval]}
* @param {...DateTime} dateTimes - the unit of time to count.
* @return {Array}
*/

@@ -316,3 +316,3 @@ splitAt(...dateTimes) {

.map(friendlyDateTime)
.filter(d => this.contains(d))
.filter((d) => this.contains(d))
.sort(),

@@ -338,3 +338,3 @@ results = [];

* @param {Duration|Object|number} duration - The length of each resulting interval.
* @return {[Interval]}
* @return {Array}
*/

@@ -354,3 +354,3 @@ splitBy(duration) {

while (s < this.e) {
const added = this.start.plus(dur.mapUnits(x => x * idx));
const added = this.start.plus(dur.mapUnits((x) => x * idx));
next = +added > +this.e ? this.e : added;

@@ -368,3 +368,3 @@ results.push(Interval.fromDateTimes(s, next));

* @param {number} numberOfParts - The number of Intervals to divide the Interval into.
* @return {[Interval]}
* @return {Array}
*/

@@ -463,18 +463,20 @@ divideEqually(numberOfParts) {

* Combines overlapping and adjacent Intervals.
* @param {[Interval]} intervals
* @return {[Interval]}
* @param {Array} intervals
* @return {Array}
*/
static merge(intervals) {
const [found, final] = intervals.sort((a, b) => a.s - b.s).reduce(
([sofar, current], item) => {
if (!current) {
return [sofar, item];
} else if (current.overlaps(item) || current.abutsStart(item)) {
return [sofar, current.union(item)];
} else {
return [sofar.concat([current]), item];
}
},
[[], null]
);
const [found, final] = intervals
.sort((a, b) => a.s - b.s)
.reduce(
([sofar, current], item) => {
if (!current) {
return [sofar, item];
} else if (current.overlaps(item) || current.abutsStart(item)) {
return [sofar, current.union(item)];
} else {
return [sofar.concat([current]), item];
}
},
[[], null]
);
if (final) {

@@ -488,4 +490,4 @@ found.push(final);

* Return an array of Intervals representing the spans of time that only appear in one of the specified Intervals.
* @param {[Interval]} intervals
* @return {[Interval]}
* @param {Array} intervals
* @return {Array}
*/

@@ -496,3 +498,6 @@ static xor(intervals) {

const results = [],
ends = intervals.map(i => [{ time: i.s, type: "s" }, { time: i.e, type: "e" }]),
ends = intervals.map((i) => [
{ time: i.s, type: "s" },
{ time: i.e, type: "e" },
]),
flattened = Array.prototype.concat(...ends),

@@ -521,8 +526,8 @@ arr = flattened.sort((a, b) => a.time - b.time);

* @param {...Interval} intervals
* @return {[Interval]}
* @return {Array}
*/
difference(...intervals) {
return Interval.xor([this].concat(intervals))
.map(i => this.intersection(i))
.filter(i => i && !i.isEmpty());
.map((i) => this.intersection(i))
.filter((i) => i && !i.isEmpty());
}

@@ -542,3 +547,3 @@

* @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals
* @param {Object} opts - The same options as {@link DateTime.toISO}
* @param {Object} opts - The same options as {@link DateTime#toISO}
* @return {string}

@@ -545,0 +550,0 @@ */

@@ -9,6 +9,6 @@ import DateTime from "./datetime.js";

import InvalidZone from "./zones/invalidZone.js";
import LocalZone from "./zones/localZone.js";
import SystemZone from "./zones/systemZone.js";
import Settings from "./settings.js";
const VERSION = "1.27.0";
const VERSION = "2.0.0";

@@ -25,4 +25,4 @@ export {

InvalidZone,
LocalZone,
Settings
SystemZone,
Settings,
};

@@ -1,2 +0,2 @@

import LocalZone from "./zones/localZone.js";
import SystemZone from "./zones/systemZone.js";
import IANAZone from "./zones/IANAZone.js";

@@ -8,7 +8,7 @@ import Locale from "./impl/locale.js";

let now = () => Date.now(),
defaultZone = null, // not setting this directly to LocalZone.instance bc loading order issues
defaultZone = "system",
defaultLocale = null,
defaultNumberingSystem = null,
defaultOutputCalendar = null,
throwOnInvalid = false;
throwOnInvalid;

@@ -39,27 +39,17 @@ /**

/**
* Get the default time zone to create DateTimes in.
* @type {string}
*/
static get defaultZoneName() {
return Settings.defaultZone.name;
}
/**
* Set the default time zone to create DateTimes in. Does not affect existing instances.
* Use the value "system" to reset this value to the system's time zone.
* @type {string}
*/
static set defaultZoneName(z) {
if (!z) {
defaultZone = null;
} else {
defaultZone = normalizeZone(z);
}
static set defaultZone(zone) {
defaultZone = zone;
}
/**
* Get the default time zone object to create DateTimes in. Does not affect existing instances.
* Get the default time zone object currently used to create DateTimes. Does not affect existing instances.
* The default value is the system's time zone (the one set on the machine that runs this code).
* @type {Zone}
*/
static get defaultZone() {
return defaultZone || LocalZone.instance;
return normalizeZone(defaultZone, SystemZone.instance);
}

@@ -66,0 +56,0 @@

@@ -1,2 +0,1 @@

/* eslint no-unused-vars: "off" */
import { ZoneIsAbstractError } from "./errors.js";

@@ -31,3 +30,3 @@

*/
get universal() {
get isUniversal() {
throw new ZoneIsAbstractError();

@@ -34,0 +33,0 @@ }

@@ -76,3 +76,3 @@ import { formatOffset, signedOffset } from "../impl/util.js";

/** @override **/
get universal() {
get isUniversal() {
return true;

@@ -79,0 +79,0 @@ }

@@ -10,3 +10,3 @@ import { formatOffset, parseZoneInfo, isUndefined, ianaRegex, objToLocalTS } from "../impl/util.js";

dtfCache[zone] = new Intl.DateTimeFormat("en-US", {
hour12: false,
hourCycle: "h23",
timeZone: zone,

@@ -18,3 +18,3 @@ year: "numeric",

minute: "2-digit",
second: "2-digit"
second: "2-digit",
});

@@ -31,3 +31,3 @@ }

minute: 4,
second: 5
second: 5,
};

@@ -142,3 +142,3 @@

/** @override **/
get universal() {
get isUniversal() {
return false;

@@ -166,5 +166,3 @@ }

? partsOffset(dtf, date)
: hackyOffset(dtf, date),
// work around https://bugs.chromium.org/p/chromium/issues/detail?id=1025564&can=2&q=%2224%3A00%22%20datetimeformat
adjustedHour = hour === 24 ? 0 : hour;
: hackyOffset(dtf, date);

@@ -175,6 +173,6 @@ const asUTC = objToLocalTS({

day,
hour: adjustedHour,
hour,
minute,
second,
millisecond: 0
millisecond: 0,
});

@@ -181,0 +179,0 @@

@@ -25,3 +25,3 @@ import Zone from "../zone.js";

/** @override **/
get universal() {
get isUniversal() {
return false;

@@ -28,0 +28,0 @@ }

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 not supported yet

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 not supported yet

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc