Skip to content

Commit

Permalink
Update dateutil to 2.5.0 with updated zoneinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
labrys committed Feb 29, 2016
1 parent fc97e18 commit 4ec759b
Show file tree
Hide file tree
Showing 10 changed files with 735 additions and 559 deletions.
2 changes: 1 addition & 1 deletion lib/dateutil/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
__version__ = "2.4.2"
__version__ = "2.5.0"
417 changes: 183 additions & 234 deletions lib/dateutil/parser.py

Large diffs are not rendered by default.

256 changes: 157 additions & 99 deletions lib/dateutil/relativedelta.py

Large diffs are not rendered by default.

31 changes: 25 additions & 6 deletions lib/dateutil/rrule.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

from six import advance_iterator, integer_types
from six.moves import _thread
import heapq

# For warning about deprecation of until and count
from warnings import warn

__all__ = ["rrule", "rruleset", "rrulestr",
"YEARLY", "MONTHLY", "WEEKLY", "DAILY",
Expand Down Expand Up @@ -405,6 +409,11 @@ def __init__(self, freq, dtstart=None,
until = datetime.datetime.fromordinal(until.toordinal())
self._until = until

if count and until:
warn("Using both 'count' and 'until' is inconsistent with RFC 2445"
" and has been deprecated in dateutil. Future versions will "
"raise an error.", DeprecationWarning)

if wkst is None:
self._wkst = calendar.firstweekday()
elif isinstance(wkst, integer_types):
Expand Down Expand Up @@ -648,6 +657,9 @@ def __str__(self):
if self._count:
parts.append('COUNT=' + str(self._count))

if self._until:
parts.append(self._until.strftime('UNTIL=%Y%m%dT%H%M%S'))

if self._original_rule.get('byweekday') is not None:
# The str() method on weekday objects doesn't generate
# RFC2445-compliant strings, so we should modify that.
Expand Down Expand Up @@ -1236,7 +1248,11 @@ def __next__(self):
try:
self.dt = advance_iterator(self.gen)
except StopIteration:
self.genlist.remove(self)
if self.genlist[0] is self:
heapq.heappop(self.genlist)
else:
self.genlist.remove(self)
heapq.heapify(self.genlist)

next = __next__

Expand Down Expand Up @@ -1288,27 +1304,30 @@ def _iter(self):
self._genitem(rlist, iter(self._rdate))
for gen in [iter(x) for x in self._rrule]:
self._genitem(rlist, gen)
rlist.sort()
exlist = []
self._exdate.sort()
self._genitem(exlist, iter(self._exdate))
for gen in [iter(x) for x in self._exrule]:
self._genitem(exlist, gen)
exlist.sort()
lastdt = None
total = 0
heapq.heapify(rlist)
heapq.heapify(exlist)
while rlist:
ritem = rlist[0]
if not lastdt or lastdt != ritem.dt:
while exlist and exlist[0] < ritem:
advance_iterator(exlist[0])
exlist.sort()
exitem = exlist[0]
advance_iterator(exitem)
if exlist and exlist[0] is exitem:
heapq.heapreplace(exlist, exitem)
if not exlist or ritem != exlist[0]:
total += 1
yield ritem.dt
lastdt = ritem.dt
advance_iterator(ritem)
rlist.sort()
if rlist and rlist[0] is ritem:
heapq.heapreplace(rlist, ritem)
self._len = total


Expand Down
20 changes: 20 additions & 0 deletions lib/dateutil/tz/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from .tz import *
from six import PY3

__all__ = ["tzutc", "tzoffset", "tzlocal", "tzfile", "tzrange",
"tzstr", "tzical", "tzwin", "tzwinlocal", "gettz"]

def tzname_in_python2(namefunc):
"""Change unicode output into bytestrings in Python 2
tzname() API changed in Python 3. It used to return bytes, but was changed
to unicode strings
"""
def adjust_encoding(*args, **kwargs):
name = namefunc(*args, **kwargs)
if name is not None and not PY3:
name = name.encode()

return name

return adjust_encoding
43 changes: 17 additions & 26 deletions lib/dateutil/tz.py → lib/dateutil/tz/tz.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,20 @@
import os

from six import string_types, PY3
from .__init__ import tzname_in_python2

try:
from dateutil.tzwin import tzwin, tzwinlocal
from .win import tzwin, tzwinlocal
except ImportError:
tzwin = tzwinlocal = None

relativedelta = None
parser = None
rrule = None

__all__ = ["tzutc", "tzoffset", "tzlocal", "tzfile", "tzrange",
"tzstr", "tzical", "tzwin", "tzwinlocal", "gettz"]


def tzname_in_python2(namefunc):
"""Change unicode output into bytestrings in Python 2
tzname() API changed in Python 3. It used to return bytes, but was changed
to unicode strings
"""
def adjust_encoding(*args, **kwargs):
name = namefunc(*args, **kwargs)
if name is not None and not PY3:
name = name.encode()

return name

return adjust_encoding

ZERO = datetime.timedelta(0)
EPOCHORDINAL = datetime.datetime.utcfromtimestamp(0).toordinal()


class tzutc(datetime.tzinfo):

def utcoffset(self, dt):
Expand Down Expand Up @@ -112,6 +93,9 @@ def __init__(self):
self._dst_offset = self._std_offset

def utcoffset(self, dt):
if dt is None:
return dt

if self._isdst(dt):
return self._dst_offset
else:
Expand Down Expand Up @@ -159,11 +143,9 @@ def _isdst(self, dt):
return time.localtime(timestamp+time.timezone).tm_isdst

def __eq__(self, other):
if not isinstance(other, tzlocal):
return False
return (self._std_offset == other._std_offset and
self._dst_offset == other._dst_offset)
return True
return (isinstance(other, tzlocal) and
(self._std_offset == other._std_offset and
self._dst_offset == other._dst_offset))

def __ne__(self, other):
return not self.__eq__(other)
Expand Down Expand Up @@ -458,6 +440,9 @@ def _find_ttinfo(self, dt, laststd=0):
return self._trans_idx[idx-1]

def utcoffset(self, dt):
if dt is None:
return None

if not self._ttinfo_std:
return ZERO
return self._find_ttinfo(dt).delta
Expand Down Expand Up @@ -537,6 +522,9 @@ def __init__(self, stdabbr, stdoffset=None,
self._end_delta = end

def utcoffset(self, dt):
if dt is None:
return None

if self._isdst(dt):
return self._dst_offset
else:
Expand Down Expand Up @@ -718,6 +706,9 @@ def _find_comp(self, dt):
return lastcomp

def utcoffset(self, dt):
if dt is None:
return None

return self._find_comp(dt).tzoffsetto

def dst(self, dt):
Expand Down

0 comments on commit 4ec759b

Please sign in to comment.