@ews-admin/global-design-system 1.21.0 → 1.22.1
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/dist/index.d.ts +17 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +29 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +29 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts +16 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/utils/index.ts +36 -2
package/dist/index.js
CHANGED
|
@@ -224,9 +224,36 @@ function formatCurrency(amount, currency = CURRENCY) {
|
|
|
224
224
|
currency,
|
|
225
225
|
}).format(amount);
|
|
226
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Parses a date value the way every date coming from these platforms'
|
|
229
|
+
* Java/Kotlin backends actually shows up, without the classic off-by-one
|
|
230
|
+
* timezone bug.
|
|
231
|
+
*
|
|
232
|
+
* A bare "YYYY-MM-DD" string is parsed by `new Date(...)` as UTC midnight
|
|
233
|
+
* (per the ECMAScript spec), which then shifts a day earlier once formatted
|
|
234
|
+
* in any timezone behind UTC. This function parses date-only strings (and
|
|
235
|
+
* Jackson's `[year, month, day, ...]` LocalDate/LocalDateTime array
|
|
236
|
+
* serialization) as local calendar components instead. Full ISO datetime
|
|
237
|
+
* strings (with a time and/or timezone), Date objects, and numeric
|
|
238
|
+
* timestamps are unaffected and still go through the normal `new Date(...)`
|
|
239
|
+
* parse.
|
|
240
|
+
*/
|
|
241
|
+
function parseDateSafe(date) {
|
|
242
|
+
if (Array.isArray(date)) {
|
|
243
|
+
const [y, m, d, h = 0, min = 0, s = 0] = date;
|
|
244
|
+
return new Date(y, m - 1, d, h, min, s);
|
|
245
|
+
}
|
|
246
|
+
if (typeof date === "string") {
|
|
247
|
+
const dateOnlyMatch = /^(\d{4})-(\d{2})-(\d{2})$/.exec(date);
|
|
248
|
+
if (dateOnlyMatch) {
|
|
249
|
+
return new Date(Number(dateOnlyMatch[1]), Number(dateOnlyMatch[2]) - 1, Number(dateOnlyMatch[3]));
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return new Date(date);
|
|
253
|
+
}
|
|
227
254
|
function formatDate(date, options) {
|
|
228
255
|
const { locale = "en-US", ...intlOptions } = options ?? {};
|
|
229
|
-
const dateObj =
|
|
256
|
+
const dateObj = parseDateSafe(date);
|
|
230
257
|
return new Intl.DateTimeFormat(locale, {
|
|
231
258
|
year: "numeric",
|
|
232
259
|
month: "long",
|
|
@@ -40818,6 +40845,7 @@ exports.getRegionOptions = getRegionOptions;
|
|
|
40818
40845
|
exports.getRegionsByCountry = getRegionsByCountry;
|
|
40819
40846
|
exports.icons = index;
|
|
40820
40847
|
exports.isValidPhoneNumber = isValidPhoneNumber;
|
|
40848
|
+
exports.parseDateSafe = parseDateSafe;
|
|
40821
40849
|
exports.useDebounce = useDebounce;
|
|
40822
40850
|
exports.useDebouncedCallback = useDebouncedCallback;
|
|
40823
40851
|
exports.useSelectField = useSelectField;
|