@capillarytech/cap-ui-utils 3.0.9-alpha.2 → 3.0.9-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 +32 -3
package/package.json
CHANGED
package/utils/timezone.js
CHANGED
|
@@ -12,8 +12,34 @@ const getTimezoneFormattedDate = (date,orgTZ = false,serverTZ = false,customTZ =
|
|
|
12
12
|
// If date is epoch (number or numeric string)
|
|
13
13
|
if (typeof date === "number" || (typeof date === "string" && /^\d+$/.test(date))) {
|
|
14
14
|
const timestamp = typeof date === "string" ? parseInt(date, 10) : date;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
// Handle zero and negative timestamps
|
|
16
|
+
if (timestamp === 0) {
|
|
17
|
+
momentDate = moment.utc(0).tz(targetTimezone);
|
|
18
|
+
} else if (timestamp < 0) {
|
|
19
|
+
momentDate = moment.utc(timestamp * 1000).tz(targetTimezone);
|
|
20
|
+
} else {
|
|
21
|
+
const timestampMs = timestamp < 1e12 ? timestamp * 1000 : timestamp;
|
|
22
|
+
momentDate = moment.utc(timestampMs).tz(targetTimezone);
|
|
23
|
+
}
|
|
24
|
+
} else if (typeof date === "string") {
|
|
25
|
+
// Try to parse formatted date string like "10 Oct 2025 4:00 PM IST"
|
|
26
|
+
const formattedDatePattern = /^\d{1,2}\s+\w{3}\s+\d{4}\s+\d{1,2}:\d{2}\s+[AP]M\s+\w+$/;
|
|
27
|
+
if (formattedDatePattern.test(date.trim())) {
|
|
28
|
+
// Extract timezone abbreviation from the string
|
|
29
|
+
const parts = date.trim().split(' ');
|
|
30
|
+
const dateWithoutTz = parts.slice(0, -1).join(' '); // Remove timezone part
|
|
31
|
+
|
|
32
|
+
// Parse the date part first
|
|
33
|
+
momentDate = moment(dateWithoutTz, "DD MMM YYYY h:mm A");
|
|
34
|
+
|
|
35
|
+
// If parsing was successful, convert to target timezone
|
|
36
|
+
if (momentDate.isValid()) {
|
|
37
|
+
momentDate = momentDate.tz(targetTimezone);
|
|
38
|
+
}
|
|
39
|
+
} else {
|
|
40
|
+
// Try standard ISO or other formats
|
|
41
|
+
momentDate = moment.tz(date, targetTimezone);
|
|
42
|
+
}
|
|
17
43
|
} else {
|
|
18
44
|
momentDate = moment.tz(date, targetTimezone);
|
|
19
45
|
}
|
|
@@ -78,10 +104,13 @@ export const formatDateWithTimezone = (date, orgTZ = false, serverTZ = false, cu
|
|
|
78
104
|
* - ISO input (e.g., "2025-01-09T00:00:00+05:30"):
|
|
79
105
|
* - Parses timezone offset correctly
|
|
80
106
|
* - Returns timezone info for that specific date/time
|
|
107
|
+
* - Formatted date string (e.g., "10 Oct 2025 4:00 PM IST"):
|
|
108
|
+
* - Parses formatted date with timezone abbreviation
|
|
109
|
+
* - Returns timezone info for that specific date/time
|
|
81
110
|
* - Date object:
|
|
82
111
|
* - Returns timezone info for that specific date/time
|
|
83
112
|
*
|
|
84
|
-
* @param {string|number|Date} date - Epoch timestamp, ISO string with timezone, or Date object.
|
|
113
|
+
* @param {string|number|Date} date - Epoch timestamp, ISO string with timezone, formatted date string, or Date object.
|
|
85
114
|
* @param {boolean} orgTZ - Whether to force conversion into organization timezone.
|
|
86
115
|
* @param {boolean} serverTZ - Whether to force conversion into server timezone.
|
|
87
116
|
* @param {string|null} customTZ - Custom timezone override (e.g., "Asia/Kolkata").
|