@8ms/helpers 1.6.5 → 1.7.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.
- package/date/getMidnight.js +6 -1
- package/date/getMonday.js +15 -2
- package/package.json +1 -1
package/date/getMidnight.js
CHANGED
|
@@ -6,7 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const getMidnight = ({ input, setMidnight = true }) => {
|
|
7
7
|
let dateInstance = input;
|
|
8
8
|
if (setMidnight) {
|
|
9
|
-
|
|
9
|
+
if (0 === dateInstance.getTimezoneOffset()) {
|
|
10
|
+
dateInstance.setHours(0, 0, 0, 0);
|
|
11
|
+
}
|
|
12
|
+
else {
|
|
13
|
+
dateInstance.setHours(1, 0, 0, 0);
|
|
14
|
+
}
|
|
10
15
|
}
|
|
11
16
|
return dateInstance;
|
|
12
17
|
};
|
package/date/getMonday.js
CHANGED
|
@@ -7,6 +7,7 @@ const getISODay_1 = __importDefault(require("date-fns/getISODay"));
|
|
|
7
7
|
const isMonday_1 = __importDefault(require("date-fns/isMonday"));
|
|
8
8
|
const subDays_1 = __importDefault(require("date-fns/subDays"));
|
|
9
9
|
const getDate_1 = __importDefault(require("./getDate"));
|
|
10
|
+
const getMidnight_1 = __importDefault(require("./getMidnight"));
|
|
10
11
|
const getToday_1 = __importDefault(require("./getToday"));
|
|
11
12
|
/**
|
|
12
13
|
* Retrieve the closest last Monday relative to the input or today.
|
|
@@ -16,11 +17,18 @@ const getToday_1 = __importDefault(require("./getToday"));
|
|
|
16
17
|
const getMonday = ({ weeksAgo, input, setMidnight = true, setTimeZone = false }) => {
|
|
17
18
|
let dateInstance;
|
|
18
19
|
if (input) {
|
|
19
|
-
dateInstance = (0, getDate_1.default)({
|
|
20
|
+
dateInstance = (0, getDate_1.default)({
|
|
21
|
+
input,
|
|
22
|
+
setMidnight: false,
|
|
23
|
+
setTimeZone
|
|
24
|
+
});
|
|
20
25
|
}
|
|
21
26
|
else {
|
|
22
27
|
// As we are getting today's date we don't want to convert this timezone
|
|
23
|
-
dateInstance = (0, getToday_1.default)({
|
|
28
|
+
dateInstance = (0, getToday_1.default)({
|
|
29
|
+
setMidnight: false,
|
|
30
|
+
});
|
|
31
|
+
// console.log('dateInstance', dateInstance);
|
|
24
32
|
}
|
|
25
33
|
if (!(0, isMonday_1.default)(dateInstance)) {
|
|
26
34
|
// Get the ISO Day of week (Monday - 1 to Sunday - 7)
|
|
@@ -30,6 +38,11 @@ const getMonday = ({ weeksAgo, input, setMidnight = true, setTimeZone = false })
|
|
|
30
38
|
}
|
|
31
39
|
// Move it back a given number of weeks
|
|
32
40
|
dateInstance = (0, subDays_1.default)(dateInstance, 7 * weeksAgo);
|
|
41
|
+
// console.log('dateInstance', dateInstance);
|
|
42
|
+
dateInstance = (0, getMidnight_1.default)({
|
|
43
|
+
input: dateInstance,
|
|
44
|
+
setMidnight
|
|
45
|
+
});
|
|
33
46
|
return dateInstance;
|
|
34
47
|
};
|
|
35
48
|
exports.default = getMonday;
|