简体   繁体   中英

Trouble with RFC 5545 Recurrence by day

I'm seeing erroneous behavior with a by-day (eg every Tuesday and Thursday) recurrence pattern.

Suppose I have an event starting on Thursday 3/12 at 9p (2100h) Pacific time and recurring every Tuesday and Thursday. Pacific time is UTC-0700 , so the event has a UTC start date of 0400h on 3/13--4am the following day.

When my recurrences are generated they take the start time of the original event, but not the date. So my recurrences are generated on Tuesdays and Thursdays at 0400h, which translates to 9p PT on Mondays and Wednesdays.

I've tried creating the events in local (Pacific) time and specifying a TZ-ID , but it doesn't seem to help.

Is there a way to account for this? I don't want to try to infer whether there will be an issue and rewrite the recurrence pattern on the fly, as that A) seems very error prone, and B) will make the interface for editing the recurrence pattern very challenging as well.

EDIT:

Consider this RRULE:

DTSTART:20200411T013000Z
RRULE:FREQ=WEEKLY;UNTIL=20200501T030000Z;BYDAY=FR

It was created to start at 6:30p PT on Friday, April 10, and repeat every Friday.

When converted to UTC that means that it has a start date of 1:30a on April 11th.

The issue is that the BY_DAY=FR is forcing all of the child events to get created on Fridays with start times of 1:30a, meaning that they start Thursday evening mountain time.

I don't think it's a code issue, I think it's an issue of the BY_DAY recurrence rule causing issues when the starting time is after midnight UTC.

Also, note that this is an example. Obviously in this case the BY_DAY field is not required. But if I wanted it to repeat on Wednesdays and Fridays I would need it, and that's where I'm running into the issue.

There is not a lot of information in your question, but let me try and help you. You're talking about the iCal format and you're probably using Django to generate iCal events. It is recommended to store all your date and time related data in UTC in your Django database, see https://docs.djangoproject.com/en/3.0/topics/i18n/timezones/#overview . You can use the standard utils functions that Django provides to calculate times and dates in other timezones from that, see https://docs.djangoproject.com/en/3.0/ref/utils/#module-django.utils.timezone . So having the right time in your Django program should not be a problem.

As far as I understand iCal is able to define events both in UTC and in other timezones. So a weekly event with a start date of 13 March 2020 and start time of 04:00 should have the following entries:

DTSTART:20200313T040000Z
RRULE:FREQ=WEEKLY

See https://icalendar.org/iCalendar-RFC-5545/4-icalendar-object-examples.html for more examples. Hope this helps to get you on track.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM