Created
September 19, 2022 05:33
-
-
Save iamssen/af373521682fe03c667d896560407f94 to your computer and use it in GitHub Desktop.
node-cron time matcher test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { describe, test, expect } from 'vitest'; | |
| import TimeMatcher from 'node-cron/src/time-matcher'; | |
| describe('node-cron TimeMatcher test', () => { | |
| test('should match times', async () => { | |
| const seoul = new TimeMatcher('* 9-16 * * 1-5', 'Asia/Seoul'); | |
| expect(seoul.match(new Date('2022-09-18T12:38+09:00'))).toBeFalsy(); // is sunday | |
| expect(seoul.match(new Date('2022-09-19T12:38+09:00'))).toBeTruthy(); // is monday | |
| expect(seoul.match(new Date('2022-09-19T08:59+09:00'))).toBeFalsy(); | |
| const newyork = new TimeMatcher('* 4-19 * * 1-5', 'America/New_York'); | |
| expect(newyork.match(new Date('2022-09-18T12:38+09:00'))).toBeFalsy(); // is sunday in ko | |
| expect(newyork.match(new Date('2022-09-19T12:38+09:00'))).toBeFalsy(); // is monday in ko | |
| expect(newyork.match(new Date('2022-09-19T17:01+09:00'))).toBeTruthy(); // is monday 5pm in ko | |
| expect(newyork.match(new Date('2022-09-19T16:01+09:00'))).toBeFalsy(); // is monday 4pm in ko | |
| expect(newyork.match(new Date('2022-09-20T09:00+09:00'))).toBeFalsy(); // is tuesday 5am in ko | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment