@capillarytech/cap-ui-utils 3.0.9-alpha.8 → 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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/utils/timezone.js +13 -36
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capillarytech/cap-ui-utils",
3
- "version": "3.0.9-alpha.8",
3
+ "version": "3.0.10-alpha.0",
4
4
  "description": "Utility functions shared accross all the modules",
5
5
  "main": "index.js",
6
6
  "scripts": {
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
- * 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.
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 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
-
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 tzAbbr = momentDate.format("z");
118
- tzAbbr = DST_NEUTRAL_TZ_MAP[tzAbbr] || 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);