@capillarytech/cap-ui-utils 3.0.7-alpha.2 → 3.0.7-alpha.3
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 +12 -12
package/package.json
CHANGED
package/utils/timezone.js
CHANGED
|
@@ -9,9 +9,9 @@ export const DATE_FORMAT = "DD MMM YYYY h:mm A";
|
|
|
9
9
|
*
|
|
10
10
|
* - ISO input:
|
|
11
11
|
* - orgTZ=false → keep ISO timezone info
|
|
12
|
-
* - orgTZ=true → convert to org timezone
|
|
12
|
+
* - orgTZ=true → convert to org timezone
|
|
13
13
|
* - Epoch input:
|
|
14
|
-
* - Always converts to org timezone
|
|
14
|
+
* - Always converts to org timezone
|
|
15
15
|
*
|
|
16
16
|
* @param {string|number|Date} date - ISO string, epoch (sec/ms), or Date object.
|
|
17
17
|
* @param {boolean} orgTZ - Whether to force conversion into org timezone.
|
|
@@ -21,7 +21,7 @@ export const formatDateWithTimezone = (date, orgTZ = false) => {
|
|
|
21
21
|
if (!date) return "-";
|
|
22
22
|
|
|
23
23
|
let momentDate;
|
|
24
|
-
const orgTimezone = utilsLocalStorageApi.loadItem("
|
|
24
|
+
const orgTimezone = utilsLocalStorageApi.loadItem("orgTZ") || "Asia/Kolkata";
|
|
25
25
|
|
|
26
26
|
// Epoch (number or numeric string)
|
|
27
27
|
if (typeof date === "number" || (typeof date === "string" && /^\d+$/.test(date))) {
|
|
@@ -53,26 +53,26 @@ export const formatDateWithTimezone = (date, orgTZ = false) => {
|
|
|
53
53
|
* Returns a tooltip string with the timezone and offset for a given date.
|
|
54
54
|
*
|
|
55
55
|
* - Epoch input:
|
|
56
|
-
* - Always uses
|
|
56
|
+
* - Always uses orgTZ
|
|
57
57
|
* - ISO input:
|
|
58
58
|
* - orgTZ=false → keep ISO timezone info
|
|
59
|
-
* - orgTZ=true → convert to org timezone (
|
|
59
|
+
* - orgTZ=true → convert to org timezone (orgTZ)
|
|
60
60
|
*
|
|
61
61
|
* @param {string|number|Date} date - ISO string, epoch (sec/ms), or Date object.
|
|
62
62
|
* @param {boolean} orgTZ - Whether to force conversion into org timezone.
|
|
63
63
|
* @returns {string} Tooltip string with timezone and offset.
|
|
64
64
|
*/
|
|
65
65
|
export const getTimezoneTooltip = (date, orgTZ = false) => {
|
|
66
|
-
const
|
|
66
|
+
const orgTimezone = utilsLocalStorageApi.loadItem("orgTZ") || "Asia/Kolkata";
|
|
67
67
|
|
|
68
68
|
// Case 1: Epoch number or numeric string
|
|
69
69
|
if (typeof date === "number" || (typeof date === "string" && /^\d+$/.test(date))) {
|
|
70
|
-
return `Timezone: ${
|
|
70
|
+
return `Timezone: ${orgTimezone} (UTC${moment.tz(orgTimezone).format("Z")})`;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
// Case 2: orgTZ = true → always use
|
|
73
|
+
// Case 2: orgTZ = true → always use orgTZ
|
|
74
74
|
if (orgTZ) {
|
|
75
|
-
return `Timezone: ${
|
|
75
|
+
return `Timezone: ${orgTimezone} (UTC${moment.tz(orgTimezone).format("Z")})`;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// Case 3: Try parsing ISO or custom string
|
|
@@ -82,10 +82,10 @@ export const getTimezoneTooltip = (date, orgTZ = false) => {
|
|
|
82
82
|
m = moment.tz(date, "DD MMM YYYY h:mm A z");
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
// If still invalid → fallback to
|
|
85
|
+
// If still invalid → fallback to orgTZ
|
|
86
86
|
if (!m.isValid()) {
|
|
87
|
-
return `Timezone: ${
|
|
87
|
+
return `Timezone: ${orgTimezone} (UTC${moment.tz(orgTimezone).format("Z")})`;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
return `Timezone: ${m.tz() ||
|
|
90
|
+
return `Timezone: ${m.tz() || orgTimezone} (UTC${m.format("Z")})`;
|
|
91
91
|
};
|