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

Method closest

src/pendulum/time.py:65–75  ·  view source on GitHub ↗

Get the closest time from the instance.

(self, dt1: Time | time, dt2: Time | time)

Source from the content-addressed store, hash-verified

63 # Comparisons
64
65 def closest(self, dt1: Time | time, dt2: Time | time) -> Self:
66 """
67 Get the closest time from the instance.
68 """
69 dt1 = self.__class__(dt1.hour, dt1.minute, dt1.second, dt1.microsecond)
70 dt2 = self.__class__(dt2.hour, dt2.minute, dt2.second, dt2.microsecond)
71
72 if self.diff(dt1).in_seconds() < self.diff(dt2).in_seconds():
73 return dt1
74
75 return dt2
76
77 def farthest(self, dt1: Time | time, dt2: Time | time) -> Self:
78 """

Callers 6

test_closestFunction · 0.45
test_closest_with_equalsFunction · 0.45
test_closestFunction · 0.45
test_closest_with_timeFunction · 0.45
test_closest_with_equalsFunction · 0.45

Calls 2

diffMethod · 0.95
in_secondsMethod · 0.80

Tested by 6

test_closestFunction · 0.36
test_closest_with_equalsFunction · 0.36
test_closestFunction · 0.36
test_closest_with_timeFunction · 0.36
test_closest_with_equalsFunction · 0.36