Skip to content

Commit

Permalink
fix: use correct month numbers from 0 to 11
Browse files Browse the repository at this point in the history
  • Loading branch information
rozsival committed Dec 19, 2022
1 parent 5a3b55d commit 62e26aa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable unicorn/no-process-exit */
import { Range, RecurrenceRule, scheduleJob } from 'node-schedule';

import { MAX_MONTH } from './constants';
import {
CHANNEL_ID,
JOB_HOUR,
Expand All @@ -11,10 +12,20 @@ import {
import { logger } from './logger';
import { run } from './run';

const formatMonth = (month: number) => {
const formatted = month - 1;
if (formatted < 0) return 0;
if (formatted > MAX_MONTH) return MAX_MONTH;
return formatted;
};

const rule = new RecurrenceRule();
rule.hour = JOB_HOUR;
rule.minute = 0;
rule.month = new Range(JOB_MONTH_START, JOB_MONTH_END);
rule.month = new Range(
formatMonth(JOB_MONTH_START),
formatMonth(JOB_MONTH_END),
);
rule.tz = TZ;

const job = scheduleJob(rule, run);
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const FIRST_MESSAGE_DAYS = 4;
export const FIRST_NOTIFICATION_DAYS = 2;
export const JANUARY = 1;
export const LAST_NOTIFICATION_DAYS = 1;
export const MAX_MONTH = 11;
export const SATURDAY = 6;
export const SATURDAY_DIFF = 1;
export const SUNDAY = 0;
Expand Down

0 comments on commit 62e26aa

Please sign in to comment.