MCPcopy Index your code
hub / github.com/python-pendulum/pendulum / __new__

Method __new__

src/pendulum/duration.py:486–522  ·  view source on GitHub ↗
(
        cls,
        days: float = 0,
        seconds: float = 0,
        microseconds: float = 0,
        milliseconds: float = 0,
        minutes: float = 0,
        hours: float = 0,
        weeks: float = 0,
        years: float = 0,
        months: float = 0,
    )

Source from the content-addressed store, hash-verified

484 """
485
486 def __new__(
487 cls,
488 days: float = 0,
489 seconds: float = 0,
490 microseconds: float = 0,
491 milliseconds: float = 0,
492 minutes: float = 0,
493 hours: float = 0,
494 weeks: float = 0,
495 years: float = 0,
496 months: float = 0,
497 ) -> AbsoluteDuration:
498 if not isinstance(years, int) or not isinstance(months, int):
499 raise ValueError("Float year and months are not supported")
500
501 self = timedelta.__new__(
502 cls, days, seconds, microseconds, milliseconds, minutes, hours, weeks
503 )
504
505 # We need to compute the total_seconds() value
506 # on a native timedelta object
507 delta = timedelta(
508 days, seconds, microseconds, milliseconds, minutes, hours, weeks
509 )
510
511 # Intuitive normalization
512 self._total = delta.total_seconds()
513 total = abs(self._total)
514
515 self._microseconds = round(total % 1 * 1e6)
516 days, self._seconds = divmod(int(total), SECONDS_PER_DAY)
517 self._days = abs(days + years * 365 + months * 30)
518 self._weeks, self._remaining_days = divmod(days, 7)
519 self._months = abs(months)
520 self._years = abs(years)
521
522 return self
523
524 def total_seconds(self) -> float:
525 return abs(self._total)

Callers

nothing calls this directly

Calls 2

__new__Method · 0.45
total_secondsMethod · 0.45

Tested by

no test coverage detected