Skip to content

Commit

Permalink
Merge pull request #6 from omarkhairy21/v0.2.2
Browse files Browse the repository at this point in the history
V0.2.2
  • Loading branch information
omarkhairy21 committed Jun 12, 2023
2 parents 0d5c115 + 5e0c2a4 commit 9404c10
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cron-toolkit-ts",
"version": "0.2.0",
"version": "0.2.2",
"description": "Type-safe Toolkit to get cron expressions for JavaScript and TypeScript",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
15 changes: 15 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,19 @@ const atMorning = Cron.atMorning(); // 0 9 * * * every day at 9:00
const atEvening = Cron.atEvening(); // 0 18 * * * every day at 18:00
const atAfternoon = Cron.atAfternoon(); // 0 15 * * * every day at 15:00
const atStartOfTheDay = Cron.atStartOfTheDay(); // 0 0 * * * every day at 00:00
```

### Months
```ts
const everyMonth = Cron.everyMonth(); // 0 0 1 * * every month at 1st day at 00:00
```

## Non-standard cron expressions

### Seconds

```typescript
const every5Seconds = cron.useNonStandard().everyCustomSecond(5);
const every10Seconds = cron.useNonStandard().every15Seconds();
const every45Seconds = cron.useNonStandard().every45Seconds();
```
26 changes: 26 additions & 0 deletions src/cron.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ describe("Standard Cron Expressions", () => {
expect(cron.atMinute(30)).toEqual("30 * * * *");
expect(cron.atMinute(45)).toEqual("45 * * * *");
});

it("gets between minutes expressions", () => {
expect(cron.betweenMinutes(0, 59)).toEqual("0-59 * * * *");
})
});

describe("Hours", () => {
Expand All @@ -60,6 +64,10 @@ describe("Standard Cron Expressions", () => {
// alternative
expect(cron.everyCustomHour(3)).toEqual("0 */3 * * *");
expect(cron.everyCustomHour(4)).toEqual("0 */4 * * *");

it("gets between hours expressions", () => {
expect(cron.betweenHours(0, 23)).toEqual("0 0-23 * * *");
})
});

describe("Days", () => {
Expand All @@ -84,8 +92,26 @@ describe("Standard Cron Expressions", () => {
it("gets every week day expressions at 00:00", () => {
expect(cron.everyWeekDay()).toEqual("0 0 * * 1-5");
});

it("gets at day expressions", () => {
expect(cron.atDay(1)).toEqual("0 0 1 * *");
})

it("gets between days expressions", () => {
expect(cron.betweenDays(0, 31)).toEqual("0 0 0-31 * *");
})
});

describe('Month', () => {
it('gets at month expressions', () => {
expect(cron.atMonth(0)).toEqual("0 0 1 0 *");
})

it('gets between months expressions', () => {
expect(cron.betweenMonths(0, 11)).toEqual("0 0 1 0-11 *");
})
})

describe("Through The Day", () => {
it("gets 12:00 AM", () => {
expect(cron.atStartOfTheDay()).toEqual("0 0 * * *");
Expand Down

0 comments on commit 9404c10

Please sign in to comment.