@mysetup/helpers 1.4.0 → 1.6.0
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDateTimeDiff.d.ts","sourceRoot":"","sources":["../../../src/getDateTimeDiff/getDateTimeDiff.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getDateTimeDiff.d.ts","sourceRoot":"","sources":["../../../src/getDateTimeDiff/getDateTimeDiff.ts"],"names":[],"mappings":"AACA,OAAO,cAAc,MAAM,uBAAuB,CAAC;AAMnD,eAAO,MAAM,eAAe,aAAc,MAAM,WAAW,MAAM;;;;;;;;CAqChE,CAAC"}
|
|
@@ -5,15 +5,14 @@ dayjs.extend(durationPlugin);
|
|
|
5
5
|
dayjs.extend(utc);
|
|
6
6
|
export const getDateTimeDiff = (fromDate, toDate) => {
|
|
7
7
|
if (!fromDate || fromDate.trim() === "") {
|
|
8
|
-
throw new Error("Invalid
|
|
9
|
-
}
|
|
10
|
-
if (toDate !== undefined && toDate.trim() === "") {
|
|
11
|
-
throw new Error("Invalid date format");
|
|
8
|
+
throw new Error("Invalid Input");
|
|
12
9
|
}
|
|
13
10
|
const start = dayjs.utc(fromDate);
|
|
14
|
-
const end = toDate
|
|
11
|
+
const end = toDate
|
|
12
|
+
? dayjs.utc(toDate)
|
|
13
|
+
: dayjs().endOf("day").endOf("hour").endOf("minute").utc();
|
|
15
14
|
if (!start.isValid() || !end.isValid()) {
|
|
16
|
-
throw new Error("Invalid
|
|
15
|
+
throw new Error("Invalid Date");
|
|
17
16
|
}
|
|
18
17
|
const diffInMilliseconds = end.diff(start);
|
|
19
18
|
if (diffInMilliseconds < 0) {
|
|
@@ -26,6 +25,7 @@ export const getDateTimeDiff = (fromDate, toDate) => {
|
|
|
26
25
|
const remainingHours = duration.subtract(totalDays, "days").hours();
|
|
27
26
|
const remainingMinutes = duration.subtract(totalDays, "days").minutes();
|
|
28
27
|
return {
|
|
28
|
+
duration,
|
|
29
29
|
years: () => totalYears,
|
|
30
30
|
months: () => totalMonths,
|
|
31
31
|
days: () => totalDays,
|