@capillarytech/cap-ui-utils 3.0.9-alpha.6 → 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.
- package/package.json +1 -1
- package/utils/timezone.js +2 -54
package/package.json
CHANGED
package/utils/timezone.js
CHANGED
|
@@ -110,68 +110,16 @@ const getTimezoneFormattedDate = (date,orgTZ = false,serverTZ = false,customTZ =
|
|
|
110
110
|
* @param {string|null} customTZ - Custom timezone override (e.g., "Asia/Kolkata").
|
|
111
111
|
* @returns {string} Formatted date string with timezone abbreviation or '-'.
|
|
112
112
|
*/
|
|
113
|
-
export const formatDateWithTimezone = (date,
|
|
113
|
+
export const formatDateWithTimezone = (date, orgTZ = false, serverTZ = false, customTZ = null) => {
|
|
114
114
|
try {
|
|
115
115
|
if (!date) return "-";
|
|
116
116
|
|
|
117
117
|
const momentDate = getTimezoneFormattedDate(date,orgTZ,serverTZ,customTZ);
|
|
118
118
|
if (!momentDate.isValid()) return "-";
|
|
119
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
|
-
}
|
|
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
120
|
let tzAbbr = momentDate.format("z");
|
|
172
121
|
tzAbbr = DST_NEUTRAL_TZ_MAP[tzAbbr] || tzAbbr;
|
|
173
|
-
|
|
174
|
-
return `${targetTimezone} (${tzAbbr},UTC${utcOffset})`;
|
|
122
|
+
return `${momentDate.format(DATE_FORMAT)} ${tzAbbr}`;
|
|
175
123
|
} catch (error) {
|
|
176
124
|
console.error(error);
|
|
177
125
|
return "-";
|