diff options
-rw-r--r-- | src/isodate/__init__.py | 28 | ||||
-rw-r--r-- | src/isodate/duration.py | 26 | ||||
-rw-r--r-- | src/isodate/isoduration.py | 13 | ||||
-rw-r--r-- | src/isodate/isotime.py | 20 |
4 files changed, 44 insertions, 43 deletions
diff --git a/src/isodate/__init__.py b/src/isodate/__init__.py index 26604c2..83c8cf8 100644 --- a/src/isodate/__init__.py +++ b/src/isodate/__init__.py @@ -54,17 +54,17 @@ from isodate.isostrf import DT_BAS_WEEK_COMPLETE, DT_EXT_WEEK_COMPLETE from isodate.isostrf import D_DEFAULT, D_WEEK, D_ALT_EXT, D_ALT_BAS from isodate.isostrf import D_ALT_BAS_ORD, D_ALT_EXT_ORD -__all__ = (parse_date, date_isoformat, parse_time, time_isoformat, - parse_datetime, datetime_isoformat, parse_duration, - duration_isoformat, ISO8601Error, parse_tzinfo, - tz_isoformat, UTC, FixedOffset, LOCAL, Duration, - strftime, DATE_BAS_COMPLETE, DATE_BAS_ORD_COMPLETE, - DATE_BAS_WEEK, DATE_BAS_WEEK_COMPLETE, DATE_CENTURY, - DATE_EXT_COMPLETE, DATE_EXT_ORD_COMPLETE, DATE_EXT_WEEK, - DATE_EXT_WEEK_COMPLETE, DATE_MONTH, DATE_YEAR, - TIME_BAS_COMPLETE, TIME_BAS_MINUTE, TIME_EXT_COMPLETE, - TIME_EXT_MINUTE, TIME_HOUR, TZ_BAS, TZ_EXT, TZ_HOUR, - DT_BAS_COMPLETE, DT_EXT_COMPLETE, DT_BAS_ORD_COMPLETE, - DT_EXT_ORD_COMPLETE, DT_BAS_WEEK_COMPLETE, - DT_EXT_WEEK_COMPLETE, D_DEFAULT, D_WEEK, D_ALT_EXT, - D_ALT_BAS, D_ALT_BAS_ORD, D_ALT_EXT_ORD) +__all__ = ['parse_date', 'date_isoformat', 'parse_time', 'time_isoformat', + 'parse_datetime', 'datetime_isoformat', 'parse_duration', + 'duration_isoformat', 'ISO8601Error', 'parse_tzinfo', + 'tz_isoformat', 'UTC', 'FixedOffset', 'LOCAL', 'Duration', + 'strftime', 'DATE_BAS_COMPLETE', 'DATE_BAS_ORD_COMPLETE', + 'DATE_BAS_WEEK', 'DATE_BAS_WEEK_COMPLETE', 'DATE_CENTURY', + 'DATE_EXT_COMPLETE', 'DATE_EXT_ORD_COMPLETE', 'DATE_EXT_WEEK', + 'DATE_EXT_WEEK_COMPLETE', 'DATE_MONTH', 'DATE_YEAR', + 'TIME_BAS_COMPLETE', 'TIME_BAS_MINUTE', 'TIME_EXT_COMPLETE', + 'TIME_EXT_MINUTE', 'TIME_HOUR', 'TZ_BAS', 'TZ_EXT', 'TZ_HOUR', + 'DT_BAS_COMPLETE', 'DT_EXT_COMPLETE', 'DT_BAS_ORD_COMPLETE', + 'DT_EXT_ORD_COMPLETE', 'DT_BAS_WEEK_COMPLETE', + 'DT_EXT_WEEK_COMPLETE', 'D_DEFAULT', 'D_WEEK', 'D_ALT_EXT', + 'D_ALT_BAS', 'D_ALT_BAS_ORD', 'D_ALT_EXT_ORD'] diff --git a/src/isodate/duration.py b/src/isodate/duration.py index b44faa8..e3283b3 100644 --- a/src/isodate/duration.py +++ b/src/isodate/duration.py @@ -159,8 +159,8 @@ class Duration(object): newduration.tdelta = self.tdelta + other.tdelta return newduration if isinstance(other, (date, datetime)): - if (not(float(self.years).is_integer() - and float(self.months).is_integer())): + if (not(float(self.years).is_integer() and + float(self.months).is_integer())): raise ValueError('fractional years or months not supported' ' for date calculations') newmonth = other.month + self.months @@ -185,8 +185,8 @@ class Duration(object): newduration.tdelta = self.tdelta + other return newduration if isinstance(other, (date, datetime)): - if (not(float(self.years).is_integer() - and float(self.months).is_integer())): + if (not(float(self.years).is_integer() and + float(self.months).is_integer())): raise ValueError('fractional years or months not supported' ' for date calculations') newmonth = other.month + self.months @@ -226,8 +226,8 @@ class Duration(object): ''' # print '__rsub__:', self, other if isinstance(other, (date, datetime)): - if (not(float(self.years).is_integer() - and float(self.months).is_integer())): + if (not(float(self.years).is_integer() and + float(self.months).is_integer())): raise ValueError('fractional years or months not supported' ' for date calculations') newmonth = other.month - self.months @@ -258,8 +258,8 @@ class Duration(object): if not isinstance(other, Duration): return NotImplemented if (((self.years * 12 + self.months) == - (other.years * 12 + other.months) - and self.tdelta == other.tdelta)): + (other.years * 12 + other.months) and + self.tdelta == other.tdelta)): return True return False @@ -268,15 +268,15 @@ class Duration(object): If the years, month part or the timedelta part is not equal, then the two Durations are considered not equal. ''' - if ((isinstance(other, timedelta) - and self.years == 0 - and self.months == 0)): + if ((isinstance(other, timedelta) and + self.years == 0 and + self.months == 0)): return self.tdelta != other if not isinstance(other, Duration): return NotImplemented if (((self.years * 12 + self.months) != - (other.years * 12 + other.months) - or self.tdelta != other.tdelta)): + (other.years * 12 + other.months) or + self.tdelta != other.tdelta)): return True return False diff --git a/src/isodate/isoduration.py b/src/isodate/isoduration.py index af44661..6da69f5 100644 --- a/src/isodate/isoduration.py +++ b/src/isodate/isoduration.py @@ -41,7 +41,8 @@ from isodate.isostrf import strftime, D_DEFAULT ISO8601_PERIOD_REGEX = re.compile( r"^(?P<sign>[+-])?" - r"P(?P<years>[0-9]+([,.][0-9]+)?Y)?" + r"P(?!\b)" + r"(?P<years>[0-9]+([,.][0-9]+)?Y)?" r"(?P<months>[0-9]+([,.][0-9]+)?M)?" r"(?P<weeks>[0-9]+([,.][0-9]+)?W)?" r"(?P<days>[0-9]+([,.][0-9]+)?D)?" @@ -136,11 +137,11 @@ def duration_isoformat(tduration, format=D_DEFAULT): ''' # TODO: implement better decision for negative Durations. # should be done in Duration class in consistent way with timedelta. - if (((isinstance(tduration, Duration) - and (tduration.years < 0 or tduration.months < 0 - or tduration.tdelta < timedelta(0))) - or (isinstance(tduration, timedelta) - and (tduration < timedelta(0))))): + if (((isinstance(tduration, Duration) and + (tduration.years < 0 or tduration.months < 0 or + tduration.tdelta < timedelta(0))) or + (isinstance(tduration, timedelta) and + (tduration < timedelta(0))))): ret = '-' else: ret = '' diff --git a/src/isodate/isotime.py b/src/isodate/isotime.py index 2b268d0..9650cda 100644 --- a/src/isodate/isotime.py +++ b/src/isodate/isotime.py @@ -71,25 +71,25 @@ def build_time_regexps(): # hh:mm:ss.ss ... extended format TIME_REGEX_CACHE.append(re.compile(r"T?(?P<hour>[0-9]{2}):" r"(?P<minute>[0-9]{2}):" - r"(?P<second>[0-9]{2}([,.][0-9]+)?)" - + TZ_REGEX)) + r"(?P<second>[0-9]{2}" + r"([,.][0-9]+)?)" + TZ_REGEX)) # hhmmss.ss ... basic format TIME_REGEX_CACHE.append(re.compile(r"T?(?P<hour>[0-9]{2})" r"(?P<minute>[0-9]{2})" - r"(?P<second>[0-9]{2}([,.][0-9]+)?)" - + TZ_REGEX)) + r"(?P<second>[0-9]{2}" + r"([,.][0-9]+)?)" + TZ_REGEX)) # 2. reduced accuracy: # hh:mm.mm ... extended format TIME_REGEX_CACHE.append(re.compile(r"T?(?P<hour>[0-9]{2}):" - r"(?P<minute>[0-9]{2}([,.][0-9]+)?)" - + TZ_REGEX)) + r"(?P<minute>[0-9]{2}" + r"([,.][0-9]+)?)" + TZ_REGEX)) # hhmm.mm ... basic format TIME_REGEX_CACHE.append(re.compile(r"T?(?P<hour>[0-9]{2})" - r"(?P<minute>[0-9]{2}([,.][0-9]+)?)" - + TZ_REGEX)) + r"(?P<minute>[0-9]{2}" + r"([,.][0-9]+)?)" + TZ_REGEX)) # hh.hh ... basic format - TIME_REGEX_CACHE.append(re.compile(r"T?(?P<hour>[0-9]{2}([,.][0-9]+)?)" - + TZ_REGEX)) + TIME_REGEX_CACHE.append(re.compile(r"T?(?P<hour>[0-9]{2}" + r"([,.][0-9]+)?)" + TZ_REGEX)) return TIME_REGEX_CACHE |