Skip to content

Commit

Permalink
refactor: improve time.ts typings
Browse files Browse the repository at this point in the history
  • Loading branch information
sheerlox committed Sep 24, 2023
1 parent 788b7e0 commit a1dbc5c
Show file tree
Hide file tree
Showing 7 changed files with 381 additions and 241 deletions.
81 changes: 81 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
export const CONSTRAINTS = Object.freeze({
second: [0, 59],
minute: [0, 59],
hour: [0, 23],
dayOfMonth: [1, 31],
month: [1, 12],
dayOfWeek: [0, 7]
} as const);
export const MONTH_CONSTRAINTS = Object.freeze({
1: 31,
2: 29, // support leap year...not perfect
3: 31,
4: 30,
5: 31,
6: 30,
7: 31,
8: 31,
9: 30,
10: 31,
11: 30,
12: 31
} as const);
export const PARSE_DEFAULTS = Object.freeze({
second: '0',
minute: '*',
hour: '*',
dayOfMonth: '*',
month: '*',
dayOfWeek: '*'
} as const);
export const ALIASES = Object.freeze({
jan: 1,
feb: 2,
mar: 3,
apr: 4,
may: 5,
jun: 6,
jul: 7,
aug: 8,
sep: 9,
oct: 10,
nov: 11,
dec: 12,
sun: 0,
mon: 1,
tue: 2,
wed: 3,
thu: 4,
fri: 5,
sat: 6
} as const);
export const TIME_UNITS_MAP = Object.freeze({
SECOND: 'second',
MINUTE: 'minute',
HOUR: 'hour',
DAY_OF_MONTH: 'dayOfMonth',
MONTH: 'month',
DAY_OF_WEEK: 'dayOfWeek'
} as const);
export const TIME_UNITS = Object.freeze(Object.values(TIME_UNITS_MAP)) as [
'second',
'minute',
'hour',
'dayOfMonth',
'month',
'dayOfWeek'
];
export const TIME_UNITS_LEN: number = TIME_UNITS.length;
export const PRESETS = Object.freeze({
'@yearly': '0 0 0 1 1 *',
'@monthly': '0 0 0 1 * *',
'@weekly': '0 0 0 * * 0',
'@daily': '0 0 0 * * *',
'@hourly': '0 0 * * * *',
'@minutely': '0 * * * * *',
'@secondly': '* * * * * *',
'@weekdays': '0 0 0 * * 1-5',
'@weekends': '0 0 0 * * 0,6'
} as const);
export const RE_WILDCARDS = /\*/g;
export const RE_RANGE = /^(\d+)(?:-(\d+))?(?:\/(\d+))?$/g;
Loading

0 comments on commit a1dbc5c

Please sign in to comment.