@8ms/helpers 2.0.22 → 2.0.24
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/.yarn/install-state.gz +0 -0
- package/date/calculation.d.ts +4 -0
- package/date/calculation.js +22 -4
- package/package.json +1 -1
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
package/date/calculation.d.ts
CHANGED
|
@@ -36,6 +36,10 @@ export declare const differenceInBusinessDays: (start: InputDate, end: InputDate
|
|
|
36
36
|
* https://www.gov.uk/when-do-the-clocks-change
|
|
37
37
|
*/
|
|
38
38
|
export declare const getDatesBetween: (start: InputDate, end: InputDate) => DateTime<true>[];
|
|
39
|
+
/**
|
|
40
|
+
* Get an array of DateTime objects representing the 1st of each month between start and end dates.
|
|
41
|
+
*/
|
|
42
|
+
export declare const getMonthsBetween: (start: InputDate, end: InputDate) => DateTime<boolean>[];
|
|
39
43
|
/**
|
|
40
44
|
* If a given date is beyond the maximum, return the maximum.
|
|
41
45
|
*/
|
package/date/calculation.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isLastWeek = exports.isThisWeek = exports.getYesterday = exports.getWeeksAgo = exports.getToday = exports.getTwoWeeksAgo = exports.getThisWeek = exports.getLastWeek = exports.getSunday = exports.getMonday = exports.getMin = exports.getMax = exports.getDatesBetween = exports.differenceInBusinessDays = exports.differenceInMinutes = exports.isWeekend = exports.isSunday = exports.isSaturday = exports.isFriday = exports.isThursday = exports.isWednesday = exports.isTuesday = exports.isMonday = exports.getDate = exports.getUnix = void 0;
|
|
3
|
+
exports.isLastWeek = exports.isThisWeek = exports.getYesterday = exports.getWeeksAgo = exports.getToday = exports.getTwoWeeksAgo = exports.getThisWeek = exports.getLastWeek = exports.getSunday = exports.getMonday = exports.getMin = exports.getMax = exports.getMonthsBetween = exports.getDatesBetween = exports.differenceInBusinessDays = exports.differenceInMinutes = exports.isWeekend = exports.isSunday = exports.isSaturday = exports.isFriday = exports.isThursday = exports.isWednesday = exports.isTuesday = exports.isMonday = exports.getDate = exports.getUnix = void 0;
|
|
4
4
|
const luxon_1 = require("luxon");
|
|
5
5
|
const getUnix = (input) => {
|
|
6
6
|
return (0, exports.getDate)(input)
|
|
@@ -13,10 +13,11 @@ exports.getUnix = getUnix;
|
|
|
13
13
|
* If it's not UTC, it needs to be converted to UTC before being used.
|
|
14
14
|
*/
|
|
15
15
|
const getDate = (input, setMidnight) => {
|
|
16
|
-
let instance = luxon_1.DateTime.now()
|
|
16
|
+
let instance = luxon_1.DateTime.now()
|
|
17
|
+
.toUTC();
|
|
17
18
|
if (input) {
|
|
18
19
|
if (input instanceof Date) {
|
|
19
|
-
instance = luxon_1.DateTime.fromJSDate(input, { zone:
|
|
20
|
+
instance = luxon_1.DateTime.fromJSDate(input, { zone: "utc" });
|
|
20
21
|
}
|
|
21
22
|
else if (input instanceof luxon_1.DateTime) {
|
|
22
23
|
instance = input.toUTC();
|
|
@@ -29,7 +30,7 @@ const getDate = (input, setMidnight) => {
|
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
// Ensure the instance is in UTC timezone
|
|
32
|
-
instance = instance.setZone(
|
|
33
|
+
instance = instance.setZone("utc", { keepLocalTime: false });
|
|
33
34
|
if (setMidnight) {
|
|
34
35
|
instance = instance.set({
|
|
35
36
|
hour: 0,
|
|
@@ -129,6 +130,23 @@ const getDatesBetween = (start, end) => {
|
|
|
129
130
|
return response;
|
|
130
131
|
};
|
|
131
132
|
exports.getDatesBetween = getDatesBetween;
|
|
133
|
+
/**
|
|
134
|
+
* Get an array of DateTime objects representing the 1st of each month between start and end dates.
|
|
135
|
+
*/
|
|
136
|
+
const getMonthsBetween = (start, end) => {
|
|
137
|
+
const months = [];
|
|
138
|
+
const endDate = (0, exports.getDate)(end)
|
|
139
|
+
.startOf("month");
|
|
140
|
+
// Start from the 1st of the month containing startDate
|
|
141
|
+
let current = (0, exports.getDate)(start).startOf("month");
|
|
142
|
+
while (current <= endDate) {
|
|
143
|
+
months.push(current);
|
|
144
|
+
// Move to next month
|
|
145
|
+
current = current.plus({ months: 1 });
|
|
146
|
+
}
|
|
147
|
+
return months;
|
|
148
|
+
};
|
|
149
|
+
exports.getMonthsBetween = getMonthsBetween;
|
|
132
150
|
/**
|
|
133
151
|
* If a given date is beyond the maximum, return the maximum.
|
|
134
152
|
*/
|