@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.
@@ -25,7 +25,22 @@ export declare function formatCurrency(amount: number, currency?: string): strin
25
25
  export interface FormatDateOptions extends Intl.DateTimeFormatOptions {
26
26
  locale?: string | string[];
27
27
  }
28
- export declare function formatDate(date: Date | string | number, options?: FormatDateOptions): string;
28
+ /**
29
+ * Parses a date value the way every date coming from these platforms'
30
+ * Java/Kotlin backends actually shows up, without the classic off-by-one
31
+ * timezone bug.
32
+ *
33
+ * A bare "YYYY-MM-DD" string is parsed by `new Date(...)` as UTC midnight
34
+ * (per the ECMAScript spec), which then shifts a day earlier once formatted
35
+ * in any timezone behind UTC. This function parses date-only strings (and
36
+ * Jackson's `[year, month, day, ...]` LocalDate/LocalDateTime array
37
+ * serialization) as local calendar components instead. Full ISO datetime
38
+ * strings (with a time and/or timezone), Date objects, and numeric
39
+ * timestamps are unaffected and still go through the normal `new Date(...)`
40
+ * parse.
41
+ */
42
+ export declare function parseDateSafe(date: Date | string | number | number[]): Date;
43
+ export declare function formatDate(date: Date | string | number | number[], options?: FormatDateOptions): string;
29
44
  /**
30
45
  * Utility function to debounce function calls
31
46
  * @param func - Function to debounce
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,MAAM,CAAC;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EACL,aAAa,EACb,iCAAiC,EACjC,gCAAgC,EAChC,qBAAqB,GACtB,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,iBAAiB,EAAE,sBAAsB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G,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,EAChE,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,MAAM,GACX,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAMlC;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,SAAQ,GAAG,MAAM,CAEjD;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,KAAG,MAE7C,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAMzD;AAED;;GAEG;AACH,oBAAY,SAAS;IACnB,UAAU,OAAO;IACjB,UAAU,OAAO;IACjB,UAAU,OAAO;IACjB,UAAU,OAAO;IACjB,WAAW,QAAQ;IACnB,WAAW,QAAQ;IACnB,UAAU,OAAO;IACjB,UAAU,OAAO;IACjB,OAAO,YAAY;CACpB;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,SAAS,EAUlC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ews-admin/global-design-system",
3
- "version": "1.21.0",
3
+ "version": "1.22.1",
4
4
  "description": "EWS Global Design System - Reusable components for EWS applications",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",
package/src/index.ts CHANGED
@@ -79,6 +79,7 @@ export {
79
79
  getRegionOptions,
80
80
  getRegionsByCountry,
81
81
  isValidPhoneNumber,
82
+ parseDateSafe,
82
83
  SupportedCountry,
83
84
  } from "./utils";
84
85
  export type {
@@ -51,12 +51,46 @@ export interface FormatDateOptions extends Intl.DateTimeFormatOptions {
51
51
  locale?: string | string[];
52
52
  }
53
53
 
54
+ /**
55
+ * Parses a date value the way every date coming from these platforms'
56
+ * Java/Kotlin backends actually shows up, without the classic off-by-one
57
+ * timezone bug.
58
+ *
59
+ * A bare "YYYY-MM-DD" string is parsed by `new Date(...)` as UTC midnight
60
+ * (per the ECMAScript spec), which then shifts a day earlier once formatted
61
+ * in any timezone behind UTC. This function parses date-only strings (and
62
+ * Jackson's `[year, month, day, ...]` LocalDate/LocalDateTime array
63
+ * serialization) as local calendar components instead. Full ISO datetime
64
+ * strings (with a time and/or timezone), Date objects, and numeric
65
+ * timestamps are unaffected and still go through the normal `new Date(...)`
66
+ * parse.
67
+ */
68
+ export function parseDateSafe(
69
+ date: Date | string | number | number[]
70
+ ): Date {
71
+ if (Array.isArray(date)) {
72
+ const [y, m, d, h = 0, min = 0, s = 0] = date;
73
+ return new Date(y, m - 1, d, h, min, s);
74
+ }
75
+ if (typeof date === "string") {
76
+ const dateOnlyMatch = /^(\d{4})-(\d{2})-(\d{2})$/.exec(date);
77
+ if (dateOnlyMatch) {
78
+ return new Date(
79
+ Number(dateOnlyMatch[1]),
80
+ Number(dateOnlyMatch[2]) - 1,
81
+ Number(dateOnlyMatch[3])
82
+ );
83
+ }
84
+ }
85
+ return new Date(date);
86
+ }
87
+
54
88
  export function formatDate(
55
- date: Date | string | number,
89
+ date: Date | string | number | number[],
56
90
  options?: FormatDateOptions
57
91
  ): string {
58
92
  const { locale = "en-US", ...intlOptions } = options ?? {};
59
- const dateObj = new Date(date);
93
+ const dateObj = parseDateSafe(date);
60
94
  return new Intl.DateTimeFormat(locale, {
61
95
  year: "numeric",
62
96
  month: "long",