@capillarytech/cap-ui-utils 3.0.9-alpha.5 → 3.0.9-alpha.7

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 +41 -53
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capillarytech/cap-ui-utils",
3
- "version": "3.0.9-alpha.5",
3
+ "version": "3.0.9-alpha.7",
4
4
  "description": "Utility functions shared accross all the modules",
5
5
  "main": "index.js",
6
6
  "scripts": {
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,65 +110,16 @@ 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, tzAbbr = true,orgTZ = false, serverTZ = false, customTZ = null) => {
113
+ export const formatDateWithTimezone = (date, 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
119
 
83
- if(tzAbbr) {
84
- const tzAbbr = momentDate.format("z");
85
- return `${momentDate.format(DATE_FORMAT)} ${tzAbbr}`;
86
- }
87
- return momentDate.format(DATE_FORMAT);
88
- } catch (error) {
89
- console.error(error);
90
- return "-";
91
- }
92
- };
93
-
94
- /**
95
- * Returns a tooltip string with the timezone and offset for a given date.
96
- *
97
- * Timezone Selection Priority:
98
- * 1. customTZ (if provided) - overrides all others
99
- * 2. serverTZ=true → uses server timezone from localStorage
100
- * 3. orgTZ=true → uses organization timezone from localStorage
101
- * 4. Default → uses organization timezone from localStorage
102
- *
103
- * Input Handling:
104
- * - Epoch input (number or numeric string):
105
- * - Treated as UTC timestamp (seconds or milliseconds)
106
- * - Returns timezone info for that specific date/time
107
- * - ISO input (e.g., "2025-01-09T00:00:00+05:30"):
108
- * - Parses timezone offset correctly
109
- * - Returns timezone info for that specific date/time
110
- * - Formatted date string (e.g., "10 Oct 2025 4:00 PM IST"):
111
- * - Parses formatted date with timezone abbreviation
112
- * - Returns timezone info for that specific date/time
113
- * - Date object:
114
- * - Returns timezone info for that specific date/time
115
- *
116
- * @param {string|number|Date} date - Epoch timestamp, ISO string with timezone, formatted date string, or Date object.
117
- * @param {boolean} orgTZ - Whether to force conversion into organization timezone.
118
- * @param {boolean} serverTZ - Whether to force conversion into server timezone.
119
- * @param {string|null} customTZ - Custom timezone override (e.g., "Asia/Kolkata").
120
- * @returns {string} Tooltip string with timezone abbreviation and UTC offset for the specific date.
121
- */
122
- export const getTimezoneTooltip = (date, orgTZ = false, serverTZ = false, customTZ = null) => {
123
- try {
124
- if (!date) return "-";
125
-
126
- const orgTimezone = utilsLocalStorageApi.loadItem("orgTZ") || "Asia/Kolkata";
127
- const serverTimezone = utilsLocalStorageApi.loadItem("serverTZ") || "Asia/Kolkata";
128
- const targetTimezone = customTZ || (serverTZ ? serverTimezone : orgTZ ? orgTimezone : orgTimezone);
129
- const momentDate = getTimezoneFormattedDate(date,orgTZ,serverTZ,customTZ);
130
- if (!momentDate.isValid()) return "-";
131
-
132
- const tzAbbr = momentDate.format("z"); // e.g., IST, PST, EDT
133
- const utcOffset = momentDate.format("Z"); // e.g., +05:30, -04:00
134
- return `${targetTimezone} (${tzAbbr},UTC${utcOffset})`;
120
+ let tzAbbr = momentDate.format("z");
121
+ tzAbbr = DST_NEUTRAL_TZ_MAP[tzAbbr] || tzAbbr;
122
+ return `${momentDate.format(DATE_FORMAT)} ${tzAbbr}`;
135
123
  } catch (error) {
136
124
  console.error(error);
137
125
  return "-";