@molopos/shared 2.0.52 → 2.0.54
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 +15 -1
- package/date/index.js +36 -11
- package/package.json +1 -1
package/date/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ interface PropsRecurrence {
|
|
|
4
4
|
date: Date;
|
|
5
5
|
duration?: number;
|
|
6
6
|
recurrence: RecurrenceEnum;
|
|
7
|
+
isRecurrence?: boolean;
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
10
|
* Format a date to a string
|
|
@@ -62,9 +63,22 @@ export declare const formateToUnixIntegerddLLLyyyy: (date: Numberlike, locale: s
|
|
|
62
63
|
* formateTDate("2026-01-01", "en-US"); // "1 Jan 2026"
|
|
63
64
|
*/
|
|
64
65
|
export declare const formateTDate: (date: Date, lang: string) => string;
|
|
66
|
+
/**
|
|
67
|
+
*
|
|
68
|
+
* @returns The current date in Unix integer format
|
|
69
|
+
* @example 1719168000
|
|
70
|
+
*/
|
|
71
|
+
export declare const dateTimeNowUtcUnixInteger: () => number;
|
|
72
|
+
/**
|
|
73
|
+
* Format a date to a Unix integer
|
|
74
|
+
* @param date - The date to format (e.g. "2026-01-01", "2026-01-01T00:00:00.000Z", etc.)
|
|
75
|
+
* @returns The formatted date in Unix integer format
|
|
76
|
+
* @example 1719168000
|
|
77
|
+
*/
|
|
78
|
+
export declare const formateDateUnixInteger: (date: Date) => number;
|
|
65
79
|
/**
|
|
66
80
|
* @example
|
|
67
81
|
* recurrenceDate({ date: new Date(), recurrence: RecurrenceEnum.Monthly }) // 23/06/2026
|
|
68
82
|
*/
|
|
69
|
-
export declare const recurrenceDate: ({ date, recurrence, duration, }: PropsRecurrence) => Date;
|
|
83
|
+
export declare const recurrenceDate: ({ date, recurrence, duration, isRecurrence, }: PropsRecurrence) => Date;
|
|
70
84
|
export {};
|
package/date/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.recurrenceDate = exports.formateTDate = exports.formateToUnixIntegerddLLLyyyy = exports.formateDDDateISO = exports.formateddLLDate = exports.formateDDDate = exports.formateMMLongDate = exports.addDaysToTimeNowUtcDate = exports.viewYyformateToYyyy = exports.formateToyyyy = exports.formateToRFC2822 = exports.formateToLLLL = exports.formateTodd = exports.formateToCccc = exports.dateTimeNowUtc = exports.formateToT = exports.formatDateDDMMYYToUtc = exports.formatDateToUtc = exports.formateHHmm = exports.formateYYDDMM = exports.formateddLLLyyyy = exports.formateDate = void 0;
|
|
3
|
+
exports.recurrenceDate = exports.formateDateUnixInteger = exports.dateTimeNowUtcUnixInteger = exports.formateTDate = exports.formateToUnixIntegerddLLLyyyy = exports.formateDDDateISO = exports.formateddLLDate = exports.formateDDDate = exports.formateMMLongDate = exports.addDaysToTimeNowUtcDate = exports.viewYyformateToYyyy = exports.formateToyyyy = exports.formateToRFC2822 = exports.formateToLLLL = exports.formateTodd = exports.formateToCccc = exports.dateTimeNowUtc = exports.formateToT = exports.formatDateDDMMYYToUtc = exports.formatDateToUtc = exports.formateHHmm = exports.formateYYDDMM = exports.formateddLLLyyyy = exports.formateDate = void 0;
|
|
4
4
|
const date_fns_1 = require("date-fns");
|
|
5
5
|
const luxon_1 = require("luxon");
|
|
6
6
|
const enum_1 = require("../enum");
|
|
@@ -128,20 +128,45 @@ const formateTDate = (date, lang) => {
|
|
|
128
128
|
return luxon_1.DateTime.fromJSDate(date).setLocale(lang).toFormat("t");
|
|
129
129
|
};
|
|
130
130
|
exports.formateTDate = formateTDate;
|
|
131
|
+
/**
|
|
132
|
+
*
|
|
133
|
+
* @returns The current date in Unix integer format
|
|
134
|
+
* @example 1719168000
|
|
135
|
+
*/
|
|
136
|
+
const dateTimeNowUtcUnixInteger = () => luxon_1.DateTime.fromJSDate((0, exports.dateTimeNowUtc)()).toUnixInteger();
|
|
137
|
+
exports.dateTimeNowUtcUnixInteger = dateTimeNowUtcUnixInteger;
|
|
138
|
+
/**
|
|
139
|
+
* Format a date to a Unix integer
|
|
140
|
+
* @param date - The date to format (e.g. "2026-01-01", "2026-01-01T00:00:00.000Z", etc.)
|
|
141
|
+
* @returns The formatted date in Unix integer format
|
|
142
|
+
* @example 1719168000
|
|
143
|
+
*/
|
|
144
|
+
const formateDateUnixInteger = (date) => luxon_1.DateTime.fromJSDate(date).toUnixInteger();
|
|
145
|
+
exports.formateDateUnixInteger = formateDateUnixInteger;
|
|
131
146
|
/**
|
|
132
147
|
* @example
|
|
133
148
|
* recurrenceDate({ date: new Date(), recurrence: RecurrenceEnum.Monthly }) // 23/06/2026
|
|
134
149
|
*/
|
|
135
|
-
const recurrenceDate = ({ date, recurrence, duration = 1, }) => {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
150
|
+
const recurrenceDate = ({ date, recurrence, duration = 1, isRecurrence = true, }) => {
|
|
151
|
+
if (isRecurrence) {
|
|
152
|
+
const dateNow = (0, exports.dateTimeNowUtcUnixInteger)();
|
|
153
|
+
const dateInit = (0, exports.formateDateUnixInteger)(date);
|
|
154
|
+
const dateNowInit = dateInit > dateNow
|
|
155
|
+
? luxon_1.DateTime.fromJSDate(date)
|
|
156
|
+
: luxon_1.DateTime.fromJSDate((0, exports.dateTimeNowUtc)());
|
|
157
|
+
switch (recurrence) {
|
|
158
|
+
case enum_1.RecurrenceEnum.Daily:
|
|
159
|
+
return dateNowInit.plus({ days: duration }).toJSDate();
|
|
160
|
+
case enum_1.RecurrenceEnum.Weekly:
|
|
161
|
+
return dateNowInit.plus({ weeks: duration }).toJSDate();
|
|
162
|
+
case enum_1.RecurrenceEnum.Monthly:
|
|
163
|
+
return dateNowInit.plus({ months: duration }).toJSDate();
|
|
164
|
+
case enum_1.RecurrenceEnum.Yearly:
|
|
165
|
+
return dateNowInit.plus({ years: duration }).toJSDate();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
return date;
|
|
145
170
|
}
|
|
146
171
|
};
|
|
147
172
|
exports.recurrenceDate = recurrenceDate;
|
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.54","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"}}
|