Comparing version 3.2.1 to 3.3.0
{ | ||
"name": "luxon", | ||
"version": "3.2.1", | ||
"version": "3.3.0", | ||
"description": "Immutable date wrapper", | ||
@@ -53,3 +53,3 @@ "author": "Isaac Cambron", | ||
"husky": "^7.0.0", | ||
"jest": "^28.1.0", | ||
"jest": "^29.4.3", | ||
"lint-staged": "^11.0.0", | ||
@@ -56,0 +56,0 @@ "prettier": "latest", |
@@ -50,2 +50,5 @@ import * as English from "./english.js"; | ||
static parseFormat(fmt) { | ||
// white-space is always considered a literal in user-provided formats | ||
// the " " token has a special meaning (see unitForToken) | ||
let current = null, | ||
@@ -59,3 +62,3 @@ currentFull = "", | ||
if (currentFull.length > 0) { | ||
splits.push({ literal: bracketed, val: currentFull }); | ||
splits.push({ literal: bracketed || /^\s+$/.test(currentFull), val: currentFull }); | ||
} | ||
@@ -71,3 +74,3 @@ current = null; | ||
if (currentFull.length > 0) { | ||
splits.push({ literal: false, val: currentFull }); | ||
splits.push({ literal: /^\s+$/.test(currentFull), val: currentFull }); | ||
} | ||
@@ -80,3 +83,3 @@ currentFull = c; | ||
if (currentFull.length > 0) { | ||
splits.push({ literal: bracketed, val: currentFull }); | ||
splits.push({ literal: bracketed || /^\s+$/.test(currentFull), val: currentFull }); | ||
} | ||
@@ -83,0 +86,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { padStart, roundTo, hasRelative } from "./util.js"; | ||
import { padStart, roundTo, hasRelative, formatOffset } from "./util.js"; | ||
import * as English from "./english.js"; | ||
@@ -200,5 +200,9 @@ import Settings from "../settings.js"; | ||
this.opts = opts; | ||
this.originalZone = undefined; | ||
let z = undefined; | ||
if (dt.zone.isUniversal) { | ||
if (this.opts.timeZone) { | ||
// Don't apply any workarounds if a timeZone is explicitly provided in opts | ||
this.dt = dt; | ||
} else if (dt.zone.type === "fixed") { | ||
// UTC-8 or Etc/UTC-8 are not part of tzdata, only Etc/GMT+8 and the like. | ||
@@ -216,21 +220,19 @@ // That is why fixed-offset TZ is set to that unless it is: | ||
} else { | ||
// 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. | ||
// Not all fixed-offset zones like Etc/+4:30 are present in tzdata so | ||
// we manually apply the offset and substitute the zone as needed. | ||
z = "UTC"; | ||
if (opts.timeZoneName) { | ||
this.dt = dt; | ||
} else { | ||
this.dt = dt.offset === 0 ? dt : DateTime.fromMillis(dt.ts + dt.offset * 60 * 1000); | ||
} | ||
this.dt = dt.offset === 0 ? dt : dt.setZone("UTC").plus({ minutes: dt.offset }); | ||
this.originalZone = dt.zone; | ||
} | ||
} else if (dt.zone.type === "system") { | ||
this.dt = dt; | ||
} else { | ||
} else if (dt.zone.type === "iana") { | ||
this.dt = dt; | ||
z = dt.zone.name; | ||
} else { | ||
// Custom zones can have any offset / offsetName so we just manually | ||
// apply the offset and substitute the zone as needed. | ||
z = "UTC"; | ||
this.dt = dt.setZone("UTC").plus({ minutes: dt.offset }); | ||
this.originalZone = dt.zone; | ||
} | ||
@@ -244,2 +246,9 @@ | ||
format() { | ||
if (this.originalZone) { | ||
// If we have to substitute in the actual zone name, we have to use | ||
// formatToParts so that the timezone can be replaced. | ||
return this.formatToParts() | ||
.map(({ value }) => value) | ||
.join(""); | ||
} | ||
return this.dtf.format(this.dt.toJSDate()); | ||
@@ -249,3 +258,20 @@ } | ||
formatToParts() { | ||
return this.dtf.formatToParts(this.dt.toJSDate()); | ||
const parts = this.dtf.formatToParts(this.dt.toJSDate()); | ||
if (this.originalZone) { | ||
return parts.map((part) => { | ||
if (part.type === "timeZoneName") { | ||
const offsetName = this.originalZone.offsetName(this.dt.ts, { | ||
locale: this.dt.locale, | ||
format: this.opts.timeZoneName, | ||
}); | ||
return { | ||
...part, | ||
value: offsetName, | ||
}; | ||
} else { | ||
return part; | ||
} | ||
}); | ||
} | ||
return parts; | ||
} | ||
@@ -252,0 +278,0 @@ |
@@ -183,2 +183,6 @@ import { parseMillis, isUndefined, untruncateYear, signedOffset, hasOwnProperty } from "./util.js"; | ||
return simple(/[a-z_+-/]{1,256}?/i); | ||
// this special-case "token" represents a place where a macro-token expanded into a white-space literal | ||
// in this case we accept any non-newline white-space | ||
case " ": | ||
return simple(/[^\S\n\r]/); | ||
default: | ||
@@ -241,5 +245,6 @@ return literal(t); | ||
if (type === "literal") { | ||
const isSpace = /^\s+$/.test(value); | ||
return { | ||
literal: true, | ||
val: value, | ||
literal: !isSpace, | ||
val: isSpace ? " " : value, | ||
}; | ||
@@ -246,0 +251,0 @@ } |
@@ -169,3 +169,6 @@ /* | ||
d = new Date(d); | ||
d.setUTCFullYear(d.getUTCFullYear() - 1900); | ||
// set the month and day again, this is necessary because year 2000 is a leap year, but year 100 is not | ||
// so if obj.year is in 99, but obj.day makes it roll over into year 100, | ||
// the calculations done by Date.UTC are using year 2000 - which is incorrect | ||
d.setUTCFullYear(obj.year, obj.month - 1, obj.day); | ||
} | ||
@@ -172,0 +175,0 @@ return +d; |
@@ -243,3 +243,3 @@ import DateTime, { friendlyDateTime } from "./datetime.js"; | ||
end = this.end.startOf(unit); | ||
return Math.floor(end.diff(start, unit).get(unit)) + 1; | ||
return Math.floor(end.diff(start, unit).get(unit)) + (end.valueOf() !== this.end.valueOf()); | ||
} | ||
@@ -246,0 +246,0 @@ |
@@ -12,3 +12,3 @@ import DateTime from "./datetime.js"; | ||
const VERSION = "3.2.1"; | ||
const VERSION = "3.3.0"; | ||
@@ -15,0 +15,0 @@ export { |
{ | ||
"type": "module" | ||
"type": "module", | ||
"version": "3.3.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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4019766
41
41968