Shifts the timezone from the current timezone to the specified timezone associated with the Delorean object, modifying the Delorean object and returning the modified object. .. testsetup:: from datetime import datetime from delorean import Delorean
(self, timezone)
| 464 | return self._dt.replace(hour=23, minute=59, second=59, microsecond=999999) |
| 465 | |
| 466 | def shift(self, timezone): |
| 467 | """ |
| 468 | Shifts the timezone from the current timezone to the specified timezone associated with the Delorean object, |
| 469 | modifying the Delorean object and returning the modified object. |
| 470 | |
| 471 | .. testsetup:: |
| 472 | |
| 473 | from datetime import datetime |
| 474 | from delorean import Delorean |
| 475 | |
| 476 | .. doctest:: |
| 477 | |
| 478 | >>> d = Delorean(datetime(2015, 1, 1), timezone='US/Pacific') |
| 479 | >>> d.shift('UTC') |
| 480 | Delorean(datetime=datetime.datetime(2015, 1, 1, 8, 0), timezone='UTC') |
| 481 | |
| 482 | """ |
| 483 | try: |
| 484 | self._tzinfo = pytz.timezone(timezone) |
| 485 | except pytz.UnknownTimeZoneError: |
| 486 | raise DeloreanInvalidTimezone('Provide a valid timezone') |
| 487 | self._dt = self._tzinfo.normalize(self._dt.astimezone(self._tzinfo)) |
| 488 | self._tzinfo = self._dt.tzinfo |
| 489 | return self |
| 490 | |
| 491 | @property |
| 492 | def epoch(self): |