Truncate the delorian object to the nearest s (second, minute, hour, day, month, year) This is a destructive method, modifies the internal datetime object associated with the Delorean object. .. testsetup:: from datetime import datetime
(self, s)
| 334 | return self._tzinfo |
| 335 | |
| 336 | def truncate(self, s): |
| 337 | """ |
| 338 | Truncate the delorian object to the nearest s |
| 339 | (second, minute, hour, day, month, year) |
| 340 | |
| 341 | This is a destructive method, modifies the internal datetime |
| 342 | object associated with the Delorean object. |
| 343 | |
| 344 | .. testsetup:: |
| 345 | |
| 346 | from datetime import datetime |
| 347 | from delorean import Delorean |
| 348 | |
| 349 | .. doctest:: |
| 350 | |
| 351 | >>> d = Delorean(datetime(2015, 1, 1, 12, 10), timezone='US/Pacific') |
| 352 | >>> d.truncate('hour') |
| 353 | Delorean(datetime=datetime.datetime(2015, 1, 1, 12, 0), timezone='US/Pacific') |
| 354 | |
| 355 | """ |
| 356 | if s == 'second': |
| 357 | self._dt = self._dt.replace(microsecond=0) |
| 358 | elif s == 'minute': |
| 359 | self._dt = self._dt.replace(second=0, microsecond=0) |
| 360 | elif s == 'hour': |
| 361 | self._dt = self._dt.replace(minute=0, second=0, microsecond=0) |
| 362 | elif s == 'day': |
| 363 | self._dt = self._dt.replace(hour=0, minute=0, second=0, microsecond=0) |
| 364 | elif s == 'month': |
| 365 | self._dt = self._dt.replace(day=1, hour=0, minute=0, second=0, microsecond=0) |
| 366 | elif s == 'year': |
| 367 | self._dt = self._dt.replace(month=1, day=1, hour=0, minute=0, second=0, microsecond=0) |
| 368 | else: |
| 369 | raise ValueError("Invalid truncation level") |
| 370 | |
| 371 | return self |
| 372 | |
| 373 | @property |
| 374 | def naive(self): |