Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(244221)

Side by Side Diff: Lib/datetime.py

Issue 17267: datetime.time support for '+' and 'now'
Patch Set: Created 6 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/test/datetimetester.py » ('j') | Modules/_datetimemodule.c » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Concrete date/time and related types -- prototype implemented in Python. 1 """Concrete date/time and related types -- prototype implemented in Python.
2 2
3 See http://www.zope.org/Members/fdrake/DateTimeWiki/FrontPage 3 See http://www.zope.org/Members/fdrake/DateTimeWiki/FrontPage
4 4
5 See also http://dir.yahoo.com/Reference/calendars/ 5 See also http://dir.yahoo.com/Reference/calendars/
6 6
7 For a primer on DST, including many current DST rules, see 7 For a primer on DST, including many current DST rules, see
8 http://webexhibits.org/daylightsaving/ 8 http://webexhibits.org/daylightsaving/
9 9
10 For more about DST than you ever wanted to know, see 10 For more about DST than you ever wanted to know, see
(...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 1051
1052 @property 1052 @property
1053 def microsecond(self): 1053 def microsecond(self):
1054 """microsecond (0-999999)""" 1054 """microsecond (0-999999)"""
1055 return self._microsecond 1055 return self._microsecond
1056 1056
1057 @property 1057 @property
1058 def tzinfo(self): 1058 def tzinfo(self):
1059 """timezone info object""" 1059 """timezone info object"""
1060 return self._tzinfo 1060 return self._tzinfo
1061
1062 def __add__(self, other):
1063 "Add a time and a timedelta"
1064 if not isinstance(other, timedelta):
1065 return NotImplemented
1066
1067 delta = timedelta(hours=self._hour,
1068 minutes=self._minute,
1069 seconds=self._second,
1070 microseconds=self._microsecond)
1071
1072 delta += other
1073 hour, rem = divmod(delta.seconds, 3600)
1074 minute, second = divmod(rem, 60)
1075 if delta.days <= _MAXORDINAL:
1076 return time(hour, minute, second,
1077 delta.microseconds,
1078 tzinfo=self._tzinfo)
1079 raise OverflowError("result out of range")
1061 1080
1062 # Standard conversions, __hash__ (and helpers) 1081 # Standard conversions, __hash__ (and helpers)
1063 1082
1064 # Comparisons of time objects with other. 1083 # Comparisons of time objects with other.
1065 1084
1066 def __eq__(self, other): 1085 def __eq__(self, other):
1067 if isinstance(other, time): 1086 if isinstance(other, time):
1068 return self._cmp(other, allow_mixed=True) == 0 1087 return self._cmp(other, allow_mixed=True) == 0
1069 else: 1088 else:
1070 return False 1089 return False
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after
2138 _check_time_fields, _check_tzinfo_arg, _check_tzname, 2157 _check_time_fields, _check_tzinfo_arg, _check_tzname,
2139 _check_utc_offset, _cmp, _cmperror, _date_class, _days_before_month, 2158 _check_utc_offset, _cmp, _cmperror, _date_class, _days_before_month,
2140 _days_before_year, _days_in_month, _format_time, _is_leap, 2159 _days_before_year, _days_in_month, _format_time, _is_leap,
2141 _isoweek1monday, _math, _ord2ymd, _time, _time_class, _tzinfo_class, 2160 _isoweek1monday, _math, _ord2ymd, _time, _time_class, _tzinfo_class,
2142 _wrap_strftime, _ymd2ord) 2161 _wrap_strftime, _ymd2ord)
2143 # XXX Since import * above excludes names that start with _, 2162 # XXX Since import * above excludes names that start with _,
2144 # docstring does not get overwritten. In the future, it may be 2163 # docstring does not get overwritten. In the future, it may be
2145 # appropriate to maintain a single module level docstring and 2164 # appropriate to maintain a single module level docstring and
2146 # remove the following line. 2165 # remove the following line.
2147 from _datetime import __doc__ 2166 from _datetime import __doc__
OLDNEW
« no previous file with comments | « no previous file | Lib/test/datetimetester.py » ('j') | Modules/_datetimemodule.c » ('J')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+