| 2247 | return NotImplemented |
| 2248 | |
| 2249 | def _cmp(self, other, allow_mixed=False): |
| 2250 | assert isinstance(other, datetime) |
| 2251 | mytz = self._tzinfo |
| 2252 | ottz = other._tzinfo |
| 2253 | myoff = otoff = None |
| 2254 | |
| 2255 | if mytz is ottz: |
| 2256 | base_compare = True |
| 2257 | else: |
| 2258 | myoff = self.utcoffset() |
| 2259 | otoff = other.utcoffset() |
| 2260 | # Assume that allow_mixed means that we are called from __eq__ |
| 2261 | if allow_mixed: |
| 2262 | if myoff != self.replace(fold=not self.fold).utcoffset(): |
| 2263 | return 2 |
| 2264 | if otoff != other.replace(fold=not other.fold).utcoffset(): |
| 2265 | return 2 |
| 2266 | base_compare = myoff == otoff |
| 2267 | |
| 2268 | if base_compare: |
| 2269 | return _cmp((self._year, self._month, self._day, |
| 2270 | self._hour, self._minute, self._second, |
| 2271 | self._microsecond), |
| 2272 | (other._year, other._month, other._day, |
| 2273 | other._hour, other._minute, other._second, |
| 2274 | other._microsecond)) |
| 2275 | if myoff is None or otoff is None: |
| 2276 | if allow_mixed: |
| 2277 | return 2 # arbitrary non-zero value |
| 2278 | else: |
| 2279 | raise TypeError("cannot compare naive and aware datetimes") |
| 2280 | # XXX What follows could be done more efficiently... |
| 2281 | diff = self - other # this will take offsets into account |
| 2282 | if diff.days < 0: |
| 2283 | return -1 |
| 2284 | return diff and 1 or 0 |
| 2285 | |
| 2286 | def __add__(self, other): |
| 2287 | "Add a datetime and a timedelta." |