Reputation: 139
Is there way in Typescript to derive Cron expressions from a start date, for Weekly, Monthly, and Annually. I have been searching for existing code base.
Upvotes: 1
Views: 422
Reputation: 139
getCreateWeeklyFromStartDate(startDate: Date): string {
const startWeekday = startDate.getDay();
const startHour = startDate.getHours();
const startMinute = startDate.getMinutes();
const cronExpression = `${startMinute} ${startHour} * * ${startWeekday}`;
return cronExpression;
}
getCreateMonthlyFromStartDate(startDate: Date): string {
const startDayOfMonth = startDate.getDate();
const startHour = startDate.getHours();
const startMinute = startDate.getMinutes();
const cronExpression = `${startMinute} ${startHour} ${startDayOfMonth} * *`;
return cronExpression;
}
getCreateAnnualFromStartDate(startDate: Date): string {
const startMonth = startDate.getMonth() + 1;
const startDayOfMonth = startDate.getDate();
const startHour = startDate.getHours();
const startMinute = startDate.getMinutes();
const cronExpression = `${startMinute} ${startHour} ${startDayOfMonth} ${startMonth} *`;
return cronExpression;
}
Upvotes: 1