@capillarytech/cap-ui-utils 3.0.8 → 3.0.9-alpha.1
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 +11 -6
package/package.json
CHANGED
package/utils/timezone.js
CHANGED
|
@@ -17,7 +17,7 @@ export const DATE_FORMAT = "DD MMM YYYY h:mm A";
|
|
|
17
17
|
* @param {boolean} orgTZ - Whether to force conversion into org timezone.
|
|
18
18
|
* @returns {string} Formatted date string with strict TZ abbreviation or '-'.
|
|
19
19
|
*/
|
|
20
|
-
export const formatDateWithTimezone = (date, orgTZ = false) => {
|
|
20
|
+
export const formatDateWithTimezone = (date, orgTZ = false, onlyAbbr = false) => {
|
|
21
21
|
try{
|
|
22
22
|
if (!date) return "-";
|
|
23
23
|
|
|
@@ -49,7 +49,12 @@ export const formatDateWithTimezone = (date, orgTZ = false) => {
|
|
|
49
49
|
tzAbbr = "UTC"; // fallback
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
if(onlyAbbr){
|
|
53
|
+
return tzAbbr;
|
|
54
|
+
}
|
|
55
|
+
else{
|
|
56
|
+
return `${momentDate.format(DATE_FORMAT)} ${tzAbbr}`;
|
|
57
|
+
}
|
|
53
58
|
}
|
|
54
59
|
catch(error){
|
|
55
60
|
console.error(error);
|
|
@@ -75,12 +80,12 @@ export const getTimezoneTooltip = (date, orgTZ = false) => {
|
|
|
75
80
|
const serverTimezone = utilsLocalStorageApi.loadItem("serverTZ") || "Asia/Kolkata";
|
|
76
81
|
|
|
77
82
|
if(orgTZ){
|
|
78
|
-
return
|
|
83
|
+
return `${orgTimezone} (UTC${moment.tz(orgTimezone).format("Z")})`;
|
|
79
84
|
}
|
|
80
85
|
else{
|
|
81
86
|
// case 1: epoch number or numeric string
|
|
82
87
|
if(typeof date === "number" || (typeof date === "string" && /^\d+$/.test(date))){
|
|
83
|
-
return
|
|
88
|
+
return `${orgTimezone} (UTC${moment.tz(orgTimezone).format("Z")})`;
|
|
84
89
|
}
|
|
85
90
|
// case 2: ISO string or Date object
|
|
86
91
|
else{
|
|
@@ -89,9 +94,9 @@ export const getTimezoneTooltip = (date, orgTZ = false) => {
|
|
|
89
94
|
m = moment.tz(date, "DD MMM YYYY h:mm A z"); // handles strings like 17 Sep 2025 6:00 AM EDT
|
|
90
95
|
}
|
|
91
96
|
if(!m.isValid() || m.isUTC()){
|
|
92
|
-
return
|
|
97
|
+
return `${orgTimezone} (UTC${moment.tz(orgTimezone).format("Z")})`; // fallback to orgTZ
|
|
93
98
|
}
|
|
94
|
-
return
|
|
99
|
+
return `${serverTimezone} (UTC${m.format("Z")})`; // return the timezone and offset
|
|
95
100
|
}
|
|
96
101
|
}
|
|
97
102
|
};
|