@capillarytech/cap-ui-utils 3.0.9-alpha.5 → 3.0.9-alpha.6
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/utils/timezone.js +43 -3
package/package.json
CHANGED
package/utils/timezone.js
CHANGED
|
@@ -3,6 +3,43 @@ import * as utilsLocalStorageApi from "./utilsLocalStorageApi";
|
|
|
3
3
|
import { DATE_FORMAT,TIMEZONE_ENABLED } from "./constants";
|
|
4
4
|
import hasFeatureAccess from "../auth/hasFeatureAccess";
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Map of timezone abbreviations to DST-neutral abbreviations
|
|
8
|
+
* @type {Object}
|
|
9
|
+
* @description This map is used to convert timezone abbreviations to DST-neutral abbreviations.
|
|
10
|
+
* @example
|
|
11
|
+
* EST -> ET
|
|
12
|
+
* EDT -> ET
|
|
13
|
+
* Please add any additional DST-observing regions as needed.
|
|
14
|
+
*/
|
|
15
|
+
const DST_NEUTRAL_TZ_MAP = {
|
|
16
|
+
// North America
|
|
17
|
+
EST: "ET", EDT: "ET",
|
|
18
|
+
CST: "CT", CDT: "CT",
|
|
19
|
+
MST: "MT", MDT: "MT",
|
|
20
|
+
PST: "PT", PDT: "PT",
|
|
21
|
+
AKST: "AKT", AKDT: "AKT",
|
|
22
|
+
HST: "HT", HDT: "HT",
|
|
23
|
+
|
|
24
|
+
// Europe
|
|
25
|
+
GMT: "GMT", BST: "GMT",
|
|
26
|
+
CET: "CET", CEST: "CET",
|
|
27
|
+
EET: "EET", EEST: "EET",
|
|
28
|
+
WEST: "WET", WET: "WET",
|
|
29
|
+
WEDT: "WET",
|
|
30
|
+
|
|
31
|
+
// Australia / New Zealand
|
|
32
|
+
AEST: "AET", AEDT: "AET",
|
|
33
|
+
ACST: "ACT", ACDT: "ACT",
|
|
34
|
+
AWST: "AWT",
|
|
35
|
+
NZST: "NZT", NZDT: "NZT",
|
|
36
|
+
|
|
37
|
+
// South America
|
|
38
|
+
BRT: "BRT", BRST: "BRT",
|
|
39
|
+
ART: "ART", ARST: "ART",
|
|
40
|
+
|
|
41
|
+
};
|
|
42
|
+
|
|
6
43
|
const getTimezoneFormattedDate = (date,orgTZ = false,serverTZ = false,customTZ = null) => {
|
|
7
44
|
const orgTimezone = utilsLocalStorageApi.loadItem("orgTZ") || "Asia/Kolkata";
|
|
8
45
|
const serverTimezone = utilsLocalStorageApi.loadItem("serverTZ") || "Asia/Kolkata";
|
|
@@ -81,10 +118,12 @@ export const formatDateWithTimezone = (date, tzAbbr = true,orgTZ = false, server
|
|
|
81
118
|
if (!momentDate.isValid()) return "-";
|
|
82
119
|
|
|
83
120
|
if(tzAbbr) {
|
|
84
|
-
|
|
121
|
+
let tzAbbr = momentDate.format("z");
|
|
122
|
+
tzAbbr = DST_NEUTRAL_TZ_MAP[tzAbbr] || tzAbbr;
|
|
85
123
|
return `${momentDate.format(DATE_FORMAT)} ${tzAbbr}`;
|
|
124
|
+
} else {
|
|
125
|
+
return momentDate.format(DATE_FORMAT);
|
|
86
126
|
}
|
|
87
|
-
return momentDate.format(DATE_FORMAT);
|
|
88
127
|
} catch (error) {
|
|
89
128
|
console.error(error);
|
|
90
129
|
return "-";
|
|
@@ -129,7 +168,8 @@ export const getTimezoneTooltip = (date, orgTZ = false, serverTZ = false, custom
|
|
|
129
168
|
const momentDate = getTimezoneFormattedDate(date,orgTZ,serverTZ,customTZ);
|
|
130
169
|
if (!momentDate.isValid()) return "-";
|
|
131
170
|
|
|
132
|
-
|
|
171
|
+
let tzAbbr = momentDate.format("z");
|
|
172
|
+
tzAbbr = DST_NEUTRAL_TZ_MAP[tzAbbr] || tzAbbr;
|
|
133
173
|
const utcOffset = momentDate.format("Z"); // e.g., +05:30, -04:00
|
|
134
174
|
return `${targetTimezone} (${tzAbbr},UTC${utcOffset})`;
|
|
135
175
|
} catch (error) {
|