@konplit-services/common 1.0.300 → 1.0.301
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.
|
@@ -23,6 +23,7 @@ export declare const convertDateToUTCString: (startTime: string) => string;
|
|
|
23
23
|
export declare const convertDateToUTC: (startTime: string) => Date;
|
|
24
24
|
type PlanInterval = keyof typeof PLAN_INTERVAL;
|
|
25
25
|
export declare const getDuration: (duration: PlanInterval) => number;
|
|
26
|
+
export declare const getFutureDateFromPlan: (duration: PlanInterval) => Date;
|
|
26
27
|
export declare const calculateDelay: (targetDate: string | Date) => {
|
|
27
28
|
isValid: boolean;
|
|
28
29
|
message: string;
|
|
@@ -3,7 +3,7 @@ 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.calculateDelay = exports.getDuration = exports.convertDateToUTC = exports.convertDateToUTCString = exports.convertDateToUTCRange = exports.convertDateToUTCRangeString = exports.getCurrentDayRange = exports.getPreviousDayRange = exports.convertToDate = exports.formatDateTime = exports.interswitchRefundDateFormat = exports.formatDate = void 0;
|
|
6
|
+
exports.calculateDelay = exports.getFutureDateFromPlan = exports.getDuration = exports.convertDateToUTC = exports.convertDateToUTCString = exports.convertDateToUTCRange = exports.convertDateToUTCRangeString = exports.getCurrentDayRange = exports.getPreviousDayRange = exports.convertToDate = exports.formatDateTime = exports.interswitchRefundDateFormat = exports.formatDate = void 0;
|
|
7
7
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
8
|
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
|
|
9
9
|
// Extend dayjs with the UTC plugin
|
|
@@ -106,6 +106,28 @@ const getDuration = (duration) => {
|
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
108
|
exports.getDuration = getDuration;
|
|
109
|
+
const getFutureDateFromPlan = (duration) => {
|
|
110
|
+
const currentDate = (0, dayjs_1.default)();
|
|
111
|
+
switch (duration) {
|
|
112
|
+
case plan_types_1.PLAN_INTERVAL.HOURLY:
|
|
113
|
+
return currentDate.add(1, "hour").toDate(); // Convert to Date object
|
|
114
|
+
case plan_types_1.PLAN_INTERVAL.DAILY:
|
|
115
|
+
return currentDate.add(1, "day").toDate();
|
|
116
|
+
case plan_types_1.PLAN_INTERVAL.WEEKLY:
|
|
117
|
+
return currentDate.add(1, "week").toDate();
|
|
118
|
+
case plan_types_1.PLAN_INTERVAL.MONTHLY:
|
|
119
|
+
return currentDate.add(1, "month").toDate();
|
|
120
|
+
case plan_types_1.PLAN_INTERVAL.QUARTERLY:
|
|
121
|
+
return currentDate.add(3, "month").toDate();
|
|
122
|
+
case plan_types_1.PLAN_INTERVAL["6MONTHS"]:
|
|
123
|
+
return currentDate.add(6, "month").toDate();
|
|
124
|
+
case plan_types_1.PLAN_INTERVAL.YEARLY:
|
|
125
|
+
return currentDate.add(1, "year").toDate();
|
|
126
|
+
default:
|
|
127
|
+
throw new Error("Invalid duration");
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
exports.getFutureDateFromPlan = getFutureDateFromPlan;
|
|
109
131
|
const calculateDelay = (targetDate) => {
|
|
110
132
|
const targetDatetime = (0, dayjs_1.default)(targetDate).utc();
|
|
111
133
|
const now = (0, dayjs_1.default)().utc();
|