diff options
| author | 2022-04-20 00:12:09 -0400 | |
|---|---|---|
| committer | 2022-04-20 00:12:09 -0400 | |
| commit | 942e313727d1ad886a1024c24fe4a9e8e2e0bb3e (patch) | |
| tree | 1c4d5d826655cdb812c88563a25410f8b54e41d2 /npm_assets/node_modules/luxon/src/impl | |
| parent | 8eeed31eb2f86ac982fa4b26f93b15828289c56d (diff) | |
New upstream version 8.2.0.upstream/8.2.0
Diffstat (limited to 'npm_assets/node_modules/luxon/src/impl')
| -rw-r--r-- | npm_assets/node_modules/luxon/src/impl/diff.js | 1 | ||||
| -rw-r--r-- | npm_assets/node_modules/luxon/src/impl/english.js | 18 | ||||
| -rw-r--r-- | npm_assets/node_modules/luxon/src/impl/formatter.js | 2 | ||||
| -rw-r--r-- | npm_assets/node_modules/luxon/src/impl/locale.js | 39 | ||||
| -rw-r--r-- | npm_assets/node_modules/luxon/src/impl/regexParser.js | 34 | ||||
| -rw-r--r-- | npm_assets/node_modules/luxon/src/impl/util.js | 12 |
6 files changed, 71 insertions, 35 deletions
diff --git a/npm_assets/node_modules/luxon/src/impl/diff.js b/npm_assets/node_modules/luxon/src/impl/diff.js index 57246dc..1b8afb3 100644 --- a/npm_assets/node_modules/luxon/src/impl/diff.js +++ b/npm_assets/node_modules/luxon/src/impl/diff.js @@ -13,6 +13,7 @@ function dayDiff(earlier, later) { function highOrderDiffs(cursor, later, units) { const differs = [ ["years", (a, b) => b.year - a.year], + ["quarters", (a, b) => b.quarter - a.quarter], ["months", (a, b) => b.month - a.month + (b.year - a.year) * 12], [ "weeks", diff --git a/npm_assets/node_modules/luxon/src/impl/english.js b/npm_assets/node_modules/luxon/src/impl/english.js index 633f594..0ae2069 100644 --- a/npm_assets/node_modules/luxon/src/impl/english.js +++ b/npm_assets/node_modules/luxon/src/impl/english.js @@ -44,11 +44,11 @@ export const monthsNarrow = ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", " export function months(length) { switch (length) { case "narrow": - return monthsNarrow; + return [...monthsNarrow]; case "short": - return monthsShort; + return [...monthsShort]; case "long": - return monthsLong; + return [...monthsLong]; case "numeric": return ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"]; case "2-digit": @@ -75,11 +75,11 @@ export const weekdaysNarrow = ["M", "T", "W", "T", "F", "S", "S"]; export function weekdays(length) { switch (length) { case "narrow": - return weekdaysNarrow; + return [...weekdaysNarrow]; case "short": - return weekdaysShort; + return [...weekdaysShort]; case "long": - return weekdaysLong; + return [...weekdaysLong]; case "numeric": return ["1", "2", "3", "4", "5", "6", "7"]; default: @@ -98,11 +98,11 @@ export const erasNarrow = ["B", "A"]; export function eras(length) { switch (length) { case "narrow": - return erasNarrow; + return [...erasNarrow]; case "short": - return erasShort; + return [...erasShort]; case "long": - return erasLong; + return [...erasLong]; default: return null; } diff --git a/npm_assets/node_modules/luxon/src/impl/formatter.js b/npm_assets/node_modules/luxon/src/impl/formatter.js index 98872f9..87b8a2f 100644 --- a/npm_assets/node_modules/luxon/src/impl/formatter.js +++ b/npm_assets/node_modules/luxon/src/impl/formatter.js @@ -166,7 +166,7 @@ export default class Formatter { era = length => knownEnglish ? English.eraForDateTime(dt, length) : string({ era: length }, "era"), tokenToString = token => { - // Where possible: http://cldr.unicode.org/translation/date-time#TOC-Stand-Alone-vs.-Format-Styles + // Where possible: http://cldr.unicode.org/translation/date-time-1/date-time#TOC-Standalone-vs.-Format-Styles switch (token) { // ms case "S": diff --git a/npm_assets/node_modules/luxon/src/impl/locale.js b/npm_assets/node_modules/luxon/src/impl/locale.js index 0f797b1..44a9266 100644 --- a/npm_assets/node_modules/luxon/src/impl/locale.js +++ b/npm_assets/node_modules/luxon/src/impl/locale.js @@ -3,6 +3,7 @@ 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"; let intlDTCache = {}; function getCachedDTF(locString, opts = {}) { @@ -183,20 +184,32 @@ class PolyDateFormatter { let z; if (dt.zone.universal && this.hasIntl) { - // Chromium doesn't support fixed-offset zones like Etc/GMT+8 in its formatter, - // See https://bugs.chromium.org/p/chromium/issues/detail?id=364374. - // So we have to make do. Two cases: - // 1. The format options tell us to show the zone. We can't do that, so the best - // we can do is format the date in UTC. - // 2. The format options don't tell us to show the zone. Then we can adjust them - // the time and tell the formatter to show it to us in UTC, so that the time is right - // and the bad zone doesn't show up. - // We can clean all this up when Chrome fixes this. - z = "UTC"; - if (opts.timeZoneName) { + // UTC-8 or Etc/UTC-8 are not part of tzdata, only Etc/GMT+8 and the like. + // That is why fixed-offset TZ is set to that unless it is: + // 1. Representing offset 0 when UTC is used to maintain previous behavior and does not become GMT. + // 2. Unsupported by the browser: + // - some do not support Etc/ + // - < Etc/GMT-14, > Etc/GMT+12, and 30-minute or 45-minute offsets are not part of tzdata + const gmtOffset = -1 * (dt.offset / 60); + const offsetZ = gmtOffset >= 0 ? `Etc/GMT+${gmtOffset}` : `Etc/GMT${gmtOffset}`; + const isOffsetZoneSupported = IANAZone.isValidZone(offsetZ); + if (dt.offset !== 0 && isOffsetZoneSupported) { + z = offsetZ; this.dt = dt; } else { - this.dt = dt.offset === 0 ? dt : DateTime.fromMillis(dt.ts + dt.offset * 60 * 1000); + // Not all fixed-offset zones like Etc/+4:30 are present in tzdata. + // So we have to make do. Two cases: + // 1. The format options tell us to show the zone. We can't do that, so the best + // we can do is format the date in UTC. + // 2. The format options don't tell us to show the zone. Then we can adjust them + // the time and tell the formatter to show it to us in UTC, so that the time is right + // and the bad zone doesn't show up. + z = "UTC"; + if (opts.timeZoneName) { + this.dt = dt; + } else { + this.dt = dt.offset === 0 ? dt : DateTime.fromMillis(dt.ts + dt.offset * 60 * 1000); + } } } else if (dt.zone.type === "local") { this.dt = dt; @@ -418,7 +431,7 @@ export default class Locale { return listStuff(this, length, defaultOK, English.eras, () => { const intl = { era: length }; - // This is utter bullshit. Different calendars are going to define eras totally differently. What I need is the minimum set of dates + // This is problematic. Different calendars are going to define eras totally differently. What I need is the minimum set of dates // to definitely enumerate them. if (!this.eraCache[length]) { this.eraCache[length] = [DateTime.utc(-40, 1, 1), DateTime.utc(2017, 1, 1)].map(dt => diff --git a/npm_assets/node_modules/luxon/src/impl/regexParser.js b/npm_assets/node_modules/luxon/src/impl/regexParser.js index 74ba737..0b0297b 100644 --- a/npm_assets/node_modules/luxon/src/impl/regexParser.js +++ b/npm_assets/node_modules/luxon/src/impl/regexParser.js @@ -97,10 +97,10 @@ function extractISOYmd(match, cursor) { function extractISOTime(match, cursor) { const item = { - hour: int(match, cursor, 0), - minute: int(match, cursor + 1, 0), - second: int(match, cursor + 2, 0), - millisecond: parseMillis(match[cursor + 3]) + hours: int(match, cursor, 0), + minutes: int(match, cursor + 1, 0), + seconds: int(match, cursor + 2, 0), + milliseconds: parseMillis(match[cursor + 3]) }; return [item, null, cursor + 4]; @@ -118,6 +118,10 @@ function extractIANAZone(match, cursor) { return [{}, zone, cursor + 1]; } +// ISO time parsing + +const isoTimeOnly = RegExp(`^T?${isoTimeBaseRegex.source}$`); + // ISO duration parsing 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)?)?)$/; @@ -136,8 +140,10 @@ function extractISODuration(match) { ] = match; const hasNegativePrefix = s[0] === "-"; + const negativeSeconds = secondStr && secondStr[0] === "-"; - const maybeNegate = num => (num && hasNegativePrefix ? -num : num); + const maybeNegate = (num, force = false) => + num !== undefined && (force || (num && hasNegativePrefix)) ? -num : num; return [ { @@ -147,8 +153,8 @@ function extractISODuration(match) { days: maybeNegate(parseInteger(dayStr)), hours: maybeNegate(parseInteger(hourStr)), minutes: maybeNegate(parseInteger(minuteStr)), - seconds: maybeNegate(parseInteger(secondStr)), - milliseconds: maybeNegate(parseMillis(millisecondsStr)) + seconds: maybeNegate(parseInteger(secondStr), secondStr === "-0"), + milliseconds: maybeNegate(parseMillis(millisecondsStr), negativeSeconds) } ]; } @@ -261,7 +267,11 @@ const extractISOWeekTimeAndOffset = combineExtractors( extractISOTime, extractISOOffset ); -const extractISOOrdinalDataAndTime = combineExtractors(extractISOOrdinalData, extractISOTime); +const extractISOOrdinalDateAndTime = combineExtractors( + extractISOOrdinalData, + extractISOTime, + extractISOOffset +); const extractISOTimeAndOffset = combineExtractors(extractISOTime, extractISOOffset); /** @@ -273,7 +283,7 @@ export function parseISODate(s) { s, [isoYmdWithTimeExtensionRegex, extractISOYmdTimeAndOffset], [isoWeekWithTimeExtensionRegex, extractISOWeekTimeAndOffset], - [isoOrdinalWithTimeExtensionRegex, extractISOOrdinalDataAndTime], + [isoOrdinalWithTimeExtensionRegex, extractISOOrdinalDateAndTime], [isoTimeCombinedRegex, extractISOTimeAndOffset] ); } @@ -295,6 +305,12 @@ export function parseISODuration(s) { return parse(s, [isoDuration, extractISODuration]); } +const extractISOTimeOnly = combineExtractors(extractISOTime); + +export function parseISOTimeOnly(s) { + return parse(s, [isoTimeOnly, extractISOTimeOnly]); +} + const sqlYmdWithTimeExtensionRegex = combineRegexes(sqlYmdRegex, sqlTimeExtensionRegex); const sqlTimeCombinedRegex = combineRegexes(sqlTimeRegex); diff --git a/npm_assets/node_modules/luxon/src/impl/util.js b/npm_assets/node_modules/luxon/src/impl/util.js index b345c69..59f6f86 100644 --- a/npm_assets/node_modules/luxon/src/impl/util.js +++ b/npm_assets/node_modules/luxon/src/impl/util.js @@ -99,11 +99,17 @@ export function floorMod(x, n) { } export function padStart(input, n = 2) { - if (input.toString().length < n) { - return ("0".repeat(n) + input).slice(-n); + const minus = input < 0 ? "-" : ""; + const target = minus ? input * -1 : input; + let result; + + if (target.toString().length < n) { + result = ("0".repeat(n) + target).slice(-n); } else { - return input.toString(); + result = target.toString(); } + + return `${minus}${result}`; } export function parseInteger(string) { |
