@capillarytech/cap-ui-utils 3.0.9-alpha.6 → 3.0.9-alpha.8

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 +8 -63
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capillarytech/cap-ui-utils",
3
- "version": "3.0.9-alpha.6",
3
+ "version": "3.0.9-alpha.8",
4
4
  "description": "Utility functions shared accross all the modules",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/utils/timezone.js CHANGED
@@ -40,10 +40,9 @@ const DST_NEUTRAL_TZ_MAP = {
40
40
 
41
41
  };
42
42
 
43
- const getTimezoneFormattedDate = (date,orgTZ = false,serverTZ = false,customTZ = null) => {
43
+ const getTimezoneFormattedDate = (date,orgTZ = false,customTZ = null) => {
44
44
  const orgTimezone = utilsLocalStorageApi.loadItem("orgTZ") || "Asia/Kolkata";
45
- const serverTimezone = utilsLocalStorageApi.loadItem("serverTZ") || "Asia/Kolkata";
46
- const targetTimezone = customTZ || (serverTZ ? serverTimezone : orgTZ ? orgTimezone : orgTimezone);
45
+ const targetTimezone = customTZ || (orgTZ ? orgTimezone : orgTimezone);
47
46
  let momentDate;
48
47
 
49
48
  // If date is epoch (number or numeric string)
@@ -90,9 +89,8 @@ const getTimezoneFormattedDate = (date,orgTZ = false,serverTZ = false,customTZ =
90
89
  *
91
90
  * Timezone Selection Priority:
92
91
  * 1. customTZ (if provided) - overrides all others
93
- * 2. serverTZ=true → uses server timezone from localStorage
94
- * 3. orgTZ=true → uses organization timezone from localStorage
95
- * 4. Default → uses organization timezone from localStorage
92
+ * 2. orgTZ=true → uses organization timezone from localStorage
93
+ * 3. Default → uses organization timezone from localStorage
96
94
  *
97
95
  * Input Handling:
98
96
  * - Epoch input (number or numeric string):
@@ -105,73 +103,20 @@ const getTimezoneFormattedDate = (date,orgTZ = false,serverTZ = false,customTZ =
105
103
  * - Converts to target timezone
106
104
  *
107
105
  * @param {string|number|Date} date - Epoch timestamp, ISO string with timezone, or Date object.
108
- * @param {boolean} orgTZ - Whether to force conversion into organization timezone.
109
- * @param {boolean} serverTZ - Whether to force conversion into server timezone.
106
+ * @param {boolean} orgTZ - Whether to force conversion into organization timezone. Default is true.
110
107
  * @param {string|null} customTZ - Custom timezone override (e.g., "Asia/Kolkata").
111
108
  * @returns {string} Formatted date string with timezone abbreviation or '-'.
112
109
  */
113
- export const formatDateWithTimezone = (date, tzAbbr = true,orgTZ = false, serverTZ = false, customTZ = null) => {
110
+ export const formatDateWithTimezone = (date, orgTZ = true, customTZ = null) => {
114
111
  try {
115
112
  if (!date) return "-";
116
113
 
117
- const momentDate = getTimezoneFormattedDate(date,orgTZ,serverTZ,customTZ);
114
+ const momentDate = getTimezoneFormattedDate(date,orgTZ,customTZ);
118
115
  if (!momentDate.isValid()) return "-";
119
116
 
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
- }
127
- } catch (error) {
128
- console.error(error);
129
- return "-";
130
- }
131
- };
132
-
133
- /**
134
- * Returns a tooltip string with the timezone and offset for a given date.
135
- *
136
- * Timezone Selection Priority:
137
- * 1. customTZ (if provided) - overrides all others
138
- * 2. serverTZ=true → uses server timezone from localStorage
139
- * 3. orgTZ=true → uses organization timezone from localStorage
140
- * 4. Default → uses organization timezone from localStorage
141
- *
142
- * Input Handling:
143
- * - Epoch input (number or numeric string):
144
- * - Treated as UTC timestamp (seconds or milliseconds)
145
- * - Returns timezone info for that specific date/time
146
- * - ISO input (e.g., "2025-01-09T00:00:00+05:30"):
147
- * - Parses timezone offset correctly
148
- * - Returns timezone info for that specific date/time
149
- * - Formatted date string (e.g., "10 Oct 2025 4:00 PM IST"):
150
- * - Parses formatted date with timezone abbreviation
151
- * - Returns timezone info for that specific date/time
152
- * - Date object:
153
- * - Returns timezone info for that specific date/time
154
- *
155
- * @param {string|number|Date} date - Epoch timestamp, ISO string with timezone, formatted date string, or Date object.
156
- * @param {boolean} orgTZ - Whether to force conversion into organization timezone.
157
- * @param {boolean} serverTZ - Whether to force conversion into server timezone.
158
- * @param {string|null} customTZ - Custom timezone override (e.g., "Asia/Kolkata").
159
- * @returns {string} Tooltip string with timezone abbreviation and UTC offset for the specific date.
160
- */
161
- export const getTimezoneTooltip = (date, orgTZ = false, serverTZ = false, customTZ = null) => {
162
- try {
163
- if (!date) return "-";
164
-
165
- const orgTimezone = utilsLocalStorageApi.loadItem("orgTZ") || "Asia/Kolkata";
166
- const serverTimezone = utilsLocalStorageApi.loadItem("serverTZ") || "Asia/Kolkata";
167
- const targetTimezone = customTZ || (serverTZ ? serverTimezone : orgTZ ? orgTimezone : orgTimezone);
168
- const momentDate = getTimezoneFormattedDate(date,orgTZ,serverTZ,customTZ);
169
- if (!momentDate.isValid()) return "-";
170
-
171
117
  let tzAbbr = momentDate.format("z");
172
118
  tzAbbr = DST_NEUTRAL_TZ_MAP[tzAbbr] || tzAbbr;
173
- const utcOffset = momentDate.format("Z"); // e.g., +05:30, -04:00
174
- return `${targetTimezone} (${tzAbbr},UTC${utcOffset})`;
119
+ return `${momentDate.format(DATE_FORMAT)} ${tzAbbr}`;
175
120
  } catch (error) {
176
121
  console.error(error);
177
122
  return "-";