@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,4 +1,6 @@
1
+ import durationPlugin from "dayjs/plugin/duration";
1
2
  export declare const getDateTimeDiff: (fromDate: string, toDate?: string) => {
3
+ duration: durationPlugin.Duration;
2
4
  years: () => number;
3
5
  months: () => number;
4
6
  days: () => number;
@@ -1 +1 @@
1
- {"version":3,"file":"getDateTimeDiff.d.ts","sourceRoot":"","sources":["../../../src/getDateTimeDiff/getDateTimeDiff.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,eAAe,aAAc,MAAM,WAAW,MAAM;;;;;;;CAqChE,CAAC"}
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 date format");
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 ? dayjs.utc(toDate) : start.endOf("month").endOf("day");
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 date format");
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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mysetup/helpers",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "files": [