jkbrzt / rrule

JavaScript library for working with recurrence rules for calendar dates as defined in the iCalendar RFC and more.
https://jkbrzt.github.io/rrule
Other
3.24k stars 506 forks source link

Invalid rrule string generated for single-digit year dtstart dates (ex: "0002-01-01") #623

Open jamesfulford opened 3 months ago

jamesfulford commented 3 months ago

Reporting an issue

Thank you for taking an interest in rrule! Please include the following in your report:

Code reproduction:

const rrule = require('rrule');
console.log(rrule.rrulestr(new rrule.RRule({ dtstart: new Date("0010-01-01T00:00:00Z") }).toString()));

Expected: any RRule object Actual: error is thrown:

Uncaught Error: Invalid UNTIL value: 00,20101T000000Z
    at untilStringToDate (/Users/jamesfulford/solomon-app/node_modules/rrule/dist/es5/rrule.js:370:15)
    at parseDtstart (/Users/jamesfulford/solomon-app/node_modules/rrule/dist/es5/rrule.js:2165:23)
    at parseInput (/Users/jamesfulford/solomon-app/node_modules/rrule/dist/es5/rrule.js:3429:25)
    at buildRule (/Users/jamesfulford/solomon-app/node_modules/rrule/dist/es5/rrule.js:3477:14)
    at Module.rrulestr (/Users/jamesfulford/solomon-app/node_modules/rrule/dist/es5/rrule.js:3512:12)

It seems that for single-digit year dtstart dates, rrule throws exceptions.

This matters because my app displays a preview of dates while the user is editing the dtstart, and "0002-01-01" is common when the user selects the year and starts typing in the year field (using the build-in <input type="date" /> selector). (Funnily enough, this was a user-discovered bug!) I'm able to fix it in my app by handling when the rrule string generated is invalid, but the library should be producing a valid rrule string in this scenario.

Operating system: MacOS Ventura 13.6.3 Node version: v18.19.0 rrule package version: 2.8.1

Timezone:

$ date
Wed Apr  3 11:38:30 MDT 2024
Velua commented 1 month ago

Are you saying you have users trying to select the year 80? not like 1980?