Skip to content

Commit 2977282

Browse files
committed
feat: add check for non-integer numbers (#291)
1 parent f6a0c53 commit 2977282

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/helper.ts

+5
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ const checkSingleElementWithinLimits = (
5252
return err(`Element '${element} of ${cronFieldType} field is invalid.`)
5353
}
5454

55+
// check if integer and not a decimal
56+
if (number % 1 !== 0) {
57+
return err(`Element '${element} of ${cronFieldType} field is not an integer.`)
58+
}
59+
5560
const { lowerLimit } = options[cronFieldType]
5661
const { upperLimit } = options[cronFieldType]
5762
if (lowerLimit && number < lowerLimit) {

src/index.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ describe('Test cron validation', () => {
114114
expect(cron('1,2,3 4,5,6 1 1 1').isValid()).toBeTruthy()
115115

116116
expect(cron('01,02,03 04,05,06 01 01 01').isValid()).toBeTruthy()
117+
118+
expect(cron('1 1 1 1 1').isValid()).toBeTruthy()
119+
expect(cron('0.1 1 1 1 1').isValid()).toBeFalsy()
120+
expect(cron('1 0.1 1 1 1').isValid()).toBeFalsy()
121+
expect(cron('1 1 0.1 1 1').isValid()).toBeFalsy()
122+
expect(cron('1 1 1 0.1 1').isValid()).toBeFalsy()
123+
expect(cron('1 1 1 1 0.1').isValid()).toBeFalsy()
117124
})
118125

119126
it('Test cron field assignment', () => {

0 commit comments

Comments
 (0)