@capillarytech/cap-ui-utils 3.0.9 → 3.0.10-alpha.0
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 +13 -36
package/package.json
CHANGED
package/utils/timezone.js
CHANGED
|
@@ -4,40 +4,17 @@ import { DATE_FORMAT,TIMEZONE_ENABLED } from "./constants";
|
|
|
4
4
|
import hasFeatureAccess from "../auth/hasFeatureAccess";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
* @
|
|
9
|
-
* @
|
|
10
|
-
*
|
|
11
|
-
* EST -> ET
|
|
12
|
-
* EDT -> ET
|
|
13
|
-
* Please add any additional DST-observing regions as needed.
|
|
7
|
+
* Get the timezone abbreviation for a given timezone
|
|
8
|
+
* @param {string} timezone - The timezone to get the abbreviation for
|
|
9
|
+
* @returns {string} The timezone abbreviation for the given IANA timezone
|
|
10
|
+
* If Abbreviation is not found then return UTC+X:XX format
|
|
14
11
|
*/
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
12
|
+
export const getTimezoneAbbreviation = timezone => {
|
|
13
|
+
const tzAbbr = moment.tz(timezone).format('z');
|
|
14
|
+
if(tzAbbr.startsWith('+') || tzAbbr.startsWith('-')) {
|
|
15
|
+
return `UTC${moment.utcOffset(tzAbbr)}`;
|
|
16
|
+
}
|
|
17
|
+
return tzAbbr;
|
|
41
18
|
};
|
|
42
19
|
|
|
43
20
|
const getTimezoneFormattedDate = (date,orgTZ = false,customTZ = null) => {
|
|
@@ -113,9 +90,9 @@ export const formatDateWithTimezone = (date, orgTZ = true, customTZ = null) => {
|
|
|
113
90
|
|
|
114
91
|
const momentDate = getTimezoneFormattedDate(date,orgTZ,customTZ);
|
|
115
92
|
if (!momentDate.isValid()) return "-";
|
|
116
|
-
|
|
117
|
-
let
|
|
118
|
-
tzAbbr =
|
|
93
|
+
const orgTimezone = utilsLocalStorageApi.loadItem("orgTZ") || "Asia/Kolkata";
|
|
94
|
+
let targetTimezone = orgTZ ? orgTimezone : customTZ ? customTZ : orgTimezone;
|
|
95
|
+
let tzAbbr = getTimezoneAbbreviation(targetTimezone);
|
|
119
96
|
return `${momentDate.format(DATE_FORMAT)} ${tzAbbr}`;
|
|
120
97
|
} catch (error) {
|
|
121
98
|
console.error(error);
|