Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8570095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:28:55+00:00 2026-06-11T18:28:55+00:00

Does dateutil rrule support DST and TZ? Need something similar to iCalendar RRULE. If

  • 0

Does dateutil rrule support DST and TZ? Need something similar to iCalendar RRULE.

If not – how to tackle this problem (scheduling recurring events & DST offset change)

Imports

>>> from django.utils import timezone
>>> import pytz
>>> from datetime import timedelta
>>> from dateutil import rrule
>>> now = timezone.now()
>>> pl = pytz.timezone("Europe/Warsaw")

Issue with timedelta (need to have the same local hours, but different DST offsets):

>>> pl.normalize(now)
datetime.datetime(2012, 9, 20, 1, 16, 58, 226000, tzinfo=<DstTzInfo 'Europe/Warsaw' CEST+2:00:00 DST>)    
>>> pl.normalize(now+timedelta(days=180))
datetime.datetime(2013, 3, 19, 0, 16, 58, 226000, tzinfo=<DstTzInfo 'Europe/Warsaw' CET+1:00:00 STD>)

Issue with rrule (need to have the same every local hour of each occurrence):

>>> r = rrule.rrule(3,dtstart=now,interval=180,count=2)
>>> pl.normalize(r[0])
datetime.datetime(2012, 9, 20, 1, 16, 58, tzinfo=<DstTzInfo 'Europe/Warsaw' CEST+2:00:00 DST>)
>>> pl.normalize(r[1])
datetime.datetime(2013, 3, 19, 0, 16, 58, tzinfo=<DstTzInfo 'Europe/Warsaw' CET+1:00:00 STD>)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:28:57+00:00Added an answer on June 11, 2026 at 6:28 pm

    @asdf: I can’t add code to comments so I need to post this as an answer:

    I am afraid that with your solution I will always loose DST info, therefore half of the year recurrences would be 1 hour off time.

    Basing on your answer I found out that this might be the correct solution:

    >>> from datetime import datetime
    >>> import pytz
    >>> from dateutil import rrule
    >>> # this is raw data I get from the DB, according to django docs I store it in UTC
    >>> raw = datetime.utcnow().replace(tzinfo=pytz.UTC)
    >>> # in addition I need to store the timezone so I can do dst the calculations
    >>> tz = pytz.timezone("Europe/Warsaw")
    >>> # this means that the actual local time would be
    >>> local = raw.astimezone(tz)
    >>> # but rrule doesn't take into account DST and local time, so I must convert aware datetime to naive
    >>> naive = local.replace(tzinfo=None)
    >>> # standard rrule
    >>> r = rrule.rrule(rrule.DAILY,interval=180,count=10,dtstart=naive)
    >>> for dt in r:
    >>>     # now we must get back to aware datetime - since we are using naive (local) datetime, 
            # we must convert it back to local timezone
    ...     print tz.localize(dt)
    

    This is why I think your solution might fail:

    >>> from datetime import datetime
    >>> from dateutil import rrule
    >>> import pytz
    >>> now = datetime.utcnow()
    >>> pl = pytz.timezone("Europe/Warsaw")
    >>> r = rrule.rrule(rrule.DAILY, dtstart=now, interval=180, count=2)
    >>> now
    datetime.datetime(2012, 9, 21, 9, 21, 57, 900000)
    >>> for dt in r:
    ...     local_dt = dt.replace(tzinfo=pytz.UTC).astimezone(pl)
    ...     print local_dt - local_dt.dst()
    ...     
    2012-09-21 10:21:57+02:00
    2013-03-20 10:21:57+01:00
    >>> # so what is the actual local time we store in the DB ?
    >>> now.replace(tzinfo=pytz.UTC).astimezone(pl)
    datetime.datetime(2012, 9, 21, 11, 21, 57, 900000, tzinfo=<DstTzInfo 'Europe/Warsaw' CEST+2:00:00 DST>)
    

    As you can see, there is 1 hour difference between the rrule result, and the real data we store in the DB.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does OpenJPA have any support for batch insert similar to Hibernate ? I haven't
Does the Java language have delegate features, similar to how C# has support for
I have a problem similar to this one below: Python pip broken after OS
Does anyone know of a free tool, similar to what is built into Visual
Does anybody know why this function, when passed an invalid date (e.g. timestamp) to
Does jQuery 1.5.1 support attribute selectors in the closest method? Given the structure below,
Does anyone know how to make this code stop the knob from rotating past
Does this line of Perl really do anything? $variable =~ s/^(\d+)\b/$1/sg; The only thing
does anyone know if iOS Simulator (that goes with XCode) support any kind of
Does SQL Server 2008 support the CREATE ASSERTION syntax? I haven't been able to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.