@capillarytech/cap-ui-utils 3.0.7-alpha.7 → 3.0.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 +32 -26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capillarytech/cap-ui-utils",
3
- "version": "3.0.7-alpha.7",
3
+ "version": "3.0.8",
4
4
  "description": "Utility functions shared accross all the modules",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/utils/timezone.js CHANGED
@@ -18,38 +18,44 @@ export const DATE_FORMAT = "DD MMM YYYY h:mm A";
18
18
  * @returns {string} Formatted date string with strict TZ abbreviation or '-'.
19
19
  */
20
20
  export const formatDateWithTimezone = (date, orgTZ = false) => {
21
- if (!date) return "-";
21
+ try{
22
+ if (!date) return "-";
22
23
 
23
- let momentDate;
24
- const orgTimezone = utilsLocalStorageApi.loadItem("orgTZ") || "Asia/Kolkata";
24
+ let momentDate;
25
+ const orgTimezone = utilsLocalStorageApi.loadItem("orgTZ") || "Asia/Kolkata";
25
26
 
26
- // Epoch (number or numeric string)
27
- if (typeof date === "number" || (typeof date === "string" && /^\d+$/.test(date))) {
28
- const timestamp = typeof date === "string" ? parseInt(date, 10) : date;
29
- const timestampMs = timestamp < 1e12 ? timestamp * 1000 : timestamp;
30
- momentDate = moment.tz(timestampMs, orgTimezone);
31
- }
32
- // ISO string or Date object
33
- else {
34
- momentDate = moment(date);
35
- if (orgTZ) {
36
- momentDate = momentDate.tz(orgTimezone);
27
+ // Epoch (number or numeric string)
28
+ if (typeof date === "number" || (typeof date === "string" && /^\d+$/.test(date))) {
29
+ const timestamp = typeof date === "string" ? parseInt(date, 10) : date;
30
+ const timestampMs = timestamp < 1e12 ? timestamp * 1000 : timestamp;
31
+ momentDate = moment.tz(timestampMs, orgTimezone);
32
+ }
33
+ // ISO string or Date object
34
+ else {
35
+ momentDate = moment(date);
36
+ if(momentDate.isUTC() || orgTZ){
37
+ momentDate = momentDate.tz(orgTimezone);
38
+ }
37
39
  }
38
- }
39
40
 
40
- if (!momentDate.isValid()) return "-";
41
+ if (!momentDate.isValid()) return "-";
41
42
 
42
- // Get strict timezone abbreviation (no offsets like GMT+05:30)
43
- let tzAbbr;
44
- if (momentDate.isValid()) {
45
- const tz = momentDate.tz() || orgTimezone;
46
- tzAbbr = moment.tz.zone(tz)?.abbr(momentDate.valueOf()) || "UTC";
47
- } else {
48
- tzAbbr = "UTC"; // fallback
49
- }
43
+ // Get strict timezone abbreviation (no offsets like GMT+05:30)
44
+ let tzAbbr;
45
+ if (momentDate.isValid()) {
46
+ const tz = momentDate.tz() || orgTimezone;
47
+ tzAbbr = moment.tz.zone(tz)?.abbr(momentDate.valueOf()) || "UTC";
48
+ } else {
49
+ tzAbbr = "UTC"; // fallback
50
+ }
50
51
 
51
- return `${momentDate.format(DATE_FORMAT)} ${tzAbbr}`;
52
- }
52
+ return `${momentDate.format(DATE_FORMAT)} ${tzAbbr}`;
53
+ }
54
+ catch(error){
55
+ console.error(error);
56
+ return "-";
57
+ }
58
+ };
53
59
 
54
60
  /**
55
61
  * Returns a tooltip string with the timezone and offset for a given date.