Skip to content

Commit

Permalink
Optimise addition of truncated TimePoint
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie committed Jan 16, 2024
1 parent 3ea9e1d commit f85ef28
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions metomi/isodatetime/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1511,17 +1511,22 @@ def add_truncated(self, other: 'TimePoint') -> 'TimePoint':
if second_of_minute is not None or minute_of_hour is not None:
new = new.to_hour_minute_second()
if second_of_minute is not None:
while new._second_of_minute != second_of_minute:
new._second_of_minute += 1.0
new._tick_over()
new._second_of_minute += (
(second_of_minute - new._second_of_minute)
% CALENDAR.SECONDS_IN_MINUTE
)
new._tick_over()
if minute_of_hour is not None:
while new._minute_of_hour != minute_of_hour:
new._minute_of_hour += 1.0
new._tick_over()
new._minute_of_hour += (
(minute_of_hour - new._minute_of_hour)
% CALENDAR.MINUTES_IN_HOUR
)
new._tick_over()
if hour_of_day is not None:
while new._hour_of_day != hour_of_day:
new._hour_of_day += 1.0
new._tick_over()
new._hour_of_day += (
(hour_of_day - new._hour_of_day) % CALENDAR.HOURS_IN_DAY
)
new._tick_over()

if day_of_week is not None:
new = new.to_week_date()
Expand Down

0 comments on commit f85ef28

Please sign in to comment.