jkbrzt / rrule

JavaScript library for working with recurrence rules for calendar dates as defined in the iCalendar RFC and more.

Home Page:https://jkbrzt.github.io/rrule

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generate UTC time when using byhour with tzid

Qasim-bbits opened this issue · comments

If user select 00:00 to 02:00 so events are generating on following time 00:00, 00:30, 01:00 and 01:30 daily or weekly

const rule = new RRule({
  freq: RRule.WEEKLY,
  dtstart: new Date(Date.UTC(2023, 0, 7, 0, 0, 0)),
  tzid: 'Asia/Karachi',
  until: new Date(Date.UTC(2023, 0, 22, 3, 48, 0)),
  count: 30,
  interval: 1,
  byweekday: [RRule.MO, RRule.TU, RRule.WE],
  byhour: [0, 1],
  byminute: [0, 30],
  bysecond: [0]
})

When I get events using rule.between() it throws wrong time as follow:

[
'Mon Jan 09 2023 05:00:00 GMT+0500 (Pakistan Standard Time)',
'Mon Jan 09 2023 05:30:00 GMT+0500 (Pakistan Standard Time)',
'Mon Jan 09 2023 06:00:00 GMT+0500 (Pakistan Standard Time)',
'Mon Jan 09 2023 06:30:00 GMT+0500 (Pakistan Standard Time)',
'Tue Jan 10 2023 05:00:00 GMT+0500 (Pakistan Standard Time)',
'Tue Jan 10 2023 05:30:00 GMT+0500 (Pakistan Standard Time)',
.
.
.
.
]

I know it byhour: [0, 1] is generating time in UTC and converting it to GMT+05:00 when calling rule.between(). But how can I handle hours when user select start and end time? Also I've tried to convert selected time to UTC and pass it to byhour but it generates weird dates and time. What is the purpose of tzid if it won't work with byhour attribute? Expected Result:

[
'Mon Jan 09 2023 00:00:00 GMT+0500 (Pakistan Standard Time)',
'Mon Jan 09 2023 00:30:00 GMT+0500 (Pakistan Standard Time)',
'Mon Jan 09 2023 01:00:00 GMT+0500 (Pakistan Standard Time)',
'Mon Jan 09 2023 01:30:00 GMT+0500 (Pakistan Standard Time)',
'Tue Jan 10 2023 00:00:00 GMT+0500 (Pakistan Standard Time)',
'Tue Jan 10 2023 00:30:00 GMT+0500 (Pakistan Standard Time)',
.
.
.
.
]

Please let me know how can I achieve expected result?