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

luxon

Package Overview
Dependencies
Maintainers
0
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 3.4.4 to 3.5.0

4

package.json
{
"name": "luxon",
"version": "3.4.4",
"version": "3.5.0",
"description": "Immutable date wrapper",

@@ -29,3 +29,3 @@ "author": "Isaac Cambron",

"format-check": "prettier --check 'src/**/*.js' 'test/**/*.js' 'benchmarks/*.js'",
"benchmark": "babel-node benchmarks/index.js",
"benchmark": "node benchmarks/index.js",
"codecov": "codecov",

@@ -32,0 +32,0 @@ "prepack": "babel-node tasks/buildAll.js",

@@ -73,4 +73,19 @@ const numberingSystems = {

// cache of {numberingSystem: {append: regex}}
let digitRegexCache = {};
export function resetDigitRegexCache() {
digitRegexCache = {};
}
export function digitRegex({ numberingSystem }, append = "") {
return new RegExp(`${numberingSystems[numberingSystem || "latn"]}${append}`);
const ns = numberingSystem || "latn";
if (!digitRegexCache[ns]) {
digitRegexCache[ns] = {};
}
if (!digitRegexCache[ns][append]) {
digitRegexCache[ns][append] = new RegExp(`${numberingSystems[ns]}${append}`);
}
return digitRegexCache[ns][append];
}

@@ -343,3 +343,3 @@ import { hasLocaleWeekInfo, hasRelative, padStart, roundTo, validateWeekSettings } from "./util.js";

const specifiedLocale = locale || Settings.defaultLocale;
// the system locale is useful for human readable strings but annoying for parsing/formatting known formats
// the system locale is useful for human-readable strings but annoying for parsing/formatting known formats
const localeR = specifiedLocale || (defaultToEN ? "en-US" : systemLocale());

@@ -543,2 +543,6 @@ const numberingSystemR = numberingSystem || Settings.defaultNumberingSystem;

}
toString() {
return `Locale(${this.locale}, ${this.numberingSystem}, ${this.outputCalendar})`;
}
}

@@ -435,25 +435,57 @@ import { parseMillis, isUndefined, untruncateYear, signedOffset, hasOwnProperty } from "./util.js";

export function explainFromTokens(locale, input, format) {
const tokens = expandMacroTokens(Formatter.parseFormat(format), locale),
units = tokens.map((t) => unitForToken(t, locale)),
disqualifyingUnit = units.find((t) => t.invalidReason);
export class TokenParser {
constructor(locale, format) {
this.locale = locale;
this.format = format;
this.tokens = expandMacroTokens(Formatter.parseFormat(format), locale);
this.units = this.tokens.map((t) => unitForToken(t, locale));
this.disqualifyingUnit = this.units.find((t) => t.invalidReason);
if (disqualifyingUnit) {
return { input, tokens, invalidReason: disqualifyingUnit.invalidReason };
} else {
const [regexString, handlers] = buildRegex(units),
regex = RegExp(regexString, "i"),
[rawMatches, matches] = match(input, regex, handlers),
[result, zone, specificOffset] = matches
? dateTimeFromMatches(matches)
: [null, null, undefined];
if (hasOwnProperty(matches, "a") && hasOwnProperty(matches, "H")) {
throw new ConflictingSpecificationError(
"Can't include meridiem when specifying 24-hour format"
);
if (!this.disqualifyingUnit) {
const [regexString, handlers] = buildRegex(this.units);
this.regex = RegExp(regexString, "i");
this.handlers = handlers;
}
return { input, tokens, regex, rawMatches, matches, result, zone, specificOffset };
}
explainFromTokens(input) {
if (!this.isValid) {
return { input, tokens: this.tokens, invalidReason: this.invalidReason };
} else {
const [rawMatches, matches] = match(input, this.regex, this.handlers),
[result, zone, specificOffset] = matches
? dateTimeFromMatches(matches)
: [null, null, undefined];
if (hasOwnProperty(matches, "a") && hasOwnProperty(matches, "H")) {
throw new ConflictingSpecificationError(
"Can't include meridiem when specifying 24-hour format"
);
}
return {
input,
tokens: this.tokens,
regex: this.regex,
rawMatches,
matches,
result,
zone,
specificOffset,
};
}
}
get isValid() {
return !this.disqualifyingUnit;
}
get invalidReason() {
return this.disqualifyingUnit ? this.disqualifyingUnit.invalidReason : null;
}
}
export function explainFromTokens(locale, input, format) {
const parser = new TokenParser(locale, format);
return parser.explainFromTokens(input);
}
export function parseFromTokens(locale, input, format) {

@@ -460,0 +492,0 @@ const { result, zone, specificOffset, invalidReason } = explainFromTokens(locale, input, format);

@@ -290,2 +290,9 @@ /*

/**
* Returns the offset's value as a string
* @param {number} ts - Epoch milliseconds for which to get the offset
* @param {string} format - What style of offset to return.
* Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively
* @return {string}
*/
export function formatOffset(offset, format) {

@@ -292,0 +299,0 @@ const hours = Math.trunc(Math.abs(offset / 60)),

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

/**
* Return whether this Interval engulfs the start and end of the specified Interval.
* Returns true if this Interval fully contains the specified Interval, specifically if the intersect (of this Interval and the other Interval) is equal to the other Interval; false otherwise.
* @param {Interval} other

@@ -411,0 +411,0 @@ * @return {boolean}

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

const VERSION = "3.4.4";
const VERSION = "3.5.0";

@@ -15,0 +15,0 @@ export {

{
"type": "module",
"version": "3.4.4"
"version": "3.5.0"
}
import SystemZone from "./zones/systemZone.js";
import IANAZone from "./zones/IANAZone.js";
import Locale from "./impl/locale.js";
import DateTime from "./datetime.js";
import { normalizeZone } from "./impl/zoneUtil.js";
import { validateWeekSettings } from "./impl/util.js";
import { resetDigitRegexCache } from "./impl/digits.js";

@@ -132,3 +134,3 @@ let now = () => Date.now(),

/**
* Get the cutoff year after which a string encoding a year as two digits is interpreted to occur in the current century.
* Get the cutoff year for whether a 2-digit year string is interpreted in the current or previous century. Numbers higher than the cutoff will be considered to mean 19xx and numbers lower or equal to the cutoff will be considered 20xx.
* @type {number}

@@ -141,6 +143,7 @@ */

/**
* Set the cutoff year after which a string encoding a year as two digits is interpreted to occur in the current century.
* Set the cutoff year for whether a 2-digit year string is interpreted in the current or previous century. Numbers higher than the cutoff will be considered to mean 19xx and numbers lower or equal to the cutoff will be considered 20xx.
* @type {number}
* @example Settings.twoDigitCutoffYear = 0 // cut-off year is 0, so all 'yy' are interpreted as current century
* @example Settings.twoDigitCutoffYear = 50 // '49' -> 1949; '50' -> 2050
* @example Settings.twoDigitCutoffYear = 0 // all 'yy' are interpreted as 20th century
* @example Settings.twoDigitCutoffYear = 99 // all 'yy' are interpreted as 21st century
* @example Settings.twoDigitCutoffYear = 50 // '49' -> 2049; '50' -> 1950
* @example Settings.twoDigitCutoffYear = 1950 // interpreted as 50

@@ -176,3 +179,5 @@ * @example Settings.twoDigitCutoffYear = 2050 // ALSO interpreted as 50

IANAZone.resetCache();
DateTime.resetCache();
resetDigitRegexCache();
}
}

@@ -25,2 +25,8 @@ import { ZoneIsAbstractError } from "./errors.js";

/**
* The IANA name of this zone.
* Defaults to `name` if not overwritten by a subclass.
* @abstract
* @type {string}
*/
get ianaName() {

@@ -27,0 +33,0 @@ return this.name;

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

/** @override **/
/**
* The type of zone. `fixed` for all instances of `FixedOffsetZone`.
* @override
* @type {string}
*/
get type() {

@@ -61,3 +65,8 @@ return "fixed";

/** @override **/
/**
* The name of this zone.
* All fixed zones' names always start with "UTC" (plus optional offset)
* @override
* @type {string}
*/
get name() {

@@ -67,2 +76,8 @@ return this.fixed === 0 ? "UTC" : `UTC${formatOffset(this.fixed, "narrow")}`;

/**
* The IANA name of this zone, i.e. `Etc/UTC` or `Etc/GMT+/-nn`
*
* @override
* @type {string}
*/
get ianaName() {

@@ -76,3 +91,8 @@ if (this.fixed === 0) {

/** @override **/
/**
* Returns the offset's common name at the specified timestamp.
*
* For fixed offset zones this equals to the zone name.
* @override
*/
offsetName() {

@@ -82,3 +102,10 @@ return this.name;

/** @override **/
/**
* Returns the offset's value as a string
* @override
* @param {number} ts - Epoch milliseconds for which to get the offset
* @param {string} format - What style of offset to return.
* Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively
* @return {string}
*/
formatOffset(ts, format) {

@@ -88,3 +115,8 @@ return formatOffset(this.fixed, format);

/** @override **/
/**
* Returns whether the offset is known to be fixed for the whole year:
* Always returns true for all fixed offset zones.
* @override
* @type {boolean}
*/
get isUniversal() {

@@ -94,3 +126,9 @@ return true;

/** @override **/
/**
* Return the offset in minutes for this zone at the specified timestamp.
*
* For fixed offset zones, this is constant and does not depend on a timestamp.
* @override
* @return {number}
*/
offset() {

@@ -100,3 +138,8 @@ return this.fixed;

/** @override **/
/**
* Return whether this Zone is equal to another zone (i.e. also fixed and same offset)
* @override
* @param {Zone} otherZone - the zone to compare
* @return {boolean}
*/
equals(otherZone) {

@@ -106,3 +149,8 @@ return otherZone.type === "fixed" && otherZone.fixed === this.fixed;

/** @override **/
/**
* Return whether this Zone is valid:
* All fixed offset zones are valid.
* @override
* @type {boolean}
*/
get isValid() {

@@ -109,0 +157,0 @@ return true;

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

* @example IANAZone.isValidSpecifier("Sport~~blorp") //=> false
* @deprecated This method returns false for some valid IANA names. Use isValidZone instead.
* @deprecated For backward compatibility, this forwards to isValidZone, better use `isValidZone()` directly instead.
* @return {boolean}

@@ -122,3 +122,7 @@ */

/** @override **/
/**
* The type of zone. `iana` for all instances of `IANAZone`.
* @override
* @type {string}
*/
get type() {

@@ -128,3 +132,7 @@ return "iana";

/** @override **/
/**
* The name of this zone (i.e. the IANA zone name).
* @override
* @type {string}
*/
get name() {

@@ -134,3 +142,8 @@ return this.zoneName;

/** @override **/
/**
* Returns whether the offset is known to be fixed for the whole year:
* Always returns false for all IANA zones.
* @override
* @type {boolean}
*/
get isUniversal() {

@@ -140,3 +153,11 @@ return false;

/** @override **/
/**
* Returns the offset's common name (such as EST) at the specified timestamp
* @override
* @param {number} ts - Epoch milliseconds for which to get the name
* @param {Object} opts - Options to affect the format
* @param {string} opts.format - What style of offset to return. Accepts 'long' or 'short'.
* @param {string} opts.locale - What locale to return the offset name in.
* @return {string}
*/
offsetName(ts, { format, locale }) {

@@ -146,3 +167,10 @@ return parseZoneInfo(ts, format, locale, this.name);

/** @override **/
/**
* Returns the offset's value as a string
* @override
* @param {number} ts - Epoch milliseconds for which to get the offset
* @param {string} format - What style of offset to return.
* Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively
* @return {string}
*/
formatOffset(ts, format) {

@@ -152,3 +180,8 @@ return formatOffset(this.offset(ts), format);

/** @override **/
/**
* Return the offset in minutes for this zone at the specified timestamp.
* @override
* @param {number} ts - Epoch milliseconds for which to compute the offset
* @return {number}
*/
offset(ts) {

@@ -187,3 +220,8 @@ const date = new Date(ts);

/** @override **/
/**
* Return whether this Zone is equal to another zone
* @override
* @param {Zone} otherZone - the zone to compare
* @return {boolean}
*/
equals(otherZone) {

@@ -193,3 +231,7 @@ return otherZone.type === "iana" && otherZone.name === this.name;

/** @override **/
/**
* Return whether this Zone is valid.
* @override
* @type {boolean}
*/
get isValid() {

@@ -196,0 +238,0 @@ return this.valid;

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

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