@kiminix/tp-client 1.9.0 → 1.11.0
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.
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { parseISO } from "date-fns";
|
|
2
|
+
import { isDayBefore, isDayBetween } from "./date-utils";
|
|
3
|
+
var BusinessUtils = /** @class */ (function () {
|
|
4
|
+
function BusinessUtils() {
|
|
5
|
+
}
|
|
6
|
+
// licence is active if business has an available date that it is not expired
|
|
7
|
+
BusinessUtils.isLicenceActive = function (available) {
|
|
8
|
+
var today = new Date();
|
|
9
|
+
return (available === null || available === void 0 ? void 0 : available.to) ? isDayBefore(today, parseISO(available.to)) : false;
|
|
10
|
+
};
|
|
11
|
+
// check if the business is active for a specific date
|
|
12
|
+
BusinessUtils.isLicenceActiveByDay = function (date, available) {
|
|
13
|
+
return available ? isDayBetween(date, parseISO(available.from), parseISO(available.to)) : false;
|
|
14
|
+
};
|
|
15
|
+
return BusinessUtils;
|
|
16
|
+
}());
|
|
17
|
+
export { BusinessUtils };
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @returns Get the seconds timestamp of the given date with truncated minutes and seconds (will be updated every one hour)
|
|
4
|
+
*/
|
|
1
5
|
export declare function getTruncatedTimestamp(): number;
|
|
2
6
|
export declare function dateToString(date: string | Date, options: Intl.DateTimeFormatOptions): string;
|
|
3
7
|
export declare function toStringDefault(date: string | Date, options: Intl.DateTimeFormatOptions): string;
|
|
@@ -5,12 +9,20 @@ export declare function isDayBetween(date: Date, start: Date, end: Date): boolea
|
|
|
5
9
|
export declare function isDayAfter(date: Date, dateToCompare: Date, include?: Boolean): boolean;
|
|
6
10
|
export declare function isDayBefore(date: Date, dateToCompare: Date, include?: Boolean): boolean;
|
|
7
11
|
/**
|
|
8
|
-
*
|
|
9
|
-
* ex: if date is in this format: 20/08/2023 , timezone should not be used
|
|
12
|
+
*
|
|
10
13
|
* @param date
|
|
11
14
|
* @param options
|
|
15
|
+
* @return a string representation of the date in the default format like: vend. 20 août 2023
|
|
16
|
+
*
|
|
17
|
+
* @note timezone should not be set for DateTimeFormatOptions for input without timezone like localdate otherwise info will be wrong.
|
|
18
|
+
* ex: if date is in this format: 20/08/2023 , timezone should not be used
|
|
12
19
|
*/
|
|
13
20
|
export declare function toString(date: string | Date, options?: Intl.DateTimeFormatOptions): string;
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param date
|
|
24
|
+
* @returns a string default representation of the date in the Tunisia timezone format (without weekday) like: 25 juin 2022 10:30
|
|
25
|
+
*/
|
|
14
26
|
export declare function toTunisiaLocale(date: string | Date): string;
|
|
15
27
|
/**
|
|
16
28
|
*
|
package/dist/utils/date-utils.js
CHANGED
|
@@ -9,8 +9,11 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
-
import {
|
|
13
|
-
|
|
12
|
+
import { differenceInCalendarDays, getUnixTime, isSameDay, parseISO, setMinutes, setSeconds } from "date-fns";
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @returns Get the seconds timestamp of the given date with truncated minutes and seconds (will be updated every one hour)
|
|
16
|
+
*/
|
|
14
17
|
export function getTruncatedTimestamp() {
|
|
15
18
|
return getUnixTime(setMinutes(setSeconds(new Date(), 0), 0));
|
|
16
19
|
}
|
|
@@ -35,17 +38,22 @@ export function isDayBetween(date, start, end) {
|
|
|
35
38
|
}
|
|
36
39
|
export function isDayAfter(date, dateToCompare, include) {
|
|
37
40
|
if (include === void 0) { include = false; }
|
|
38
|
-
|
|
41
|
+
//DO NOT USE isAfter because it compare time and not only date
|
|
42
|
+
return differenceInCalendarDays(date, dateToCompare) > 0 || (include && isSameDay(date, dateToCompare));
|
|
39
43
|
}
|
|
40
44
|
export function isDayBefore(date, dateToCompare, include) {
|
|
41
45
|
if (include === void 0) { include = false; }
|
|
42
|
-
|
|
46
|
+
//DO NOT USE isBefore because it compare time and not only date
|
|
47
|
+
return differenceInCalendarDays(date, dateToCompare) < 0 || (include && isSameDay(date, dateToCompare));
|
|
43
48
|
}
|
|
44
49
|
/**
|
|
45
|
-
*
|
|
46
|
-
* ex: if date is in this format: 20/08/2023 , timezone should not be used
|
|
50
|
+
*
|
|
47
51
|
* @param date
|
|
48
52
|
* @param options
|
|
53
|
+
* @return a string representation of the date in the default format like: vend. 20 août 2023
|
|
54
|
+
*
|
|
55
|
+
* @note timezone should not be set for DateTimeFormatOptions for input without timezone like localdate otherwise info will be wrong.
|
|
56
|
+
* ex: if date is in this format: 20/08/2023 , timezone should not be used
|
|
49
57
|
*/
|
|
50
58
|
export function toString(date, options) {
|
|
51
59
|
if (options === void 0) { options = {}; }
|
|
@@ -63,10 +71,14 @@ export function toString(date, options) {
|
|
|
63
71
|
return date.toLocaleDateString("fr-FR", mergedOptions);
|
|
64
72
|
}
|
|
65
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
*
|
|
76
|
+
* @param date
|
|
77
|
+
* @returns a string default representation of the date in the Tunisia timezone format (without weekday) like: 25 juin 2022 10:30
|
|
78
|
+
*/
|
|
66
79
|
export function toTunisiaLocale(date) {
|
|
67
80
|
// This is how we get Timezone auto from user OS, but for simplicity we will use Africa/Tunis
|
|
68
81
|
// const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
69
|
-
// request a weekday along with a long date. ex: 25 juin 2022 10:30
|
|
70
82
|
var options = {
|
|
71
83
|
year: "numeric",
|
|
72
84
|
month: "long",
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Available, LocalDate } from "../types";
|
|
2
1
|
import { DailyDiscount, PresetMenu } from "../menus/preset/types/preset-menu";
|
|
2
|
+
import { LocalDate } from "../types";
|
|
3
3
|
export declare class MenuUtils {
|
|
4
|
-
static isBusinessAvailable(available?: Available): boolean;
|
|
5
4
|
static isMenuAvailableByDay(menu: PresetMenu, date: Date): boolean;
|
|
6
5
|
static getDiscounts(menu: PresetMenu): Map<LocalDate, DailyDiscount>;
|
|
7
6
|
static getAvailableDiscounts(menu: PresetMenu): Map<LocalDate, DailyDiscount>;
|
package/dist/utils/menu-utils.js
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { BusinessUtils } from "./business-utils";
|
|
2
|
+
import { toLocaleDate } from "./date-utils";
|
|
3
3
|
var MenuUtils = /** @class */ (function () {
|
|
4
4
|
function MenuUtils() {
|
|
5
5
|
}
|
|
6
|
-
// business account is available if it has an available date that it is not expired
|
|
7
|
-
MenuUtils.isBusinessAvailable = function (available) {
|
|
8
|
-
var today = new Date();
|
|
9
|
-
return (available === null || available === void 0 ? void 0 : available.to) ? isDayBefore(today, parseISO(available.to)) : false;
|
|
10
|
-
};
|
|
11
6
|
MenuUtils.isMenuAvailableByDay = function (menu, date) {
|
|
12
7
|
var _a, _b;
|
|
13
|
-
|
|
14
|
-
var isBusinessAvailable = (menu === null || menu === void 0 ? void 0 : menu.available) ? isDayBetween(date, parseISO(menu.available.from), parseISO(menu.available.to)) : false;
|
|
8
|
+
var isLicenceActive = BusinessUtils.isLicenceActiveByDay(date, menu.available);
|
|
15
9
|
var isDayExcluded = (_b = (_a = menu.excludedDays) === null || _a === void 0 ? void 0 : _a.includes(toLocaleDate(date))) !== null && _b !== void 0 ? _b : false;
|
|
16
|
-
return
|
|
10
|
+
return isLicenceActive && !isDayExcluded;
|
|
17
11
|
};
|
|
18
12
|
MenuUtils.getDiscounts = function (menu) {
|
|
19
13
|
var _a;
|