@molopos/shared 2.1.4 → 2.1.6
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.d.ts +51 -1
- package/date/index.js +66 -5
- package/package.json +1 -1
package/date/index.d.ts
CHANGED
|
@@ -27,6 +27,11 @@ export declare const formateddMMYYYYHHmm: (date: DateLike, locale: string) => st
|
|
|
27
27
|
* formateHHmm("2026-01-01", "en-US"); // "00:00"
|
|
28
28
|
*/
|
|
29
29
|
export declare const formateHHmm: (date: Date, locale: string) => string;
|
|
30
|
+
/**
|
|
31
|
+
* @example
|
|
32
|
+
* formateHH("2026-01-01"); // "00:00"
|
|
33
|
+
*/
|
|
34
|
+
export declare const formateHH: (date: Date) => string;
|
|
30
35
|
/**
|
|
31
36
|
* @example
|
|
32
37
|
* formatDateDDMMYYToUtc("2026-01-01", "en"); // "01/01/2026"
|
|
@@ -42,6 +47,11 @@ export declare const formatDateFnsToDdMMYYYY: (date: Date) => string;
|
|
|
42
47
|
* formatDateFnsToDdMMYYYYHHmmss("2026-01-01"); // "01-01-2026 00:00:00"
|
|
43
48
|
*/
|
|
44
49
|
export declare const formatDateFnsToDdMMYYYYHHmm: (date: Date) => string;
|
|
50
|
+
/**
|
|
51
|
+
* @example
|
|
52
|
+
* formateDateMMyyyy("2026-01-01"); // "012026"
|
|
53
|
+
*/
|
|
54
|
+
export declare const formateDateMMyyyy: (date: Date) => string;
|
|
45
55
|
/**
|
|
46
56
|
* @example
|
|
47
57
|
* formateToyyyy("2026-01-01"); // 2026
|
|
@@ -51,7 +61,7 @@ export declare const formateToyyyy: (date: Date) => number;
|
|
|
51
61
|
* @example
|
|
52
62
|
* addDaysToTimeNowUtcDate(1); // 2026-01-02
|
|
53
63
|
*/
|
|
54
|
-
export declare const addDaysToTimeNowUtcDate: (
|
|
64
|
+
export declare const addDaysToTimeNowUtcDate: (value: number) => Date;
|
|
55
65
|
/**
|
|
56
66
|
*
|
|
57
67
|
* @example
|
|
@@ -63,6 +73,46 @@ export declare const dateTimeNowUtcUnixInteger: () => number;
|
|
|
63
73
|
* formateDateUnixInteger("2026-01-01"); // 1719168000
|
|
64
74
|
*/
|
|
65
75
|
export declare const formateDateUnixInteger: (date: Date) => number;
|
|
76
|
+
/**
|
|
77
|
+
* @example
|
|
78
|
+
* addMonthsToTimeNowUtcDate(1); // 1719168000
|
|
79
|
+
*/
|
|
80
|
+
export declare const addMonthsToTimeNowUtcUnixInteger: (month: number) => number;
|
|
81
|
+
/**
|
|
82
|
+
* @example
|
|
83
|
+
* addDaysToTimeNowUtcUnixInteger(1); // 1719168000
|
|
84
|
+
*/
|
|
85
|
+
export declare const addDaysToTimeNowUtcUnixInteger: (value: number) => number;
|
|
86
|
+
/**
|
|
87
|
+
* @example
|
|
88
|
+
* addMonthsToTimeDateNowUtc(1); // 2026-01-02
|
|
89
|
+
*/
|
|
90
|
+
export declare const addMonthsToTimeDateNowUtc: (value: number) => Date;
|
|
91
|
+
/**
|
|
92
|
+
* @example
|
|
93
|
+
* addDaysToTimeDateNowUtc(1); // 2026-01-02
|
|
94
|
+
*/
|
|
95
|
+
export declare const addDaysToTimeDateNowUtc: (value: number) => Date;
|
|
96
|
+
/**
|
|
97
|
+
* @example
|
|
98
|
+
* addDaysToTimeDateStartOfDayNowUtc(1); // 2026-01-02 00:00:00
|
|
99
|
+
*/
|
|
100
|
+
export declare const addDaysToTimeDateStartOfDayNowUtc: (value: number) => Date;
|
|
101
|
+
/**
|
|
102
|
+
* @example
|
|
103
|
+
* addMonthsToTimeDate(new Date(), 1); // 2026-01-02
|
|
104
|
+
*/
|
|
105
|
+
export declare const addMonthsToTimeDate: (date: Date, value: number) => Date;
|
|
106
|
+
/**
|
|
107
|
+
* @example
|
|
108
|
+
* addDaysToTimeDate(new Date(), 1); // 2026-01-02
|
|
109
|
+
*/
|
|
110
|
+
export declare const addDaysToTimeDate: (date: Date, value: number) => Date;
|
|
111
|
+
/**
|
|
112
|
+
* @example
|
|
113
|
+
* substrateDaysToTimeDateNowUtc(1); // 2026-01-02
|
|
114
|
+
*/
|
|
115
|
+
export declare const substrateDaysToTimeDateNowUtc: (value: number) => Date;
|
|
66
116
|
/**
|
|
67
117
|
* @example
|
|
68
118
|
* recurrenceDate({ date: new Date(), recurrence: RecurrenceEnum.Monthly }) // 23/06/2026
|
package/date/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.recurrenceDate = exports.formateDateUnixInteger = exports.dateTimeNowUtcUnixInteger = exports.addDaysToTimeNowUtcDate = exports.formateToyyyy = exports.formatDateFnsToDdMMYYYYHHmm = exports.formatDateFnsToDdMMYYYY = exports.formatDateDDMMYYToUtc = exports.formateHHmm = exports.formateddMMYYYYHHmm = exports.formateddMMYYYY = exports.formateDate = exports.dateTimeNowUtc = void 0;
|
|
3
|
+
exports.recurrenceDate = exports.substrateDaysToTimeDateNowUtc = exports.addDaysToTimeDate = exports.addMonthsToTimeDate = exports.addDaysToTimeDateStartOfDayNowUtc = exports.addDaysToTimeDateNowUtc = exports.addMonthsToTimeDateNowUtc = exports.addDaysToTimeNowUtcUnixInteger = exports.addMonthsToTimeNowUtcUnixInteger = exports.formateDateUnixInteger = exports.dateTimeNowUtcUnixInteger = exports.addDaysToTimeNowUtcDate = exports.formateToyyyy = exports.formateDateMMyyyy = exports.formatDateFnsToDdMMYYYYHHmm = exports.formatDateFnsToDdMMYYYY = exports.formatDateDDMMYYToUtc = exports.formateHH = exports.formateHHmm = exports.formateddMMYYYYHHmm = exports.formateddMMYYYY = exports.formateDate = exports.dateTimeNowUtc = void 0;
|
|
4
4
|
const date_fns_1 = require("date-fns");
|
|
5
|
+
const utc_1 = require("@date-fns/utc");
|
|
5
6
|
const locale_1 = require("date-fns/locale");
|
|
6
7
|
const enum_1 = require("../enum");
|
|
7
8
|
const dataFnsLocale = {
|
|
@@ -58,6 +59,12 @@ exports.formateddMMYYYYHHmm = formateddMMYYYYHHmm;
|
|
|
58
59
|
*/
|
|
59
60
|
const formateHHmm = (date, locale) => (0, date_fns_1.format)(date, "p", { locale: dataFnsLocale[locale] });
|
|
60
61
|
exports.formateHHmm = formateHHmm;
|
|
62
|
+
/**
|
|
63
|
+
* @example
|
|
64
|
+
* formateHH("2026-01-01"); // "00:00"
|
|
65
|
+
*/
|
|
66
|
+
const formateHH = (date) => (0, date_fns_1.format)(date, "HH");
|
|
67
|
+
exports.formateHH = formateHH;
|
|
61
68
|
/**
|
|
62
69
|
* @example
|
|
63
70
|
* formatDateDDMMYYToUtc("2026-01-01", "en"); // "01/01/2026"
|
|
@@ -76,6 +83,12 @@ exports.formatDateFnsToDdMMYYYY = formatDateFnsToDdMMYYYY;
|
|
|
76
83
|
*/
|
|
77
84
|
const formatDateFnsToDdMMYYYYHHmm = (date) => (0, date_fns_1.format)(date, "dd-MM-yyyy HH:mm");
|
|
78
85
|
exports.formatDateFnsToDdMMYYYYHHmm = formatDateFnsToDdMMYYYYHHmm;
|
|
86
|
+
/**
|
|
87
|
+
* @example
|
|
88
|
+
* formateDateMMyyyy("2026-01-01"); // "012026"
|
|
89
|
+
*/
|
|
90
|
+
const formateDateMMyyyy = (date) => (0, date_fns_1.format)(date, "MMyyyy");
|
|
91
|
+
exports.formateDateMMyyyy = formateDateMMyyyy;
|
|
79
92
|
/**
|
|
80
93
|
* @example
|
|
81
94
|
* formateToyyyy("2026-01-01"); // 2026
|
|
@@ -86,7 +99,7 @@ exports.formateToyyyy = formateToyyyy;
|
|
|
86
99
|
* @example
|
|
87
100
|
* addDaysToTimeNowUtcDate(1); // 2026-01-02
|
|
88
101
|
*/
|
|
89
|
-
const addDaysToTimeNowUtcDate = (
|
|
102
|
+
const addDaysToTimeNowUtcDate = (value) => (0, date_fns_1.addDays)((0, exports.dateTimeNowUtc)(), value);
|
|
90
103
|
exports.addDaysToTimeNowUtcDate = addDaysToTimeNowUtcDate;
|
|
91
104
|
/**
|
|
92
105
|
*
|
|
@@ -101,6 +114,54 @@ exports.dateTimeNowUtcUnixInteger = dateTimeNowUtcUnixInteger;
|
|
|
101
114
|
*/
|
|
102
115
|
const formateDateUnixInteger = (date) => Number((0, date_fns_1.format)(date, "T"));
|
|
103
116
|
exports.formateDateUnixInteger = formateDateUnixInteger;
|
|
117
|
+
/**
|
|
118
|
+
* @example
|
|
119
|
+
* addMonthsToTimeNowUtcDate(1); // 1719168000
|
|
120
|
+
*/
|
|
121
|
+
const addMonthsToTimeNowUtcUnixInteger = (month) => Number((0, date_fns_1.format)((0, date_fns_1.addMonths)((0, exports.dateTimeNowUtc)(), month), "T"));
|
|
122
|
+
exports.addMonthsToTimeNowUtcUnixInteger = addMonthsToTimeNowUtcUnixInteger;
|
|
123
|
+
/**
|
|
124
|
+
* @example
|
|
125
|
+
* addDaysToTimeNowUtcUnixInteger(1); // 1719168000
|
|
126
|
+
*/
|
|
127
|
+
const addDaysToTimeNowUtcUnixInteger = (value) => Number((0, date_fns_1.format)((0, date_fns_1.addDays)((0, exports.dateTimeNowUtc)(), value), "T"));
|
|
128
|
+
exports.addDaysToTimeNowUtcUnixInteger = addDaysToTimeNowUtcUnixInteger;
|
|
129
|
+
/**
|
|
130
|
+
* @example
|
|
131
|
+
* addMonthsToTimeDateNowUtc(1); // 2026-01-02
|
|
132
|
+
*/
|
|
133
|
+
const addMonthsToTimeDateNowUtc = (value) => (0, date_fns_1.addMonths)((0, exports.dateTimeNowUtc)(), value);
|
|
134
|
+
exports.addMonthsToTimeDateNowUtc = addMonthsToTimeDateNowUtc;
|
|
135
|
+
/**
|
|
136
|
+
* @example
|
|
137
|
+
* addDaysToTimeDateNowUtc(1); // 2026-01-02
|
|
138
|
+
*/
|
|
139
|
+
const addDaysToTimeDateNowUtc = (value) => (0, date_fns_1.addDays)((0, exports.dateTimeNowUtc)(), value);
|
|
140
|
+
exports.addDaysToTimeDateNowUtc = addDaysToTimeDateNowUtc;
|
|
141
|
+
/**
|
|
142
|
+
* @example
|
|
143
|
+
* addDaysToTimeDateStartOfDayNowUtc(1); // 2026-01-02 00:00:00
|
|
144
|
+
*/
|
|
145
|
+
const addDaysToTimeDateStartOfDayNowUtc = (value) => new Date((0, date_fns_1.startOfDay)((0, date_fns_1.addDays)(new utc_1.UTCDate((0, exports.dateTimeNowUtc)()), value)));
|
|
146
|
+
exports.addDaysToTimeDateStartOfDayNowUtc = addDaysToTimeDateStartOfDayNowUtc;
|
|
147
|
+
/**
|
|
148
|
+
* @example
|
|
149
|
+
* addMonthsToTimeDate(new Date(), 1); // 2026-01-02
|
|
150
|
+
*/
|
|
151
|
+
const addMonthsToTimeDate = (date, value) => (0, date_fns_1.addMonths)(date, value);
|
|
152
|
+
exports.addMonthsToTimeDate = addMonthsToTimeDate;
|
|
153
|
+
/**
|
|
154
|
+
* @example
|
|
155
|
+
* addDaysToTimeDate(new Date(), 1); // 2026-01-02
|
|
156
|
+
*/
|
|
157
|
+
const addDaysToTimeDate = (date, value) => (0, date_fns_1.addDays)(date, value);
|
|
158
|
+
exports.addDaysToTimeDate = addDaysToTimeDate;
|
|
159
|
+
/**
|
|
160
|
+
* @example
|
|
161
|
+
* substrateDaysToTimeDateNowUtc(1); // 2026-01-02
|
|
162
|
+
*/
|
|
163
|
+
const substrateDaysToTimeDateNowUtc = (value) => (0, date_fns_1.subDays)((0, exports.dateTimeNowUtc)(), value);
|
|
164
|
+
exports.substrateDaysToTimeDateNowUtc = substrateDaysToTimeDateNowUtc;
|
|
104
165
|
/**
|
|
105
166
|
* @example
|
|
106
167
|
* recurrenceDate({ date: new Date(), recurrence: RecurrenceEnum.Monthly }) // 23/06/2026
|
|
@@ -116,17 +177,17 @@ const recurrenceDate = ({ date, recurrence, duration = 1, isRecurrence = false,
|
|
|
116
177
|
const dateNowInit = isFutureDate ? dateInit : (0, exports.dateTimeNowUtc)();
|
|
117
178
|
switch (recurrence) {
|
|
118
179
|
case enum_1.RecurrenceEnum.Daily:
|
|
119
|
-
return (0,
|
|
180
|
+
return (0, exports.addDaysToTimeDate)(dateNowInit, duration);
|
|
120
181
|
case enum_1.RecurrenceEnum.Weekly:
|
|
121
182
|
return (0, date_fns_1.addWeeks)(dateNowInit, duration);
|
|
122
183
|
case enum_1.RecurrenceEnum.Monthly: {
|
|
123
184
|
if (isFutureDate) {
|
|
124
|
-
return (0,
|
|
185
|
+
return (0, exports.addMonthsToTimeDate)(dateNowInit, duration);
|
|
125
186
|
}
|
|
126
187
|
const now = (0, exports.dateTimeNowUtc)();
|
|
127
188
|
let nextOccurrence = (0, date_fns_1.setDate)(now, dateInit.getDate());
|
|
128
189
|
if ((0, exports.formateDateUnixInteger)(nextOccurrence) <= dateNowUnix) {
|
|
129
|
-
nextOccurrence = (0,
|
|
190
|
+
nextOccurrence = (0, exports.addMonthsToTimeDate)(nextOccurrence, duration);
|
|
130
191
|
}
|
|
131
192
|
return nextOccurrence;
|
|
132
193
|
}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@molopos/shared","publishConfig":{"access":"public"},"version":"2.1.
|
|
1
|
+
{"name":"@molopos/shared","publishConfig":{"access":"public"},"version":"2.1.6","description":"Shared between backend and frontend repos","license":"ISC","repository":{"type":"git","url":"https://github.com/unicubate/molopos-shared.git"},"dependencies":{"@date-fns/utc":"^2.1.1","class-transformer":"^0.5.1","date-fns":"^4.4.0"}}
|