-1

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.

nickos556
  • 337
  • 3
  • 16
  • So what's the difference in timezone between the two machines...? – Makoto Feb 27 '15 at 07:01
  • 1
    I think your linux environment has some issues, I get the same results as windows on my ubuntu setup... – Anshul Goyal Feb 27 '15 at 07:05
  • Actually, it lookslike a bug in dateutil as I can recreate the issue on my mac at home... It works ok in dateutil 1.5, but fails (ie the result is datetime.datetime(2015, 3, 5, 0, 0)) in dateutil 2.4 – nickos556 Feb 28 '15 at 03:08
  • I've raised an issue on github [link]https://github.com/dateutil/dateutil/issues/46 – nickos556 Feb 28 '15 at 03:14
  • FYI this issue got fixed https://github.com/dateutil/dateutil/issues/34 – nickos556 Aug 02 '15 at 07:05

1 Answers1

0

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.

jfs
  • 399,953
  • 195
  • 994
  • 1,670