| 2290 | return NotImplemented |
| 2291 | |
| 2292 | def _cmp(self, other, allow_mixed=False): |
| 2293 | assert isinstance(other, datetime) |
| 2294 | mytz = self._tzinfo |
| 2295 | ottz = other._tzinfo |
| 2296 | myoff = otoff = None |
| 2297 | |
| 2298 | if mytz is ottz: |
| 2299 | base_compare = True |
| 2300 | else: |
| 2301 | myoff = self.utcoffset() |
| 2302 | otoff = other.utcoffset() |
| 2303 | # Assume that allow_mixed means that we are called from __eq__ |
| 2304 | if allow_mixed: |
| 2305 | if myoff != self.replace(fold=not self.fold).utcoffset(): |
| 2306 | return 2 |
| 2307 | if otoff != other.replace(fold=not other.fold).utcoffset(): |
| 2308 | return 2 |
| 2309 | base_compare = myoff == otoff |
| 2310 | |
| 2311 | if base_compare: |
| 2312 | return _cmp((self._year, self._month, self._day, |
| 2313 | self._hour, self._minute, self._second, |
| 2314 | self._microsecond), |
| 2315 | (other._year, other._month, other._day, |
| 2316 | other._hour, other._minute, other._second, |
| 2317 | other._microsecond)) |
| 2318 | if myoff is None or otoff is None: |
| 2319 | if allow_mixed: |
| 2320 | return 2 # arbitrary non-zero value |
| 2321 | else: |
| 2322 | raise TypeError("cannot compare naive and aware datetimes") |
| 2323 | # XXX What follows could be done more efficiently... |
| 2324 | diff = self - other # this will take offsets into account |
| 2325 | if diff.days < 0: |
| 2326 | return -1 |
| 2327 | return diff and 1 or 0 |
| 2328 | |
| 2329 | def __add__(self, other): |
| 2330 | "Add a datetime and a timedelta." |