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

Method average

src/pendulum/datetime.py:1171–1184  ·  view source on GitHub ↗

Modify the current instance to the average of a given instance (default now) and the current instance.

(  # type: ignore[override]
        self, dt: datetime.datetime | None = None
    )

Source from the content-addressed store, hash-verified

1169 return self.on(self.year, dt.month, dt.day).start_of("day")
1170
1171 def average( # type: ignore[override]
1172 self, dt: datetime.datetime | None = None
1173 ) -> Self:
1174 """
1175 Modify the current instance to the average
1176 of a given instance (default now) and the current instance.
1177 """
1178 if dt is None:
1179 dt = self.now(self.tz)
1180
1181 diff = self.diff(dt, False)
1182 return self.add(
1183 microseconds=(diff.in_seconds() * 1000000 + diff.microseconds) // 2
1184 )
1185
1186 @overload # type: ignore[override]
1187 def __sub__(self, other: datetime.timedelta) -> Self: ...

Callers

nothing calls this directly

Calls 4

nowMethod · 0.95
diffMethod · 0.95
addMethod · 0.95
in_secondsMethod · 0.80

Tested by

no test coverage detected