Search code examples
pythonpython-dateutil

python dateutil -different behaviour on Linux vs. Windows


Why am I getting different results from this code on Windows vs. Linux:

In [1]: from dateutil.rrule import rrule, DAILY, MONTHLY, MO, TU, WE, TH, FR

In [2]: from datetime import date, datetime

In [3]: r = rrule(MONTHLY, byweekday=TH(3), bymonth=(3,6,9,12), dtstart=datetime(2009,3,19))

In [4]: r.after(datetime(2015,3,1,12))
Out[4]: datetime.datetime(2015, 3, 5, 0, 0)

On windows I get:

In [1]: from dateutil.rrule import rrule, DAILY, MONTHLY, MO, TU, WE, TH, FR

In [2]: from datetime import date, datetime

In [3]: r = rrule(MONTHLY, byweekday=TH(3), bymonth=(3,6,9,12), dtstart=datetime(2009,3,19))

In [4]: r.after(datetime(2015,3,1,12))
Out[4]: datetime.datetime(2015, 3, 19, 0, 0)

Note that the machines are in different timezones.


Solution

  • I get the correct datetime(2015, 3, 19, 0, 0) on my Linux machine (dateutil-2.0).

    >>> import calendar
    >>> calendar.prmonth(2015, 3)
         March 2015
    Mo Tu We Th Fr Sa Su
                       1
     2  3  4  5  6  7  8
     9 10 11 12 13 14 15
    16 17 18 19 20 21 22
    23 24 25 26 27 28 29
    30 31
    

    The local timezone does not matter in this case -- 2015-03-19 may correspond to different UTC times in different timezones but as long as Gregorian calendar is used, 2015-03-05 won't be the 3rd Thursday of the month whatever the local timezone is.

    Try to update your dateutil version on your Linux machine.