asv-hlps 1.3.22 → 1.3.24

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.
@@ -119,8 +119,7 @@ class HlpProduct {
119
119
  let lots = [];
120
120
  for (const pdtIn of ins) {
121
121
  if (pdtIn.lot) {
122
- // lots.push(pdtIn.lot + " =>" + moment(pdtIn.expirationDate).format("DD/MM/YYYY"));
123
- lots.push(pdtIn.lot + " =>" + (0, utils_1.convertEnDateToFr)(pdtIn.expirationDate, "/"));
122
+ lots.push(pdtIn.lot + " =>" + (0, utils_1.dateFormatter)(pdtIn.expirationDate, "dmy", "/"));
124
123
  }
125
124
  }
126
125
  return [...new Set(lots)];
@@ -27,8 +27,7 @@ const infoSale = (tob) => {
27
27
  ],
28
28
  [
29
29
  { text: tob.ref, style: "rowText" },
30
- // { text: moment(tob.createdAt ).format('DD/MM/YYYY'), style: 'rowText'},
31
- { text: (0, utils_1.convertEnDateToFr)(tob.createdAt, "/"), style: "rowText" },
30
+ { text: (0, utils_1.dateFormatter)(tob.createdAt, "dmy", "/"), style: "rowText" },
32
31
  { text: nbProducts, style: "rowText" },
33
32
  { text: totalQtity, style: "rowText" },
34
33
  { text: nbColis, style: "rowText" },
@@ -66,7 +65,7 @@ const infoBill = (tob) => {
66
65
  [
67
66
  { text: tob.ref, style: "rowText" },
68
67
  // { text: moment(tob.createdAt ).format('DD/MM/YYYY'), style: 'rowText'},
69
- { text: (0, utils_1.convertEnDateToFr)(tob.createdAt, "/"), style: "rowText" },
68
+ { text: (0, utils_1.dateFormatter)(tob.createdAt, "dmy", "/"), style: "rowText" },
70
69
  { text: nbProducts, style: "rowText" },
71
70
  { text: totalQtity, style: "rowText" },
72
71
  { text: nbColis, style: "rowText" },
@@ -4,9 +4,9 @@ exports.displayClient = exports.displayTitle = exports.displayPdfDate = void 0;
4
4
  const user_1 = require("../../user");
5
5
  const utils_1 = require("../../utils");
6
6
  const displayPdfDate = (label, fromDate, toDate) => {
7
- fromDate = !fromDate ? (0, utils_1.formatDateYmdHypen)(new Date()) : fromDate;
7
+ fromDate = !fromDate ? (0, utils_1.dateFormatter)(new Date(), "ymd", "-") : fromDate;
8
8
  toDate = !toDate ? fromDate : toDate;
9
- return label + " du " + (0, utils_1.convertEnDateToFr)(fromDate) + " au " + (0, utils_1.convertEnDateToFr)(toDate);
9
+ return label + " du " + (0, utils_1.dateFormatter)(fromDate) + " au " + (0, utils_1.dateFormatter)(toDate);
10
10
  };
11
11
  exports.displayPdfDate = displayPdfDate;
12
12
  const displayTitle = (title) => {
package/lib/cjs/sale.js CHANGED
@@ -111,7 +111,7 @@ const tabLabel = (sale) => {
111
111
  const name = (0, user_1.labelSteName)(sale.client.ste);
112
112
  const product = sp.product.designation;
113
113
  const pp = (0, utils_1.formatToStringCfa)(Math.ceil(sp.publicPrice));
114
- const saleDate = (0, utils_1.convertEnDateToFr)(sale.saleDate, "/");
114
+ const saleDate = (0, utils_1.dateFormatter)(sale.saleDate, "dmy", "/");
115
115
  // const saleDate = formatDateYmd(sale.saleDate, '/');
116
116
  // const saleDate = moment(sale.saleDate ).format('DD/MM/YYYY');
117
117
  labels.push({ name, product, pp, saleDate });
@@ -1,14 +1,4 @@
1
- export declare const formatDateYmdHypen: (date: Date | any) => string;
2
- export declare const formatDateYmdHypenFr: (date: Date | any) => string;
3
- export declare const formatDateFirstDayFr: (date: Date | any) => string;
4
- export declare const formatDateYmHypen: (date: Date | any) => string;
5
- export declare const formatFromAndToDate: (fromDate: Date, toDate: Date) => string;
6
- export declare const formatDateYmd: (date: Date | any, separator?: string) => string;
7
- export declare const formatDateYmFirstDay: (date: Date | any, separator?: string) => string;
8
- export declare const formatDateYm: (date: Date | any, separator?: string) => string;
9
- export declare const formatDateMd: (date: Date | any, separator?: string) => string;
10
- export declare const convertEnDateToFr: (date: Date | any, separator?: string) => string;
11
- export declare const convertFrDateToEnDate: (date: Date | any, separator?: string) => string;
1
+ import "dayjs/locale/fr";
12
2
  export declare const genDateMinutesStep: (step: number, lang?: string) => string[];
13
3
  export declare const percentOf: (nbr: number, percentage: number) => number;
14
4
  export declare const calPercent: (nbr: number, percentage: number) => number;
@@ -98,7 +88,7 @@ export declare const returnBool: (tob?: boolean) => boolean;
98
88
  export declare const monthStringName: (date: string | Date, format?: "MMM" | "MMMM", options?: {
99
89
  en?: true;
100
90
  }) => string;
101
- export declare const dateFormatter: (date: Date | string, format?: "y" | "ymd" | "dmy" | "dmy-hm" | "dmyfr" | "myfr" | "mfr-short" | "mfr-long", separator?: "/" | "-") => string;
91
+ export declare const dateFormatter: (date: Date | string, format?: "y" | "ymd" | "dmy" | "ago" | "md" | "dmy-hm" | "dmyfr" | "myfr" | "mfr-short" | "mfr-long", separator?: "/" | "-") => string;
102
92
  export declare const countryIsoToFlag: (code: string) => string;
103
93
  export declare const removeParamKeyName: (params: any, name?: string) => any;
104
94
  export declare const toggleProp: (tob: any, propToToggle: string) => any;
package/lib/cjs/utils.js CHANGED
@@ -3,74 +3,66 @@ 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.unCheckedAll = exports.inputChecked = exports.arrayMultiChecked = exports.getPeriodDateColor = exports.getColorAccordingToDate = exports.genRandomColour = exports.formatNgbDate = exports.dateToString = exports.replaceSpacesWith = exports.replaceAllIn = exports.sesStorageGet = exports.sesStorageSet = exports.genSequenceRef = exports.removeBackSlashOccurences = exports.removeString = exports.deepClone = exports.findFirstSequenceMissing = exports.fillNumWithZero = exports.findSequencesMissing = exports.sequencesToNumbers = exports.notInSequence = exports.reformatDates = 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.getNbOfDaysBetweenTwoDates = exports.displayDateRangeFr = exports.calPercent = exports.percentOf = exports.genDateMinutesStep = exports.convertFrDateToEnDate = exports.convertEnDateToFr = exports.formatDateMd = exports.formatDateYm = exports.formatDateYmFirstDay = exports.formatDateYmd = exports.formatFromAndToDate = exports.formatDateYmHypen = exports.formatDateFirstDayFr = exports.formatDateYmdHypenFr = exports.formatDateYmdHypen = void 0;
7
- exports.toggleProp = exports.removeParamKeyName = exports.countryIsoToFlag = exports.dateFormatter = 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 = exports.padEndWithZero = exports.padStartWithZero = exports.formatMonthYearToLocaleString = exports.calculPercent = exports.validEmail = exports.convertToCfa = exports.packAndUnit = void 0;
6
+ exports.randomRgbColor = exports.randomInteger = exports.insertAtInArray = exports.isBirthday = 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.dateToString = exports.replaceSpacesWith = exports.replaceAllIn = exports.sesStorageGet = exports.sesStorageSet = exports.genSequenceRef = exports.removeBackSlashOccurences = exports.removeString = exports.deepClone = exports.findFirstSequenceMissing = exports.fillNumWithZero = exports.findSequencesMissing = exports.sequencesToNumbers = exports.notInSequence = exports.reformatDates = 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.getNbOfDaysBetweenTwoDates = exports.displayDateRangeFr = exports.calPercent = exports.percentOf = exports.genDateMinutesStep = void 0;
7
+ exports.toggleProp = exports.removeParamKeyName = exports.countryIsoToFlag = exports.dateFormatter = 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 = void 0;
8
8
  const dayjs_1 = __importDefault(require("dayjs"));
9
+ const relativeTime_1 = __importDefault(require("dayjs/plugin/relativeTime"));
9
10
  const lodash_1 = __importDefault(require("lodash"));
11
+ require("dayjs/locale/fr");
12
+ dayjs_1.default.extend(relativeTime_1.default);
10
13
  // require("dayjs/locale/fr");
11
- const formatDateYmdHypen = (date) => {
12
- return (0, exports.formatDateYmd)(date, "-");
13
- };
14
- exports.formatDateYmdHypen = formatDateYmdHypen;
15
- const formatDateYmdHypenFr = (date) => {
16
- return (0, exports.convertEnDateToFr)((0, exports.formatDateYmd)(date, "-"));
17
- };
18
- exports.formatDateYmdHypenFr = formatDateYmdHypenFr;
19
- const formatDateFirstDayFr = (date) => {
20
- return ("0" + 1).slice(-2) + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + date.getUTCFullYear();
21
- };
22
- exports.formatDateFirstDayFr = formatDateFirstDayFr;
23
- const formatDateYmHypen = (date) => {
24
- return (0, exports.formatDateYm)(date, "-");
25
- };
26
- exports.formatDateYmHypen = formatDateYmHypen;
27
- const formatFromAndToDate = (fromDate, toDate) => {
28
- const getFromDate = !fromDate ? new Date() : fromDate;
29
- const getToDate = !toDate ? fromDate : toDate;
30
- return (0, exports.formatDateYmdHypenFr)(new Date(getFromDate)) + " au " + (0, exports.formatDateYmdHypenFr)(new Date(getToDate));
31
- };
32
- exports.formatFromAndToDate = formatFromAndToDate;
33
- const formatDateYmd = (date, separator = "") => {
34
- return (0, exports.formatDateYm)(date, separator) + separator + ("0" + date.getUTCDate()).slice(-2);
35
- };
36
- exports.formatDateYmd = formatDateYmd;
37
- const formatDateYmFirstDay = (date, separator = "") => {
38
- return (0, exports.formatDateYm)(date, separator) + separator + ("0" + 1).slice(-2);
39
- };
40
- exports.formatDateYmFirstDay = formatDateYmFirstDay;
41
- const formatDateYm = (date, separator = "") => {
42
- return date.getUTCFullYear() + separator + ("0" + (date.getMonth() + 1)).slice(-2);
43
- };
44
- exports.formatDateYm = formatDateYm;
45
- const formatDateMd = (date, separator = "") => {
46
- // return ('0' + (date.getMonth() + 1)).slice(-2) + separator + ('0' + date.getUTCDate()).slice(-2);
47
- return date.getMonth() + 1 + separator + date.getUTCDate();
48
- };
49
- exports.formatDateMd = formatDateMd;
50
- const convertEnDateToFr = (date, separator = "-") => {
51
- if (!date) {
52
- return null;
53
- }
54
- date = new Date(date).toISOString();
55
- date = date.trim();
56
- const year = date.substring(0, 4);
57
- const month = date.substring(5, 7);
58
- const day = date.substring(8, 10);
59
- return day + separator + month + separator + year;
60
- };
61
- exports.convertEnDateToFr = convertEnDateToFr;
62
- const convertFrDateToEnDate = (date, separator = "-") => {
63
- if (!date) {
64
- return null;
65
- }
66
- date = date.trim();
67
- const day = date.substring(0, 2);
68
- const month = date.substring(3, 5);
69
- const year = date.substring(6, 10);
70
- // return day + separator + month + separator + year
71
- return year + separator + month + separator + day;
72
- };
73
- exports.convertFrDateToEnDate = convertFrDateToEnDate;
14
+ /* start: dates -------------------------------------- */
15
+ const name = () => { };
16
+ /* end: dates ---------------------------------------- */
17
+ /* export const formatDateYmdHypenFr = (date: Date | any) => {
18
+ return convertEnDateToFr(formatDateYmd(date, "-"));
19
+ }; */
20
+ /* export const formatDateFirstDayFr = (date: Date | any) => {
21
+ return ("0" + 1).slice(-2) + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + date.getUTCFullYear();
22
+ }; */
23
+ /* export const formatDateYmHypen = (date: Date | any) => {
24
+ return formatDateYm(date, "-");
25
+ }; */
26
+ /* export const formatFromAndToDate = (fromDate: Date, toDate: Date) => {
27
+ const getFromDate = !fromDate ? new Date() : fromDate;
28
+ const getToDate = !toDate ? fromDate : toDate;
29
+ return formatDateYmdHypenFr(new Date(getFromDate)) + " au " + formatDateYmdHypenFr(new Date(getToDate));
30
+ }; */
31
+ /* export const formatDateYmd = (date: Date | any, separator: string = "") => {
32
+ return formatDateYm(date, separator) + separator + ("0" + date.getUTCDate()).slice(-2);
33
+ }; */
34
+ /* export const formatDateYmFirstDay = (date: Date | any, separator: string = "") => {
35
+ return formatDateYm(date, separator) + separator + ("0" + 1).slice(-2);
36
+ }; */
37
+ /* export const formatDateYm = (date: Date | any, separator: string = "") => {
38
+ return date.getUTCFullYear() + separator + ("0" + (date.getMonth() + 1)).slice(-2);
39
+ }; */
40
+ /* export const formatDateMd = (date: Date | any, separator: string = "") => {
41
+ // return ('0' + (date.getMonth() + 1)).slice(-2) + separator + ('0' + date.getUTCDate()).slice(-2);
42
+ return date.getMonth() + 1 + separator + date.getUTCDate();
43
+ }; */
44
+ /* export const convertEnDateToFr = (date: Date | any, separator: string = "-") => {
45
+ if (!date) {
46
+ return null;
47
+ }
48
+ date = new Date(date).toISOString();
49
+ date = date.trim();
50
+ const year = date.substring(0, 4);
51
+ const month = date.substring(5, 7);
52
+ const day = date.substring(8, 10);
53
+ return day + separator + month + separator + year;
54
+ }; */
55
+ /* export const convertFrDateToEnDate = (date: Date | any, separator: string = "-") => {
56
+ if (!date) {
57
+ return null;
58
+ }
59
+ date = date.trim();
60
+ const day = date.substring(0, 2);
61
+ const month = date.substring(3, 5);
62
+ const year = date.substring(6, 10);
63
+ // return day + separator + month + separator + year
64
+ return year + separator + month + separator + day;
65
+ }; */
74
66
  const genDateMinutesStep = (step, lang = "fr-FR") => {
75
67
  const date = new Date(2021, 0, 1);
76
68
  const series = [];
@@ -98,7 +90,7 @@ exports.calPercent = calPercent;
98
90
  const displayDateRangeFr = (getFromDate, getToDate) => {
99
91
  const fromDate = !getFromDate ? new Date() : getFromDate;
100
92
  const toDate = !getToDate ? fromDate : getToDate;
101
- return (0, exports.formatDateYmdHypenFr)(new Date(fromDate)) + " au " + (0, exports.formatDateYmdHypenFr)(new Date(toDate));
93
+ return (0, exports.dateFormatter)(new Date(fromDate), "dmy", "/") + " au " + (0, exports.dateFormatter)(new Date(toDate), "dmy", "/");
102
94
  };
103
95
  exports.displayDateRangeFr = displayDateRangeFr;
104
96
  const getNbOfDaysBetweenTwoDates = (date1, date2) => {
@@ -489,8 +481,8 @@ const padEndWithZero = (num, targetLength) => {
489
481
  exports.padEndWithZero = padEndWithZero;
490
482
  const isBirthday = (birthDayDate) => {
491
483
  if (birthDayDate) {
492
- const toDay = (0, exports.formatDateMd)(new Date());
493
- const birthDay = (0, exports.formatDateMd)(new Date(birthDayDate));
484
+ const toDay = (0, exports.dateFormatter)(new Date(), "md", "-");
485
+ const birthDay = (0, exports.dateFormatter)(new Date(birthDayDate), "md", "-");
494
486
  return toDay === birthDay;
495
487
  }
496
488
  };
@@ -553,7 +545,7 @@ exports.getArrayOfRandomColor = getArrayOfRandomColor;
553
545
  const displayFrDatePeriode = (getFromDate, getToDate) => {
554
546
  const fromDate = !getFromDate ? new Date() : getFromDate;
555
547
  const toDate = !getToDate ? fromDate : getToDate;
556
- return (0, exports.formatDateYmdHypenFr)(new Date(fromDate)) + " au " + (0, exports.formatDateYmdHypenFr)(new Date(toDate));
548
+ return (0, exports.dateFormatter)(new Date(fromDate), "dmy", "/") + " au " + (0, exports.dateFormatter)(new Date(toDate), "dmy", "/");
557
549
  };
558
550
  exports.displayFrDatePeriode = displayFrDatePeriode;
559
551
  const returnDates = (fromDate, toDate) => {
@@ -629,6 +621,8 @@ const dateFormatter = (date, format = "dmy", separator = "/") => {
629
621
  return (0, dayjs_1.default)(date).format("YYYY");
630
622
  case "ymd":
631
623
  return (0, dayjs_1.default)(date).format(`YYYY${separator}MM${separator}DD`);
624
+ case "md":
625
+ return (0, dayjs_1.default)(date).format(`MM${separator}DD`);
632
626
  case "dmy":
633
627
  return (0, dayjs_1.default)(date).format(`DD${separator}MM${separator}YYYY`);
634
628
  case "dmy-hm":
@@ -641,6 +635,8 @@ const dateFormatter = (date, format = "dmy", separator = "/") => {
641
635
  return (0, dayjs_1.default)(date).locale("fr").format("MMM");
642
636
  case "mfr-long":
643
637
  return (0, dayjs_1.default)(date).locale("fr").format("MMMM");
638
+ case "ago":
639
+ return (0, dayjs_1.default)(date).locale("fr").fromNow(true);
644
640
  default:
645
641
  return (0, dayjs_1.default)(date).format(`DD/MM/YYYY`);
646
642
  // return dayjs(date).format(`YYYY${separator}MM${separator}DD`);
@@ -1,4 +1,4 @@
1
- import { convertEnDateToFr } from "../utils";
1
+ import { dateFormatter } from "../utils";
2
2
  class HlpProduct {
3
3
  productCatCode(product, catCodes) {
4
4
  return catCodes.includes(product.cat.code && product.cat.code.toLowerCase());
@@ -117,8 +117,7 @@ class HlpProduct {
117
117
  let lots = [];
118
118
  for (const pdtIn of ins) {
119
119
  if (pdtIn.lot) {
120
- // lots.push(pdtIn.lot + " =>" + moment(pdtIn.expirationDate).format("DD/MM/YYYY"));
121
- lots.push(pdtIn.lot + " =>" + convertEnDateToFr(pdtIn.expirationDate, "/"));
120
+ lots.push(pdtIn.lot + " =>" + dateFormatter(pdtIn.expirationDate, "dmy", "/"));
122
121
  }
123
122
  }
124
123
  return [...new Set(lots)];
@@ -1,6 +1,6 @@
1
1
  import { getNbFreezeOnBill, getNbPackagesOnBill, getNbProductsOnBill, getTotalQtityOnBill } from "../../bill";
2
2
  import { getNbProductsOnSale, getTotalQtityOnSale } from "../../sale";
3
- import { convertEnDateToFr } from "../../utils";
3
+ import { dateFormatter } from "../../utils";
4
4
  export const infoSale = (tob) => {
5
5
  const totalQtity = getTotalQtityOnSale(tob);
6
6
  const nbProducts = getNbProductsOnSale(tob);
@@ -24,8 +24,7 @@ export const infoSale = (tob) => {
24
24
  ],
25
25
  [
26
26
  { text: tob.ref, style: "rowText" },
27
- // { text: moment(tob.createdAt ).format('DD/MM/YYYY'), style: 'rowText'},
28
- { text: convertEnDateToFr(tob.createdAt, "/"), style: "rowText" },
27
+ { text: dateFormatter(tob.createdAt, "dmy", "/"), style: "rowText" },
29
28
  { text: nbProducts, style: "rowText" },
30
29
  { text: totalQtity, style: "rowText" },
31
30
  { text: nbColis, style: "rowText" },
@@ -62,7 +61,7 @@ export const infoBill = (tob) => {
62
61
  [
63
62
  { text: tob.ref, style: "rowText" },
64
63
  // { text: moment(tob.createdAt ).format('DD/MM/YYYY'), style: 'rowText'},
65
- { text: convertEnDateToFr(tob.createdAt, "/"), style: "rowText" },
64
+ { text: dateFormatter(tob.createdAt, "dmy", "/"), style: "rowText" },
66
65
  { text: nbProducts, style: "rowText" },
67
66
  { text: totalQtity, style: "rowText" },
68
67
  { text: nbColis, style: "rowText" },
@@ -1,9 +1,9 @@
1
1
  import { getSteShortname } from "../../user";
2
- import { convertEnDateToFr, formatDateYmdHypen } from "../../utils";
2
+ import { dateFormatter } from "../../utils";
3
3
  export const displayPdfDate = (label, fromDate, toDate) => {
4
- fromDate = !fromDate ? formatDateYmdHypen(new Date()) : fromDate;
4
+ fromDate = !fromDate ? dateFormatter(new Date(), "ymd", "-") : fromDate;
5
5
  toDate = !toDate ? fromDate : toDate;
6
- return label + " du " + convertEnDateToFr(fromDate) + " au " + convertEnDateToFr(toDate);
6
+ return label + " du " + dateFormatter(fromDate) + " au " + dateFormatter(toDate);
7
7
  };
8
8
  export const displayTitle = (title) => {
9
9
  return {
package/lib/esm/sale.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { unitPriceByClientCat } from "./product";
2
2
  import { labelSteName } from "./user";
3
- import { convertEnDateToFr, formatToStringCfa, removeBackSlashOccurences } from "./utils";
3
+ import { dateFormatter, formatToStringCfa, removeBackSlashOccurences } from "./utils";
4
4
  export const getNbProductsOnSale = (sale) => {
5
5
  return sale.saleProducts.length || 0;
6
6
  };
@@ -92,7 +92,7 @@ export const tabLabel = (sale) => {
92
92
  const name = labelSteName(sale.client.ste);
93
93
  const product = sp.product.designation;
94
94
  const pp = formatToStringCfa(Math.ceil(sp.publicPrice));
95
- const saleDate = convertEnDateToFr(sale.saleDate, "/");
95
+ const saleDate = dateFormatter(sale.saleDate, "dmy", "/");
96
96
  // const saleDate = formatDateYmd(sale.saleDate, '/');
97
97
  // const saleDate = moment(sale.saleDate ).format('DD/MM/YYYY');
98
98
  labels.push({ name, product, pp, saleDate });
@@ -1,14 +1,4 @@
1
- export declare const formatDateYmdHypen: (date: Date | any) => string;
2
- export declare const formatDateYmdHypenFr: (date: Date | any) => string;
3
- export declare const formatDateFirstDayFr: (date: Date | any) => string;
4
- export declare const formatDateYmHypen: (date: Date | any) => string;
5
- export declare const formatFromAndToDate: (fromDate: Date, toDate: Date) => string;
6
- export declare const formatDateYmd: (date: Date | any, separator?: string) => string;
7
- export declare const formatDateYmFirstDay: (date: Date | any, separator?: string) => string;
8
- export declare const formatDateYm: (date: Date | any, separator?: string) => string;
9
- export declare const formatDateMd: (date: Date | any, separator?: string) => string;
10
- export declare const convertEnDateToFr: (date: Date | any, separator?: string) => string;
11
- export declare const convertFrDateToEnDate: (date: Date | any, separator?: string) => string;
1
+ import "dayjs/locale/fr";
12
2
  export declare const genDateMinutesStep: (step: number, lang?: string) => string[];
13
3
  export declare const percentOf: (nbr: number, percentage: number) => number;
14
4
  export declare const calPercent: (nbr: number, percentage: number) => number;
@@ -98,7 +88,7 @@ export declare const returnBool: (tob?: boolean) => boolean;
98
88
  export declare const monthStringName: (date: string | Date, format?: "MMM" | "MMMM", options?: {
99
89
  en?: true;
100
90
  }) => string;
101
- export declare const dateFormatter: (date: Date | string, format?: "y" | "ymd" | "dmy" | "dmy-hm" | "dmyfr" | "myfr" | "mfr-short" | "mfr-long", separator?: "/" | "-") => string;
91
+ export declare const dateFormatter: (date: Date | string, format?: "y" | "ymd" | "dmy" | "ago" | "md" | "dmy-hm" | "dmyfr" | "myfr" | "mfr-short" | "mfr-long", separator?: "/" | "-") => string;
102
92
  export declare const countryIsoToFlag: (code: string) => string;
103
93
  export declare const removeParamKeyName: (params: any, name?: string) => any;
104
94
  export declare const toggleProp: (tob: any, propToToggle: string) => any;
package/lib/esm/utils.js CHANGED
@@ -1,58 +1,61 @@
1
1
  import dayjs from "dayjs";
2
+ import relativeTime from "dayjs/plugin/relativeTime";
2
3
  import lodash from "lodash";
4
+ import "dayjs/locale/fr";
5
+ dayjs.extend(relativeTime);
3
6
  // require("dayjs/locale/fr");
4
- export const formatDateYmdHypen = (date) => {
5
- return formatDateYmd(date, "-");
6
- };
7
- export const formatDateYmdHypenFr = (date) => {
8
- return convertEnDateToFr(formatDateYmd(date, "-"));
9
- };
10
- export const formatDateFirstDayFr = (date) => {
11
- return ("0" + 1).slice(-2) + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + date.getUTCFullYear();
12
- };
13
- export const formatDateYmHypen = (date) => {
14
- return formatDateYm(date, "-");
15
- };
16
- export const formatFromAndToDate = (fromDate, toDate) => {
17
- const getFromDate = !fromDate ? new Date() : fromDate;
18
- const getToDate = !toDate ? fromDate : toDate;
19
- return formatDateYmdHypenFr(new Date(getFromDate)) + " au " + formatDateYmdHypenFr(new Date(getToDate));
20
- };
21
- export const formatDateYmd = (date, separator = "") => {
22
- return formatDateYm(date, separator) + separator + ("0" + date.getUTCDate()).slice(-2);
23
- };
24
- export const formatDateYmFirstDay = (date, separator = "") => {
25
- return formatDateYm(date, separator) + separator + ("0" + 1).slice(-2);
26
- };
27
- export const formatDateYm = (date, separator = "") => {
28
- return date.getUTCFullYear() + separator + ("0" + (date.getMonth() + 1)).slice(-2);
29
- };
30
- export const formatDateMd = (date, separator = "") => {
31
- // return ('0' + (date.getMonth() + 1)).slice(-2) + separator + ('0' + date.getUTCDate()).slice(-2);
32
- return date.getMonth() + 1 + separator + date.getUTCDate();
33
- };
34
- export const convertEnDateToFr = (date, separator = "-") => {
35
- if (!date) {
36
- return null;
37
- }
38
- date = new Date(date).toISOString();
39
- date = date.trim();
40
- const year = date.substring(0, 4);
41
- const month = date.substring(5, 7);
42
- const day = date.substring(8, 10);
43
- return day + separator + month + separator + year;
44
- };
45
- export const convertFrDateToEnDate = (date, separator = "-") => {
46
- if (!date) {
47
- return null;
48
- }
49
- date = date.trim();
50
- const day = date.substring(0, 2);
51
- const month = date.substring(3, 5);
52
- const year = date.substring(6, 10);
53
- // return day + separator + month + separator + year
54
- return year + separator + month + separator + day;
55
- };
7
+ /* start: dates -------------------------------------- */
8
+ const name = () => { };
9
+ /* end: dates ---------------------------------------- */
10
+ /* export const formatDateYmdHypenFr = (date: Date | any) => {
11
+ return convertEnDateToFr(formatDateYmd(date, "-"));
12
+ }; */
13
+ /* export const formatDateFirstDayFr = (date: Date | any) => {
14
+ return ("0" + 1).slice(-2) + "-" + ("0" + (date.getMonth() + 1)).slice(-2) + "-" + date.getUTCFullYear();
15
+ }; */
16
+ /* export const formatDateYmHypen = (date: Date | any) => {
17
+ return formatDateYm(date, "-");
18
+ }; */
19
+ /* export const formatFromAndToDate = (fromDate: Date, toDate: Date) => {
20
+ const getFromDate = !fromDate ? new Date() : fromDate;
21
+ const getToDate = !toDate ? fromDate : toDate;
22
+ return formatDateYmdHypenFr(new Date(getFromDate)) + " au " + formatDateYmdHypenFr(new Date(getToDate));
23
+ }; */
24
+ /* export const formatDateYmd = (date: Date | any, separator: string = "") => {
25
+ return formatDateYm(date, separator) + separator + ("0" + date.getUTCDate()).slice(-2);
26
+ }; */
27
+ /* export const formatDateYmFirstDay = (date: Date | any, separator: string = "") => {
28
+ return formatDateYm(date, separator) + separator + ("0" + 1).slice(-2);
29
+ }; */
30
+ /* export const formatDateYm = (date: Date | any, separator: string = "") => {
31
+ return date.getUTCFullYear() + separator + ("0" + (date.getMonth() + 1)).slice(-2);
32
+ }; */
33
+ /* export const formatDateMd = (date: Date | any, separator: string = "") => {
34
+ // return ('0' + (date.getMonth() + 1)).slice(-2) + separator + ('0' + date.getUTCDate()).slice(-2);
35
+ return date.getMonth() + 1 + separator + date.getUTCDate();
36
+ }; */
37
+ /* export const convertEnDateToFr = (date: Date | any, separator: string = "-") => {
38
+ if (!date) {
39
+ return null;
40
+ }
41
+ date = new Date(date).toISOString();
42
+ date = date.trim();
43
+ const year = date.substring(0, 4);
44
+ const month = date.substring(5, 7);
45
+ const day = date.substring(8, 10);
46
+ return day + separator + month + separator + year;
47
+ }; */
48
+ /* export const convertFrDateToEnDate = (date: Date | any, separator: string = "-") => {
49
+ if (!date) {
50
+ return null;
51
+ }
52
+ date = date.trim();
53
+ const day = date.substring(0, 2);
54
+ const month = date.substring(3, 5);
55
+ const year = date.substring(6, 10);
56
+ // return day + separator + month + separator + year
57
+ return year + separator + month + separator + day;
58
+ }; */
56
59
  export const genDateMinutesStep = (step, lang = "fr-FR") => {
57
60
  const date = new Date(2021, 0, 1);
58
61
  const series = [];
@@ -77,7 +80,7 @@ export const calPercent = (nbr, percentage) => {
77
80
  export const displayDateRangeFr = (getFromDate, getToDate) => {
78
81
  const fromDate = !getFromDate ? new Date() : getFromDate;
79
82
  const toDate = !getToDate ? fromDate : getToDate;
80
- return formatDateYmdHypenFr(new Date(fromDate)) + " au " + formatDateYmdHypenFr(new Date(toDate));
83
+ return dateFormatter(new Date(fromDate), "dmy", "/") + " au " + dateFormatter(new Date(toDate), "dmy", "/");
81
84
  };
82
85
  export const getNbOfDaysBetweenTwoDates = (date1, date2) => {
83
86
  const day = 1000 * 60 * 60 * 24;
@@ -425,8 +428,8 @@ export const padEndWithZero = (num, targetLength) => {
425
428
  };
426
429
  export const isBirthday = (birthDayDate) => {
427
430
  if (birthDayDate) {
428
- const toDay = formatDateMd(new Date());
429
- const birthDay = formatDateMd(new Date(birthDayDate));
431
+ const toDay = dateFormatter(new Date(), "md", "-");
432
+ const birthDay = dateFormatter(new Date(birthDayDate), "md", "-");
430
433
  return toDay === birthDay;
431
434
  }
432
435
  };
@@ -482,7 +485,7 @@ export const getArrayOfRandomColor = (length, type = "hex") => {
482
485
  export const displayFrDatePeriode = (getFromDate, getToDate) => {
483
486
  const fromDate = !getFromDate ? new Date() : getFromDate;
484
487
  const toDate = !getToDate ? fromDate : getToDate;
485
- return formatDateYmdHypenFr(new Date(fromDate)) + " au " + formatDateYmdHypenFr(new Date(toDate));
488
+ return dateFormatter(new Date(fromDate), "dmy", "/") + " au " + dateFormatter(new Date(toDate), "dmy", "/");
486
489
  };
487
490
  export const returnDates = (fromDate, toDate) => {
488
491
  if (fromDate === undefined || fromDate === null) {
@@ -548,6 +551,8 @@ export const dateFormatter = (date, format = "dmy", separator = "/") => {
548
551
  return dayjs(date).format("YYYY");
549
552
  case "ymd":
550
553
  return dayjs(date).format(`YYYY${separator}MM${separator}DD`);
554
+ case "md":
555
+ return dayjs(date).format(`MM${separator}DD`);
551
556
  case "dmy":
552
557
  return dayjs(date).format(`DD${separator}MM${separator}YYYY`);
553
558
  case "dmy-hm":
@@ -560,6 +565,8 @@ export const dateFormatter = (date, format = "dmy", separator = "/") => {
560
565
  return dayjs(date).locale("fr").format("MMM");
561
566
  case "mfr-long":
562
567
  return dayjs(date).locale("fr").format("MMMM");
568
+ case "ago":
569
+ return dayjs(date).locale("fr").fromNow(true);
563
570
  default:
564
571
  return dayjs(date).format(`DD/MM/YYYY`);
565
572
  // return dayjs(date).format(`YYYY${separator}MM${separator}DD`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asv-hlps",
3
- "version": "1.3.22",
3
+ "version": "1.3.24",
4
4
  "description": "helpers",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/esm/index.js",