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

Method add

src/pendulum/datetime.py:559–640  ·  view source on GitHub ↗

Add a duration to the instance. If we're adding units of variable length (i.e., years, months), move forward from current time, otherwise move forward from utc, for accuracy when moving across DST boundaries.

(
        self,
        years: int = 0,
        months: int = 0,
        weeks: int = 0,
        days: int = 0,
        hours: int = 0,
        minutes: int = 0,
        seconds: float = 0,
        microseconds: int = 0,
    )

Source from the content-addressed store, hash-verified

557 # ADDITIONS AND SUBSTRACTIONS
558
559 def add(
560 self,
561 years: int = 0,
562 months: int = 0,
563 weeks: int = 0,
564 days: int = 0,
565 hours: int = 0,
566 minutes: int = 0,
567 seconds: float = 0,
568 microseconds: int = 0,
569 ) -> Self:
570 """
571 Add a duration to the instance.
572
573 If we're adding units of variable length (i.e., years, months),
574 move forward from current time, otherwise move forward from utc, for accuracy
575 when moving across DST boundaries.
576 """
577 units_of_variable_length = any([years, months, weeks, days])
578
579 current_dt = datetime.datetime(
580 self.year,
581 self.month,
582 self.day,
583 self.hour,
584 self.minute,
585 self.second,
586 self.microsecond,
587 )
588 if not units_of_variable_length:
589 offset = self.utcoffset()
590 if offset:
591 current_dt = current_dt - offset
592
593 dt = add_duration(
594 current_dt,
595 years=years,
596 months=months,
597 weeks=weeks,
598 days=days,
599 hours=hours,
600 minutes=minutes,
601 seconds=seconds,
602 microseconds=microseconds,
603 )
604
605 if units_of_variable_length or self.tz is None:
606 return self.__class__.create(
607 dt.year,
608 dt.month,
609 dt.day,
610 dt.hour,
611 dt.minute,
612 dt.second,
613 dt.microsecond,
614 tz=self.tz,
615 )
616

Callers 7

subtractMethod · 0.95
_add_timedelta_Method · 0.95
averageMethod · 0.95
test_multiplyFunction · 0.95
test_divideFunction · 0.95
test_floor_divideFunction · 0.95
nextMethod · 0.45

Calls 5

add_durationFunction · 0.90
utcoffsetMethod · 0.80
createMethod · 0.80
datetimeMethod · 0.45
convertMethod · 0.45

Tested by 3

test_multiplyFunction · 0.76
test_divideFunction · 0.76
test_floor_divideFunction · 0.76