1

I'm seeing erroneous behavior with a by-day (e.g. 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.

stranger
  • 390
  • 4
  • 17
  • 1
    It would help to see some code. – snakecharmerb Apr 11 '20 at 15:44
  • There isn't enough detail here to answer the question. I guess you're using Django? All datetimes will be stored in UTC if `USE_TZ = True`. However views and templates (including [form fields](https://docs.djangoproject.com/en/dev/topics/i18n/timezones/#time-zone-aware-input-in-forms)) will automatically convert those fields to the current time zone. If that isn't what you're looking for, please update your question with more detail on what you're trying to do and why it isn't working. – Kevin Christopher Henry Apr 11 '20 at 19:30
  • @snakecharmerb I don't think it's a code issue, I just added a more specific example to clarify. – stranger Apr 13 '20 at 15:58
  • @KevinChristopherHenry I just updated it to have a more specific example. Please let me know if there are more details that you think would be helpful – stranger Apr 13 '20 at 15:58

1 Answers1

1

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.

Paul Rene
  • 680
  • 4
  • 14
  • I just updated my question with a specific example. The issue arises when I include a `BY_DAY` rule in the recurrence pattern. – stranger Apr 13 '20 at 15:59
  • From the docs (haven't tried it) the following would give you an event on every Tuesday and Thursday at 18:30 Pacific Time: DTSTART;TZID=Pacific/Honolulu:20200410T183000 RRULE:FREQ=WEEKLY;BYDAY=TU,TH. For non-UTC time zone there should not be a Z at the end of DTSTART. Many more examples at https://icalendar.org/iCalendar-RFC-5545/3-8-5-3-recurrence-rule.html. – Paul Rene Apr 13 '20 at 17:49
  • I've tried this, and I can't get it to work. I can get Django to store the DTSTART in my local timezone, but the start dates of the recurrences are still getting stored incorrectly. The time is the UTC time, but the date is still the "target date", so the event happens a day early. I'm using django-recurrences, and am having a difficult time figuring out how to create a fully fledged Recurrence object on the command line, so I'm not sure what to present here as an example – stranger Apr 15 '20 at 20:47
  • Wasn't aware that you were using django-recurrence, haven't used that. Did you set USE_TZ = True? According to the changelog 1.8.0 of the docs that should return a timezone-aware object. But I see there have been some issues with this package similar to yours: https://github.com/django-recurrence/django-recurrence/pull/71 and https://github.com/django-recurrence/django-recurrence/pull/104. I'm out of my depth here, but maybe the references can help you. – Paul Rene Apr 15 '20 at 21:26
  • Thank you very much. I'm sorry I didn't mention the Django library first – stranger Apr 15 '20 at 22:00