@capillarytech/cap-ui-utils 3.0.7-alpha.2 → 3.0.7-alpha.4

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 +24 -27
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capillarytech/cap-ui-utils",
3
- "version": "3.0.7-alpha.2",
3
+ "version": "3.0.7-alpha.4",
4
4
  "description": "Utility functions shared accross all the modules",
5
5
  "main": "index.js",
6
6
  "scripts": {
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 (serverTZ)
12
+ * - orgTZ=true → convert to org timezone
13
13
  * - Epoch input:
14
- * - Always converts to org timezone (serverTZ)
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("serverTZ") || "Asia/Kolkata";
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,39 +53,36 @@ 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 serverTZ
56
+ * - Always uses orgTZ
57
57
  * - ISO input:
58
58
  * - orgTZ=false → keep ISO timezone info
59
- * - orgTZ=true → convert to org timezone (serverTZ)
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 serverTZ = utilsLocalStorageApi.loadItem("serverTZ") || "Asia/Kolkata";
66
+ const orgTimezone = utilsLocalStorageApi.loadItem("orgTZ") || "Asia/Kolkata";
67
67
 
68
- // Case 1: Epoch number or numeric string
69
- if (typeof date === "number" || (typeof date === "string" && /^\d+$/.test(date))) {
70
- return `Timezone: ${serverTZ} (UTC${moment.tz(serverTZ).format("Z")})`;
71
- }
72
-
73
- // Case 2: orgTZ = true → always use serverTZ
74
- if (orgTZ) {
75
- return `Timezone: ${serverTZ} (UTC${moment.tz(serverTZ).format("Z")})`;
76
- }
77
-
78
- // Case 3: Try parsing ISO or custom string
79
- let m = moment.parseZone(date); // handles ISO strings like 2025-08-12T23:59:59.000Z
80
-
81
- if (!m.isValid()) {
82
- m = moment.tz(date, "DD MMM YYYY h:mm A z");
68
+ if(orgTZ){
69
+ return `Timezone: ${orgTimezone} (UTC${moment.tz(orgTimezone).format("Z")})`;
83
70
  }
84
-
85
- // If still invalid fallback to serverTZ
86
- if (!m.isValid()) {
87
- return `Timezone: ${serverTZ} (UTC${moment.tz(serverTZ).format("Z")})`;
71
+ else{
72
+ // case 1: epoch number or numeric string
73
+ if(typeof date === "number" || (typeof date === "string" && /^\d+$/.test(date))){
74
+ return `Timezone: ${orgTimezone} (UTC${moment.tz(orgTimezone).format("Z")})`;
75
+ }
76
+ // case 2: ISO string or Date object
77
+ else{
78
+ let m = moment.parseZone(date); // handles ISO strings like 2025-08-12T23:59:59.000Z or 2025-08-12T23:59:59+05:30
79
+ if(!m.isValid()){
80
+ m = moment.tz(date, "DD MMM YYYY h:mm A z"); // handles strings like 17 Sep 2025 6:00 AM EDT
81
+ }
82
+ if(!m.isValid()){
83
+ return `Timezone: ${orgTimezone} (UTC${moment.tz(orgTimezone).format("Z")})`; // fallback to orgTZ
84
+ }
85
+ return `Timezone: ${m.tz() || orgTimezone} (UTC${m.format("Z")})`; // return the timezone and offset
86
+ }
88
87
  }
89
-
90
- return `Timezone: ${m.tz() || serverTZ} (UTC${m.format("Z")})`;
91
88
  };