-
-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DTSTART with TZID: between produces incorrect time #355
Comments
I clonned this repo and added this test: it('generates correct recurrences when recurrence is WEEKLY and has BYDAY specified', () => {
const rrule = new RRule({
freq: RRule.WEEKLY,
dtstart: new Date(Date.UTC(2019, 6, 17, 18, 0, 0)),
tzid: 'America/Los_Angeles',
count: 10,
interval: 1,
wkst: RRule.SU,
byweekday: [RRule.MO, RRule.TU, RRule.WE, RRule.FR, RRule.SA]
})
expect(rrule.all()).to.deep.equal([
new Date('2019-07-17T18:00:00.000-07:00'), // WE
new Date('2019-07-19T18:00:00.000-07:00'), // FR
new Date('2019-07-20T18:00:00.000-07:00'), // SA
new Date('2019-07-22T18:00:00.000-07:00'), // MO
new Date('2019-07-23T18:00:00.000-07:00'), // TU
new Date('2019-07-24T18:00:00.000-07:00'),
new Date('2019-07-26T18:00:00.000-07:00'),
new Date('2019-07-27T18:00:00.000-07:00'),
new Date('2019-07-29T18:00:00.000-07:00'),
new Date('2019-07-30T18:00:00.000-07:00')
])
}) It succeeds only when I run it under UTC time zone (when I set |
I have this same issue but with rrule.all(). UTC works, while any other time zone applies the offset again when it shouldn't. |
I think it might have something to do with line 1849 of rrule-tz.js.
Looks like it's rezoning the date even though it's already correctly zoned. |
Changing |
This is not correct. The |
@agordeev I will look into this issue. @hlee5zebra 's "fix" of simply removing timezone support was not necessary. Do you get the expected results if you simply don't use the Regardless, the inconsistency between the RRule and RRuleSet behavior is concerning to me and probably a bug that needs a deeper look. Thanks for the test case! |
I see the issue that led to my problem -- my server code was not handling the DTSTART value time correctly, passing in UTC when it should be localized to the time zone specified by the TZID. Perhaps that may help you with your issue @agordeev . Thanks @davidgoli for pointing me in the right direction. |
Looks like I may have stumbled upon an issue in the codebase. The |
@hlee5zebra make sure to note this text in the README: https://github.com/jakubroztocil/rrule#important-use-utc-dates Important: Use UTC datesDates in JavaScript are tricky. RRule tries to support as much flexibility as possible without adding any large required 3rd party dependencies, but that means we also have some special rules. By default, RRule deals in "floating" times or UTC timezones. If you want results in a specific timezone, RRule also provides timezone support. Either way, JavaScript's built-in "timezone" offset tends to just get in the way, so this library simply doesn't use it at all. All times are returned with zero offset, as though it didn't exist in JavaScript. The bottom line is the returned "UTC" dates are always meant to be interpreted as dates in your local timezone. This may mean you have to do additional conversion to get the "correct" local time with offset applied. For this reason, it is highly recommended to use timestamps in UTC eg. new Date(Date.UTC(...)). Returned dates will likewise be in UTC (except on Chrome, which always returns dates with a timezone offset). |
The additional wrinkle is in most JS implementations, you either get UTC offset or local offset, but you can't switch between them. This also varies depending on the implementation. So a "UTC date" may be returned giving a For example, in Chrome:
but in node:
This is why for the best result, ignore the |
Note that this approach - using only UTC methods for all dates, and then "interpreting" them as being in local time - allows a uniform way of accessing dates & times returned by rrule without needing to consider the timezone of the rrule. |
Okay, I've been tinkering around with
While walking through the iterator function passed into America/Adak: America/Chicago: America/New_York: UTC: It looks like when the time zone is not set to UTC (e.g. America/Adak, America/New_York), then the offset between your local time and the selected time zone is subtracted from the DTSTART date. So the New York ISO string is showing 23:00 since the offset between my local time and New York is +1, which when subtracted from midnight on 07/18/2019, results in what we see, which is 11pm on 07/17/2019. Note that this doesn't happen for UTC though, which is curious. Do you think this might be the issue, or is there some configuration that needs to be done that I might have missed? |
As a workaround to what I've been seeing, I've done the following, and this seems to reliably get me an accurate instance of JavaScript's
|
@hlee5zebra Yes, your approach of using the Keep in mind that a pseudo-UTC date is almost never really in UTC time. UTC is just overloaded to be the "neutral" timezone, so the This is why my rewrite of this library will not use the builtin JS Date object at all. It's simply too confusing. |
Thanks for your reply David. const rrule = new RRule({
freq: RRule.WEEKLY,
dtstart: new Date(Date.UTC(2019, 6, 17, 18, 0, 0)),
// tzid: 'America/Los_Angeles',
count: 10,
interval: 1,
wkst: RRule.SU,
byweekday: [RRule.MO, RRule.TU, RRule.WE, RRule.FR, RRule.SA]
}) produces:
So the dates/times are correct, but time zone is UTC. rrule considers DTSTART in UTC when I omit tzid param.
I thought the only option to get recurrences in the user's time zone is to pass that time zone to tzid param? Keeping in mind the library is used with node.js on the server. |
If the recurrence will be at 1800 in the user's local time regardless of the timezone, then you do not need to use |
this issue is still opened? |
Reporting an issue
outputs this:
15:15:00 GMT-0500 (CDT)
is 17:15 PDT, while DTSTART isDTSTART;TZID=America/Los_Angeles:20190603T181500
When I set
tzid
implemented by @davidgoli I get a different result:The expected result is:
What's the reason of this?
rrule version: 2.6.2
I run node under CDT time zone. My system time zone is
America/Los_Angeles
The text was updated successfully, but these errors were encountered: