@molopos/shared 2.0.58 → 2.0.61
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/index.js +28 -13
- package/date/index.test.js +8 -8
- package/package.json +1 -1
package/date/index.js
CHANGED
|
@@ -170,24 +170,39 @@ const recurrenceDate = ({ date, recurrence, duration = 1, isRecurrence = false,
|
|
|
170
170
|
const dateNowUnix = (0, exports.dateTimeNowUtcUnixInteger)();
|
|
171
171
|
const dateUnix = (0, exports.formateDateUnixInteger)(date);
|
|
172
172
|
const isFutureDate = dateUnix > dateNowUnix;
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
? isFutureDate
|
|
177
|
-
? luxon_1.DateTime.fromJSDate(date)
|
|
178
|
-
: luxon_1.DateTime.fromJSDate((0, exports.dateTimeNowUtc)()).set({ day: date.getDate() })
|
|
179
|
-
: isFutureDate
|
|
180
|
-
? luxon_1.DateTime.fromJSDate(date)
|
|
181
|
-
: luxon_1.DateTime.fromJSDate((0, exports.dateTimeNowUtc)());
|
|
173
|
+
const dateNowInit = isFutureDate
|
|
174
|
+
? luxon_1.DateTime.fromJSDate(date)
|
|
175
|
+
: luxon_1.DateTime.fromJSDate((0, exports.dateTimeNowUtc)());
|
|
182
176
|
switch (recurrence) {
|
|
183
177
|
case enum_1.RecurrenceEnum.Daily:
|
|
184
178
|
return dateNowInit.plus({ days: duration }).toJSDate();
|
|
185
179
|
case enum_1.RecurrenceEnum.Weekly:
|
|
186
180
|
return dateNowInit.plus({ weeks: duration }).toJSDate();
|
|
187
|
-
case enum_1.RecurrenceEnum.Monthly:
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
181
|
+
case enum_1.RecurrenceEnum.Monthly: {
|
|
182
|
+
if (isFutureDate) {
|
|
183
|
+
return dateNowInit.plus({ months: duration }).toJSDate();
|
|
184
|
+
}
|
|
185
|
+
const now = luxon_1.DateTime.fromJSDate((0, exports.dateTimeNowUtc)());
|
|
186
|
+
let nextOccurrence = now.set({ day: date.getDate() });
|
|
187
|
+
if (nextOccurrence.toUnixInteger() <= dateNowUnix) {
|
|
188
|
+
nextOccurrence = nextOccurrence.plus({ months: duration });
|
|
189
|
+
}
|
|
190
|
+
return nextOccurrence.toJSDate();
|
|
191
|
+
}
|
|
192
|
+
case enum_1.RecurrenceEnum.Yearly: {
|
|
193
|
+
if (isFutureDate) {
|
|
194
|
+
return dateNowInit.plus({ years: duration }).toJSDate();
|
|
195
|
+
}
|
|
196
|
+
const now = luxon_1.DateTime.fromJSDate((0, exports.dateTimeNowUtc)());
|
|
197
|
+
let nextOccurrence = now.set({
|
|
198
|
+
month: date.getMonth() + 1,
|
|
199
|
+
day: date.getDate(),
|
|
200
|
+
});
|
|
201
|
+
if (nextOccurrence.toUnixInteger() <= dateNowUnix) {
|
|
202
|
+
nextOccurrence = nextOccurrence.plus({ years: duration });
|
|
203
|
+
}
|
|
204
|
+
return nextOccurrence.toJSDate();
|
|
205
|
+
}
|
|
191
206
|
}
|
|
192
207
|
};
|
|
193
208
|
exports.recurrenceDate = recurrenceDate;
|
package/date/index.test.js
CHANGED
|
@@ -3,28 +3,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const _1 = require(".");
|
|
4
4
|
const enum_1 = require("../enum");
|
|
5
5
|
describe("Date", () => {
|
|
6
|
-
|
|
6
|
+
it("dateTimeNowUtc", () => {
|
|
7
7
|
const dateNow = (0, _1.dateTimeNowUtc)();
|
|
8
8
|
expect(dateNow).not.toBeNull();
|
|
9
9
|
expect(dateNow).toBeDefined();
|
|
10
10
|
});
|
|
11
|
-
|
|
11
|
+
it("dateTimeNowUtcUnixInteger", () => {
|
|
12
12
|
const dateNow = (0, _1.dateTimeNowUtcUnixInteger)();
|
|
13
13
|
expect(dateNow).not.toBeNull();
|
|
14
14
|
expect(dateNow).toBeDefined();
|
|
15
15
|
});
|
|
16
|
-
|
|
16
|
+
it("formateDateUnixInteger", () => {
|
|
17
17
|
const dateNow = (0, _1.formateDateUnixInteger)(new Date());
|
|
18
18
|
expect(dateNow).not.toBeNull();
|
|
19
19
|
expect(dateNow).toBeDefined();
|
|
20
20
|
});
|
|
21
|
-
|
|
21
|
+
it("subtractDaysToDateTimeNowUtc", () => {
|
|
22
22
|
const dateNow = (0, _1.subtractDaysToDateTimeNowUtc)(1);
|
|
23
23
|
expect(dateNow).not.toBeNull();
|
|
24
24
|
expect(dateNow).toBeDefined();
|
|
25
25
|
});
|
|
26
|
-
|
|
27
|
-
const dateNow = (
|
|
26
|
+
it("recurrenceDate isRecurrence = true", () => {
|
|
27
|
+
const dateNow = new Date("2025-07-09 00:00:00+00");
|
|
28
28
|
const dateNextMonth = (0, _1.recurrenceDate)({
|
|
29
29
|
date: dateNow,
|
|
30
30
|
isRecurrence: true,
|
|
@@ -54,8 +54,8 @@ describe("Date", () => {
|
|
|
54
54
|
expect(dateNextMonth).toBeDefined();
|
|
55
55
|
expect(dateNextWeek).toBeDefined();
|
|
56
56
|
});
|
|
57
|
-
|
|
58
|
-
const dateNow = (
|
|
57
|
+
it("recurrenceDate isRecurrence = false", () => {
|
|
58
|
+
const dateNow = new Date("2025-07-10 00:00:00+00");
|
|
59
59
|
const dateNextMonth = (0, _1.recurrenceDate)({
|
|
60
60
|
date: dateNow,
|
|
61
61
|
isRecurrence: false,
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@molopos/shared","publishConfig":{"access":"public"},"version":"2.0.
|
|
1
|
+
{"name":"@molopos/shared","publishConfig":{"access":"public"},"version":"2.0.61","description":"Shared between backend and frontend repos","license":"ISC","repository":{"type":"git","url":"https://github.com/unicubate/molopos-shared.git"},"dependencies":{"class-transformer":"^0.5.1","date-fns":"^4.4.0","luxon":"^3.7.2"}}
|