temporal-fmt 0.8.981 → 0.8.982
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/cli.mjs +23 -1
package/package.json
CHANGED
package/scripts/cli.mjs
CHANGED
|
@@ -78,6 +78,11 @@ function parseIsoInput(isoInput) {
|
|
|
78
78
|
return Temporal.PlainDate.from(isoInput);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
// Matches the "+HH:MM"/"-HH:MM" offset suffix that parseIsoInput's
|
|
82
|
+
// PlainDateTime.from() branch silently discards. Used only to make the
|
|
83
|
+
// resulting "no offset field" format() error more specific — see below.
|
|
84
|
+
const HAS_NUMERIC_OFFSET = /T.*[+-]\d{2}:\d{2}$/;
|
|
85
|
+
|
|
81
86
|
// Each command takes { positional, options } and either returns the
|
|
82
87
|
// output string or throws. Kept free of process.exit/stdout writes so
|
|
83
88
|
// both one-shot mode and the REPL can call the same logic and just
|
|
@@ -95,7 +100,24 @@ const COMMANDS = {
|
|
|
95
100
|
} catch (err) {
|
|
96
101
|
throw new Error(`could not parse "${isoInput}" as a Temporal value: ${err.message}`);
|
|
97
102
|
}
|
|
98
|
-
|
|
103
|
+
try {
|
|
104
|
+
return format(temporal, formatStr, { locale });
|
|
105
|
+
} catch (err) {
|
|
106
|
+
// parseIsoInput deliberately drops a numeric offset (e.g. "+02:00")
|
|
107
|
+
// when it's not "Z" — see the comment there — so any offset token
|
|
108
|
+
// (X/XX/XXX/x/xx/xxx) fails with a generic "doesn't have this
|
|
109
|
+
// field" error that gives no hint the offset was ever present.
|
|
110
|
+
// Recognize that specific case and say so, without changing what
|
|
111
|
+
// parseIsoInput actually does.
|
|
112
|
+
if (/requires "offset"/.test(err.message) && HAS_NUMERIC_OFFSET.test(isoInput)) {
|
|
113
|
+
throw new Error(
|
|
114
|
+
`${err.message} "${isoInput}" has a numeric offset, but temporal-fmt drops it during parsing ` +
|
|
115
|
+
`and keeps only the wall-clock date/time (see --help). Offset-formatting tokens only work on ` +
|
|
116
|
+
`a "Z"-suffixed input.`
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
throw err;
|
|
120
|
+
}
|
|
99
121
|
},
|
|
100
122
|
},
|
|
101
123
|
parse: {
|