@capillarytech/cap-ui-utils 3.0.9-alpha.4 → 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 +48 -5
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";
|
|
@@ -73,15 +110,20 @@ const getTimezoneFormattedDate = (date,orgTZ = false,serverTZ = false,customTZ =
|
|
|
73
110
|
* @param {string|null} customTZ - Custom timezone override (e.g., "Asia/Kolkata").
|
|
74
111
|
* @returns {string} Formatted date string with timezone abbreviation or '-'.
|
|
75
112
|
*/
|
|
76
|
-
export const formatDateWithTimezone = (date, orgTZ = false, serverTZ = false, customTZ = null) => {
|
|
113
|
+
export const formatDateWithTimezone = (date, tzAbbr = true,orgTZ = false, serverTZ = false, customTZ = null) => {
|
|
77
114
|
try {
|
|
78
115
|
if (!date) return "-";
|
|
79
116
|
|
|
80
117
|
const momentDate = getTimezoneFormattedDate(date,orgTZ,serverTZ,customTZ);
|
|
81
118
|
if (!momentDate.isValid()) return "-";
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
119
|
+
|
|
120
|
+
if(tzAbbr) {
|
|
121
|
+
let tzAbbr = momentDate.format("z");
|
|
122
|
+
tzAbbr = DST_NEUTRAL_TZ_MAP[tzAbbr] || tzAbbr;
|
|
123
|
+
return `${momentDate.format(DATE_FORMAT)} ${tzAbbr}`;
|
|
124
|
+
} else {
|
|
125
|
+
return momentDate.format(DATE_FORMAT);
|
|
126
|
+
}
|
|
85
127
|
} catch (error) {
|
|
86
128
|
console.error(error);
|
|
87
129
|
return "-";
|
|
@@ -126,7 +168,8 @@ export const getTimezoneTooltip = (date, orgTZ = false, serverTZ = false, custom
|
|
|
126
168
|
const momentDate = getTimezoneFormattedDate(date,orgTZ,serverTZ,customTZ);
|
|
127
169
|
if (!momentDate.isValid()) return "-";
|
|
128
170
|
|
|
129
|
-
|
|
171
|
+
let tzAbbr = momentDate.format("z");
|
|
172
|
+
tzAbbr = DST_NEUTRAL_TZ_MAP[tzAbbr] || tzAbbr;
|
|
130
173
|
const utcOffset = momentDate.format("Z"); // e.g., +05:30, -04:00
|
|
131
174
|
return `${targetTimezone} (${tzAbbr},UTC${utcOffset})`;
|
|
132
175
|
} catch (error) {
|