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

Method closest

src/pendulum/datetime.py:495–501  ·  view source on GitHub ↗

Get the closest date to the instance.

(self, *dts: datetime.datetime)

Source from the content-addressed store, hash-verified

493
494 # Comparisons
495 def closest(self, *dts: datetime.datetime) -> Self: # type: ignore[override]
496 """
497 Get the closest date to the instance.
498 """
499 pdts = [self.instance(x) for x in dts]
500
501 return min((abs(self - dt), dt) for dt in pdts)[1]
502
503 def farthest(self, *dts: datetime.datetime) -> Self: # type: ignore[override]
504 """

Callers

nothing calls this directly

Calls 1

instanceMethod · 0.95

Tested by

no test coverage detected