Skip to content

Fix #772: Speed up DateTime.to_clock_time #781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions neo4j/time/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2642,14 +2642,9 @@ def to_clock_time(self):
:rtype: ClockTime
"""
total_seconds = 0
for year in range(1, self.year):
total_seconds += 86400 * DAYS_IN_YEAR[year]
for month in range(1, self.month):
total_seconds += 86400 * Date.days_in_month(self.year, month)
total_seconds += 86400 * (self.day - 1)
seconds, nanoseconds = divmod(self.__time.ticks_ns, NANO_SECONDS)
return ClockTime(total_seconds + seconds, nanoseconds)
ordinal_seconds = 86400 * (self.__date.to_ordinal() - 1)
time_seconds, nanoseconds = divmod(self.__time.ticks_ns, NANO_SECONDS)
return ClockTime(ordinal_seconds + time_seconds, nanoseconds)

def to_native(self):
"""Convert to a native Python :class:`datetime.datetime` value.
Expand Down