asv-hlps 1.3.32 → 1.3.33
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/lib/cjs/utils.d.ts +9 -7
- package/lib/cjs/utils.js +58 -52
- package/lib/esm/utils.d.ts +9 -7
- package/lib/esm/utils.js +51 -46
- package/package.json +1 -1
package/lib/cjs/utils.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import { ConfigType, OpUnitType, QUnitType } from "dayjs";
|
|
1
2
|
import "dayjs/locale/fr";
|
|
2
3
|
export declare const genDateMinutesStep: (step: number, lang?: string) => string[];
|
|
3
4
|
export declare const percentOf: (nbr: number, percentage: number) => number;
|
|
4
5
|
export declare const calPercent: (nbr: number, percentage: number) => number;
|
|
5
|
-
export declare const displayDateRangeFr: (getFromDate?: any, getToDate?: any) => string;
|
|
6
|
-
export declare const getNbOfDaysBetweenTwoDates: (date1: Date, date2: Date) => number;
|
|
7
6
|
export declare const getRandomColor: (brightness: number) => string;
|
|
8
7
|
/**
|
|
9
8
|
* remove duplicates from array by crietere (key)
|
|
@@ -25,10 +24,6 @@ export declare const formatToString: (val: number, separator?: string, currency?
|
|
|
25
24
|
export declare const currencyFormatter: (val: number, separator?: string, currency?: string) => string;
|
|
26
25
|
export declare const formatToStringCfa: (val: number) => string;
|
|
27
26
|
export declare const currencyFormatterCfa: (val: number) => string;
|
|
28
|
-
export declare const reformatDates: (fromDate: any, toDate: any) => {
|
|
29
|
-
fromDate: any;
|
|
30
|
-
toDate: any;
|
|
31
|
-
};
|
|
32
27
|
export declare const notInSequence: (arr: number[]) => number[];
|
|
33
28
|
export declare const sequencesToNumbers: (arr: any[]) => number[];
|
|
34
29
|
export declare const findSequencesMissing: (arr: any[]) => number[];
|
|
@@ -44,7 +39,15 @@ export declare const sesStorageSet: (key: string, val: any) => void;
|
|
|
44
39
|
export declare const sesStorageGet: (key: string) => any;
|
|
45
40
|
export declare const replaceAllIn: (text: string, regex?: RegExp, toChar?: string) => string;
|
|
46
41
|
export declare const replaceSpacesWith: (text: string, toChar?: string) => string;
|
|
42
|
+
export declare const dateFormatter: (date: Date | string, format?: "y" | "ym" | "ymd" | "dmy" | "ago" | "md" | "dmy-hm" | "dmyfr" | "myfr" | "mfr-short" | "mfr-long", separator?: "/" | "" | "-") => string;
|
|
43
|
+
export declare const dateDiff: (date1: ConfigType, unit?: QUnitType | OpUnitType, date2?: Date) => number;
|
|
47
44
|
export declare const dateToString: (date: Date | any) => string;
|
|
45
|
+
export declare const reformatDates: (fromDate: any, toDate: any) => {
|
|
46
|
+
fromDate: any;
|
|
47
|
+
toDate: any;
|
|
48
|
+
};
|
|
49
|
+
export declare const displayDateRangeFr: (getFromDate?: any, getToDate?: any) => string;
|
|
50
|
+
export declare const getNbOfDaysBetweenTwoDates: (date1: Date, date2: Date) => number;
|
|
48
51
|
export declare const formatNgbDate: (date: any) => {
|
|
49
52
|
fromDate: string;
|
|
50
53
|
toDate: string;
|
|
@@ -90,7 +93,6 @@ export declare const returnBool: (tob?: boolean) => boolean;
|
|
|
90
93
|
export declare const monthStringName: (date: string | Date, format?: "MMM" | "MMMM", options?: {
|
|
91
94
|
en?: true;
|
|
92
95
|
}) => string;
|
|
93
|
-
export declare const dateFormatter: (date: Date | string, format?: "y" | "ym" | "ymd" | "dmy" | "ago" | "md" | "dmy-hm" | "dmyfr" | "myfr" | "mfr-short" | "mfr-long", separator?: "/" | "" | "-") => string;
|
|
94
96
|
export declare const countryIsoToFlag: (code: string) => string;
|
|
95
97
|
export declare const removeParamKeyName: (params: any, name?: string) => any;
|
|
96
98
|
export declare const roundLastNDigits: (num: number, digits?: number) => number | false;
|
package/lib/cjs/utils.js
CHANGED
|
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
exports.toggleProp = exports.roundLastNDigits = exports.removeParamKeyName = exports.countryIsoToFlag = exports.
|
|
6
|
+
exports.padEndWithZero = exports.padStartWithZero = exports.formatMonthYearToLocaleString = exports.calculPercent = exports.validEmail = exports.convertToCfa = exports.packAndUnit = exports.unCheckedAll = exports.inputChecked = exports.arrayMultiChecked = exports.getPeriodDateColor = exports.getColorAccordingToDate = exports.genRandomColour = exports.formatNgbDate = exports.getNbOfDaysBetweenTwoDates = exports.displayDateRangeFr = exports.reformatDates = exports.dateToString = exports.dateDiff = exports.dateFormatter = exports.replaceSpacesWith = exports.replaceAllIn = exports.sesStorageGet = exports.sesStorageSet = exports.genSequenceRef = exports.removeBackSlashOccurences = exports.removeString = exports.diffArraysByProp = exports.diffArraysByFunc = exports.deepClone = exports.findFirstSequenceMissing = exports.fillNumWithZero = exports.findSequencesMissing = exports.sequencesToNumbers = exports.notInSequence = exports.currencyFormatterCfa = exports.formatToStringCfa = exports.currencyFormatter = exports.formatToString = exports.wakeUp = exports.sleep = exports.limitTo = exports.titleCase = exports.toObjectDate = exports.duplicateObjects = exports.removeDuplicateObjects = exports.getRandomColor = exports.calPercent = exports.percentOf = exports.genDateMinutesStep = void 0;
|
|
7
|
+
exports.toggleProp = exports.roundLastNDigits = exports.removeParamKeyName = exports.countryIsoToFlag = exports.monthStringName = exports.returnBool = exports.formatAmountToString = exports.reduceSum = exports.sumAmount = exports.fillEndWithZero = exports.fillStartWithZero = exports.absFromSequence = exports.returnDates = exports.displayFrDatePeriode = exports.getArrayOfRandomColor = exports.randomHslColor = exports.randomHexColor = exports.randomRgbColor = exports.randomInteger = exports.insertAtInArray = exports.isBirthday = void 0;
|
|
8
8
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
9
9
|
const relativeTime_1 = __importDefault(require("dayjs/plugin/relativeTime"));
|
|
10
10
|
const lodash_1 = __importDefault(require("lodash"));
|
|
@@ -86,18 +86,6 @@ const calPercent = (nbr, percentage) => {
|
|
|
86
86
|
return nbr + (nbr * percentage) / 100;
|
|
87
87
|
};
|
|
88
88
|
exports.calPercent = calPercent;
|
|
89
|
-
const displayDateRangeFr = (getFromDate, getToDate) => {
|
|
90
|
-
const fromDate = !getFromDate ? new Date() : getFromDate;
|
|
91
|
-
const toDate = !getToDate ? fromDate : getToDate;
|
|
92
|
-
return (0, exports.dateFormatter)(new Date(fromDate), "dmy", "/") + " au " + (0, exports.dateFormatter)(new Date(toDate), "dmy", "/");
|
|
93
|
-
};
|
|
94
|
-
exports.displayDateRangeFr = displayDateRangeFr;
|
|
95
|
-
const getNbOfDaysBetweenTwoDates = (date1, date2) => {
|
|
96
|
-
const day = 1000 * 60 * 60 * 24;
|
|
97
|
-
const diff = Math.abs(date2.getTime() - date1.getTime());
|
|
98
|
-
return Math.ceil(diff / day);
|
|
99
|
-
};
|
|
100
|
-
exports.getNbOfDaysBetweenTwoDates = getNbOfDaysBetweenTwoDates;
|
|
101
89
|
const getRandomColor = (brightness) => {
|
|
102
90
|
// Six levels of brightness from 0 to 5, 0 being the darkest
|
|
103
91
|
const rgb = [Math.random() * 256, Math.random() * 256, Math.random() * 256];
|
|
@@ -196,14 +184,6 @@ const currencyFormatterCfa = (val) => {
|
|
|
196
184
|
};
|
|
197
185
|
exports.currencyFormatterCfa = currencyFormatterCfa;
|
|
198
186
|
// const = reformatDates(fromDate: string, toDate: string) => {
|
|
199
|
-
const reformatDates = (fromDate, toDate) => {
|
|
200
|
-
if (fromDate === undefined || fromDate === null) {
|
|
201
|
-
return null;
|
|
202
|
-
}
|
|
203
|
-
toDate = !toDate ? fromDate : toDate;
|
|
204
|
-
return { fromDate, toDate };
|
|
205
|
-
};
|
|
206
|
-
exports.reformatDates = reformatDates;
|
|
207
187
|
const notInSequence = (arr) => {
|
|
208
188
|
const [min, max] = [Math.min(...arr), Math.max(...arr)];
|
|
209
189
|
// let out = Array.from(Array(max - min), (v, i) => i + min).filter((i) => !arr.includes(i));
|
|
@@ -302,10 +282,66 @@ const replaceSpacesWith = (text, toChar = "_") => {
|
|
|
302
282
|
return text.replace(/\s/g, toChar) || text;
|
|
303
283
|
};
|
|
304
284
|
exports.replaceSpacesWith = replaceSpacesWith;
|
|
285
|
+
/* start: dates -------------------------------------- */
|
|
286
|
+
const dateFormatter = (date, format = "dmy", separator = "/") => {
|
|
287
|
+
switch (format) {
|
|
288
|
+
case "y":
|
|
289
|
+
return (0, dayjs_1.default)(date).format("YYYY");
|
|
290
|
+
case "ym":
|
|
291
|
+
return (0, dayjs_1.default)(date).format(`YYYY${separator}MM`);
|
|
292
|
+
case "ymd":
|
|
293
|
+
return (0, dayjs_1.default)(date).format(`YYYY${separator}MM${separator}DD`);
|
|
294
|
+
case "md":
|
|
295
|
+
return (0, dayjs_1.default)(date).format(`MM${separator}DD`);
|
|
296
|
+
case "dmy":
|
|
297
|
+
return (0, dayjs_1.default)(date).format(`DD${separator}MM${separator}YYYY`);
|
|
298
|
+
case "dmy-hm":
|
|
299
|
+
return (0, dayjs_1.default)(date).format(`DD${separator}MM${separator}YYYY HH:mm`);
|
|
300
|
+
case "dmyfr":
|
|
301
|
+
return (0, dayjs_1.default)(date).locale("fr").format("dddd DD MMMM YYYY");
|
|
302
|
+
case "myfr":
|
|
303
|
+
return (0, dayjs_1.default)(date).locale("fr").format("MMMM YYYY");
|
|
304
|
+
case "mfr-short":
|
|
305
|
+
return (0, dayjs_1.default)(date).locale("fr").format("MMM");
|
|
306
|
+
case "mfr-long":
|
|
307
|
+
return (0, dayjs_1.default)(date).locale("fr").format("MMMM");
|
|
308
|
+
case "ago":
|
|
309
|
+
return (0, dayjs_1.default)(date).locale("fr").fromNow(true);
|
|
310
|
+
default:
|
|
311
|
+
return (0, dayjs_1.default)(date).format(`DD/MM/YYYY`);
|
|
312
|
+
// return dayjs(date).format(`YYYY${separator}MM${separator}DD`);
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
exports.dateFormatter = dateFormatter;
|
|
316
|
+
const dateDiff = (date1, unit = "year", date2 = new Date()) => {
|
|
317
|
+
return (0, dayjs_1.default)(date2).diff(date1, unit);
|
|
318
|
+
};
|
|
319
|
+
exports.dateDiff = dateDiff;
|
|
305
320
|
const dateToString = (date) => {
|
|
306
321
|
return date.year + "-" + ("0" + date.month).slice(-2) + "-" + ("0" + date.day).slice(-2);
|
|
307
322
|
};
|
|
308
323
|
exports.dateToString = dateToString;
|
|
324
|
+
const reformatDates = (fromDate, toDate) => {
|
|
325
|
+
if (fromDate === undefined || fromDate === null) {
|
|
326
|
+
return null;
|
|
327
|
+
}
|
|
328
|
+
toDate = !toDate ? fromDate : toDate;
|
|
329
|
+
return { fromDate, toDate };
|
|
330
|
+
};
|
|
331
|
+
exports.reformatDates = reformatDates;
|
|
332
|
+
const displayDateRangeFr = (getFromDate, getToDate) => {
|
|
333
|
+
const fromDate = !getFromDate ? new Date() : getFromDate;
|
|
334
|
+
const toDate = !getToDate ? fromDate : getToDate;
|
|
335
|
+
return (0, exports.dateFormatter)(new Date(fromDate), "dmy", "/") + " au " + (0, exports.dateFormatter)(new Date(toDate), "dmy", "/");
|
|
336
|
+
};
|
|
337
|
+
exports.displayDateRangeFr = displayDateRangeFr;
|
|
338
|
+
const getNbOfDaysBetweenTwoDates = (date1, date2) => {
|
|
339
|
+
const day = 1000 * 60 * 60 * 24;
|
|
340
|
+
const diff = Math.abs(date2.getTime() - date1.getTime());
|
|
341
|
+
return Math.ceil(diff / day);
|
|
342
|
+
};
|
|
343
|
+
exports.getNbOfDaysBetweenTwoDates = getNbOfDaysBetweenTwoDates;
|
|
344
|
+
/* end: dates ---------------------------------------- */
|
|
309
345
|
// export const formatNgbDate = (date: DateSelected) => {
|
|
310
346
|
const formatNgbDate = (date) => {
|
|
311
347
|
const fromDate = date.fromDate ? (0, exports.dateToString)(date.fromDate) : null;
|
|
@@ -624,36 +660,6 @@ const monthStringName = (date, format = "MMM", options) => {
|
|
|
624
660
|
return (0, dayjs_1.default)(date).locale("fr").format(format);
|
|
625
661
|
};
|
|
626
662
|
exports.monthStringName = monthStringName;
|
|
627
|
-
const dateFormatter = (date, format = "dmy", separator = "/") => {
|
|
628
|
-
switch (format) {
|
|
629
|
-
case "y":
|
|
630
|
-
return (0, dayjs_1.default)(date).format("YYYY");
|
|
631
|
-
case "ym":
|
|
632
|
-
return (0, dayjs_1.default)(date).format(`YYYY${separator}MM`);
|
|
633
|
-
case "ymd":
|
|
634
|
-
return (0, dayjs_1.default)(date).format(`YYYY${separator}MM${separator}DD`);
|
|
635
|
-
case "md":
|
|
636
|
-
return (0, dayjs_1.default)(date).format(`MM${separator}DD`);
|
|
637
|
-
case "dmy":
|
|
638
|
-
return (0, dayjs_1.default)(date).format(`DD${separator}MM${separator}YYYY`);
|
|
639
|
-
case "dmy-hm":
|
|
640
|
-
return (0, dayjs_1.default)(date).format(`DD${separator}MM${separator}YYYY HH:mm`);
|
|
641
|
-
case "dmyfr":
|
|
642
|
-
return (0, dayjs_1.default)(date).locale("fr").format("dddd DD MMMM YYYY");
|
|
643
|
-
case "myfr":
|
|
644
|
-
return (0, dayjs_1.default)(date).locale("fr").format("MMMM YYYY");
|
|
645
|
-
case "mfr-short":
|
|
646
|
-
return (0, dayjs_1.default)(date).locale("fr").format("MMM");
|
|
647
|
-
case "mfr-long":
|
|
648
|
-
return (0, dayjs_1.default)(date).locale("fr").format("MMMM");
|
|
649
|
-
case "ago":
|
|
650
|
-
return (0, dayjs_1.default)(date).locale("fr").fromNow(true);
|
|
651
|
-
default:
|
|
652
|
-
return (0, dayjs_1.default)(date).format(`DD/MM/YYYY`);
|
|
653
|
-
// return dayjs(date).format(`YYYY${separator}MM${separator}DD`);
|
|
654
|
-
}
|
|
655
|
-
};
|
|
656
|
-
exports.dateFormatter = dateFormatter;
|
|
657
663
|
const countryIsoToFlag = (code) => {
|
|
658
664
|
return code
|
|
659
665
|
.split("")
|
package/lib/esm/utils.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
import { ConfigType, OpUnitType, QUnitType } from "dayjs";
|
|
1
2
|
import "dayjs/locale/fr";
|
|
2
3
|
export declare const genDateMinutesStep: (step: number, lang?: string) => string[];
|
|
3
4
|
export declare const percentOf: (nbr: number, percentage: number) => number;
|
|
4
5
|
export declare const calPercent: (nbr: number, percentage: number) => number;
|
|
5
|
-
export declare const displayDateRangeFr: (getFromDate?: any, getToDate?: any) => string;
|
|
6
|
-
export declare const getNbOfDaysBetweenTwoDates: (date1: Date, date2: Date) => number;
|
|
7
6
|
export declare const getRandomColor: (brightness: number) => string;
|
|
8
7
|
/**
|
|
9
8
|
* remove duplicates from array by crietere (key)
|
|
@@ -25,10 +24,6 @@ export declare const formatToString: (val: number, separator?: string, currency?
|
|
|
25
24
|
export declare const currencyFormatter: (val: number, separator?: string, currency?: string) => string;
|
|
26
25
|
export declare const formatToStringCfa: (val: number) => string;
|
|
27
26
|
export declare const currencyFormatterCfa: (val: number) => string;
|
|
28
|
-
export declare const reformatDates: (fromDate: any, toDate: any) => {
|
|
29
|
-
fromDate: any;
|
|
30
|
-
toDate: any;
|
|
31
|
-
};
|
|
32
27
|
export declare const notInSequence: (arr: number[]) => number[];
|
|
33
28
|
export declare const sequencesToNumbers: (arr: any[]) => number[];
|
|
34
29
|
export declare const findSequencesMissing: (arr: any[]) => number[];
|
|
@@ -44,7 +39,15 @@ export declare const sesStorageSet: (key: string, val: any) => void;
|
|
|
44
39
|
export declare const sesStorageGet: (key: string) => any;
|
|
45
40
|
export declare const replaceAllIn: (text: string, regex?: RegExp, toChar?: string) => string;
|
|
46
41
|
export declare const replaceSpacesWith: (text: string, toChar?: string) => string;
|
|
42
|
+
export declare const dateFormatter: (date: Date | string, format?: "y" | "ym" | "ymd" | "dmy" | "ago" | "md" | "dmy-hm" | "dmyfr" | "myfr" | "mfr-short" | "mfr-long", separator?: "/" | "" | "-") => string;
|
|
43
|
+
export declare const dateDiff: (date1: ConfigType, unit?: QUnitType | OpUnitType, date2?: Date) => number;
|
|
47
44
|
export declare const dateToString: (date: Date | any) => string;
|
|
45
|
+
export declare const reformatDates: (fromDate: any, toDate: any) => {
|
|
46
|
+
fromDate: any;
|
|
47
|
+
toDate: any;
|
|
48
|
+
};
|
|
49
|
+
export declare const displayDateRangeFr: (getFromDate?: any, getToDate?: any) => string;
|
|
50
|
+
export declare const getNbOfDaysBetweenTwoDates: (date1: Date, date2: Date) => number;
|
|
48
51
|
export declare const formatNgbDate: (date: any) => {
|
|
49
52
|
fromDate: string;
|
|
50
53
|
toDate: string;
|
|
@@ -90,7 +93,6 @@ export declare const returnBool: (tob?: boolean) => boolean;
|
|
|
90
93
|
export declare const monthStringName: (date: string | Date, format?: "MMM" | "MMMM", options?: {
|
|
91
94
|
en?: true;
|
|
92
95
|
}) => string;
|
|
93
|
-
export declare const dateFormatter: (date: Date | string, format?: "y" | "ym" | "ymd" | "dmy" | "ago" | "md" | "dmy-hm" | "dmyfr" | "myfr" | "mfr-short" | "mfr-long", separator?: "/" | "" | "-") => string;
|
|
94
96
|
export declare const countryIsoToFlag: (code: string) => string;
|
|
95
97
|
export declare const removeParamKeyName: (params: any, name?: string) => any;
|
|
96
98
|
export declare const roundLastNDigits: (num: number, digits?: number) => number | false;
|
package/lib/esm/utils.js
CHANGED
|
@@ -76,16 +76,6 @@ export const calPercent = (nbr, percentage) => {
|
|
|
76
76
|
}
|
|
77
77
|
return nbr + (nbr * percentage) / 100;
|
|
78
78
|
};
|
|
79
|
-
export const displayDateRangeFr = (getFromDate, getToDate) => {
|
|
80
|
-
const fromDate = !getFromDate ? new Date() : getFromDate;
|
|
81
|
-
const toDate = !getToDate ? fromDate : getToDate;
|
|
82
|
-
return dateFormatter(new Date(fromDate), "dmy", "/") + " au " + dateFormatter(new Date(toDate), "dmy", "/");
|
|
83
|
-
};
|
|
84
|
-
export const getNbOfDaysBetweenTwoDates = (date1, date2) => {
|
|
85
|
-
const day = 1000 * 60 * 60 * 24;
|
|
86
|
-
const diff = Math.abs(date2.getTime() - date1.getTime());
|
|
87
|
-
return Math.ceil(diff / day);
|
|
88
|
-
};
|
|
89
79
|
export const getRandomColor = (brightness) => {
|
|
90
80
|
// Six levels of brightness from 0 to 5, 0 being the darkest
|
|
91
81
|
const rgb = [Math.random() * 256, Math.random() * 256, Math.random() * 256];
|
|
@@ -172,13 +162,6 @@ export const currencyFormatterCfa = (val) => {
|
|
|
172
162
|
return currencyFormatter(val, " ", " FCFA");
|
|
173
163
|
};
|
|
174
164
|
// const = reformatDates(fromDate: string, toDate: string) => {
|
|
175
|
-
export const reformatDates = (fromDate, toDate) => {
|
|
176
|
-
if (fromDate === undefined || fromDate === null) {
|
|
177
|
-
return null;
|
|
178
|
-
}
|
|
179
|
-
toDate = !toDate ? fromDate : toDate;
|
|
180
|
-
return { fromDate, toDate };
|
|
181
|
-
};
|
|
182
165
|
export const notInSequence = (arr) => {
|
|
183
166
|
const [min, max] = [Math.min(...arr), Math.max(...arr)];
|
|
184
167
|
// let out = Array.from(Array(max - min), (v, i) => i + min).filter((i) => !arr.includes(i));
|
|
@@ -262,9 +245,60 @@ export const replaceAllIn = (text, regex = / /g, toChar = "_") => {
|
|
|
262
245
|
export const replaceSpacesWith = (text, toChar = "_") => {
|
|
263
246
|
return text.replace(/\s/g, toChar) || text;
|
|
264
247
|
};
|
|
248
|
+
/* start: dates -------------------------------------- */
|
|
249
|
+
export const dateFormatter = (date, format = "dmy", separator = "/") => {
|
|
250
|
+
switch (format) {
|
|
251
|
+
case "y":
|
|
252
|
+
return dayjs(date).format("YYYY");
|
|
253
|
+
case "ym":
|
|
254
|
+
return dayjs(date).format(`YYYY${separator}MM`);
|
|
255
|
+
case "ymd":
|
|
256
|
+
return dayjs(date).format(`YYYY${separator}MM${separator}DD`);
|
|
257
|
+
case "md":
|
|
258
|
+
return dayjs(date).format(`MM${separator}DD`);
|
|
259
|
+
case "dmy":
|
|
260
|
+
return dayjs(date).format(`DD${separator}MM${separator}YYYY`);
|
|
261
|
+
case "dmy-hm":
|
|
262
|
+
return dayjs(date).format(`DD${separator}MM${separator}YYYY HH:mm`);
|
|
263
|
+
case "dmyfr":
|
|
264
|
+
return dayjs(date).locale("fr").format("dddd DD MMMM YYYY");
|
|
265
|
+
case "myfr":
|
|
266
|
+
return dayjs(date).locale("fr").format("MMMM YYYY");
|
|
267
|
+
case "mfr-short":
|
|
268
|
+
return dayjs(date).locale("fr").format("MMM");
|
|
269
|
+
case "mfr-long":
|
|
270
|
+
return dayjs(date).locale("fr").format("MMMM");
|
|
271
|
+
case "ago":
|
|
272
|
+
return dayjs(date).locale("fr").fromNow(true);
|
|
273
|
+
default:
|
|
274
|
+
return dayjs(date).format(`DD/MM/YYYY`);
|
|
275
|
+
// return dayjs(date).format(`YYYY${separator}MM${separator}DD`);
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
export const dateDiff = (date1, unit = "year", date2 = new Date()) => {
|
|
279
|
+
return dayjs(date2).diff(date1, unit);
|
|
280
|
+
};
|
|
265
281
|
export const dateToString = (date) => {
|
|
266
282
|
return date.year + "-" + ("0" + date.month).slice(-2) + "-" + ("0" + date.day).slice(-2);
|
|
267
283
|
};
|
|
284
|
+
export const reformatDates = (fromDate, toDate) => {
|
|
285
|
+
if (fromDate === undefined || fromDate === null) {
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
toDate = !toDate ? fromDate : toDate;
|
|
289
|
+
return { fromDate, toDate };
|
|
290
|
+
};
|
|
291
|
+
export const displayDateRangeFr = (getFromDate, getToDate) => {
|
|
292
|
+
const fromDate = !getFromDate ? new Date() : getFromDate;
|
|
293
|
+
const toDate = !getToDate ? fromDate : getToDate;
|
|
294
|
+
return dateFormatter(new Date(fromDate), "dmy", "/") + " au " + dateFormatter(new Date(toDate), "dmy", "/");
|
|
295
|
+
};
|
|
296
|
+
export const getNbOfDaysBetweenTwoDates = (date1, date2) => {
|
|
297
|
+
const day = 1000 * 60 * 60 * 24;
|
|
298
|
+
const diff = Math.abs(date2.getTime() - date1.getTime());
|
|
299
|
+
return Math.ceil(diff / day);
|
|
300
|
+
};
|
|
301
|
+
/* end: dates ---------------------------------------- */
|
|
268
302
|
// export const formatNgbDate = (date: DateSelected) => {
|
|
269
303
|
export const formatNgbDate = (date) => {
|
|
270
304
|
const fromDate = date.fromDate ? dateToString(date.fromDate) : null;
|
|
@@ -552,35 +586,6 @@ export const monthStringName = (date, format = "MMM", options) => {
|
|
|
552
586
|
}
|
|
553
587
|
return dayjs(date).locale("fr").format(format);
|
|
554
588
|
};
|
|
555
|
-
export const dateFormatter = (date, format = "dmy", separator = "/") => {
|
|
556
|
-
switch (format) {
|
|
557
|
-
case "y":
|
|
558
|
-
return dayjs(date).format("YYYY");
|
|
559
|
-
case "ym":
|
|
560
|
-
return dayjs(date).format(`YYYY${separator}MM`);
|
|
561
|
-
case "ymd":
|
|
562
|
-
return dayjs(date).format(`YYYY${separator}MM${separator}DD`);
|
|
563
|
-
case "md":
|
|
564
|
-
return dayjs(date).format(`MM${separator}DD`);
|
|
565
|
-
case "dmy":
|
|
566
|
-
return dayjs(date).format(`DD${separator}MM${separator}YYYY`);
|
|
567
|
-
case "dmy-hm":
|
|
568
|
-
return dayjs(date).format(`DD${separator}MM${separator}YYYY HH:mm`);
|
|
569
|
-
case "dmyfr":
|
|
570
|
-
return dayjs(date).locale("fr").format("dddd DD MMMM YYYY");
|
|
571
|
-
case "myfr":
|
|
572
|
-
return dayjs(date).locale("fr").format("MMMM YYYY");
|
|
573
|
-
case "mfr-short":
|
|
574
|
-
return dayjs(date).locale("fr").format("MMM");
|
|
575
|
-
case "mfr-long":
|
|
576
|
-
return dayjs(date).locale("fr").format("MMMM");
|
|
577
|
-
case "ago":
|
|
578
|
-
return dayjs(date).locale("fr").fromNow(true);
|
|
579
|
-
default:
|
|
580
|
-
return dayjs(date).format(`DD/MM/YYYY`);
|
|
581
|
-
// return dayjs(date).format(`YYYY${separator}MM${separator}DD`);
|
|
582
|
-
}
|
|
583
|
-
};
|
|
584
589
|
export const countryIsoToFlag = (code) => {
|
|
585
590
|
return code
|
|
586
591
|
.split("")
|