Skip to content

Commit

Permalink
Issue metomi#80 invert order of checks when ticking time
Browse files Browse the repository at this point in the history
  • Loading branch information
kinow committed Oct 10, 2018
1 parent 197de94 commit 02ac23a
Showing 1 changed file with 41 additions and 45 deletions.
86 changes: 41 additions & 45 deletions isodatetime/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,62 +1162,58 @@ def add_truncated(self, year_of_century=None, year_of_decade=None,
minute_of_hour=None, second_of_minute=None):
"""Combine this TimePoint with truncated time properties."""
new = self.copy()
if hour_of_day is not None and minute_of_hour is None:
minute_of_hour = 0
if ((hour_of_day is not None or minute_of_hour is not None) and
second_of_minute is None):
second_of_minute = 0
if second_of_minute is not None or minute_of_hour is not None:
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()
if minute_of_hour is not None:
while new.minute_of_hour != minute_of_hour:
new.minute_of_hour += 1.0
new.tick_over()
if hour_of_day is not None:
while new.hour_of_day != hour_of_day:
new.hour_of_day += 1.0

if year_of_century is not None:
new.to_calendar_date()
new_year_of_century = new.year % 100
while new_year_of_century != year_of_century:
new.year += 1
new_year_of_century = new.year % 100
if year_of_decade is not None:
new.to_calendar_date()
new_year_of_decade = new.year % 10
while new_year_of_decade != year_of_decade:
new.year += 1
new_year_of_decade = new.year % 10
if month_of_year is not None:
new.to_calendar_date()
while new.month_of_year != month_of_year:
new.month_of_year += 1
new.tick_over()
if day_of_week is not None:
if week_of_year is not None:
new.to_week_date()
while new.day_of_week != day_of_week:
new.day_of_week += 1
while new.week_of_year != week_of_year:
new.week_of_year += 1
new.tick_over()
if day_of_month is not None:
new.to_calendar_date()
while new.day_of_month != day_of_month:
new.day_of_month += 1
new.tick_over()
if day_of_year is not None:
new.to_ordinal_date()
while new.day_of_year != day_of_year:
new.day_of_year += 1
new.tick_over()
if week_of_year is not None:
if day_of_week is not None:
new.to_week_date()
while new.week_of_year != week_of_year:
new.week_of_year += 1
while new.day_of_week != day_of_week:
new.day_of_week += 1
new.tick_over()
if month_of_year is not None:
new.to_calendar_date()
while new.month_of_year != month_of_year:
new.month_of_year += 1
if hour_of_day is not None:
while new.hour_of_day != hour_of_day:
new.hour_of_day += 1.0
new.tick_over()
if year_of_decade is not None:
new.to_calendar_date()
new_year_of_decade = new.year % 10
while new_year_of_decade != year_of_decade:
new.year += 1
new_year_of_decade = new.year % 10
if year_of_century is not None:
new.to_calendar_date()
new_year_of_century = new.year % 100
while new_year_of_century != year_of_century:
new.year += 1
new_year_of_century = new.year % 100
if minute_of_hour is not None:
while new.minute_of_hour != minute_of_hour:
new.minute_of_hour += 1.0
new.tick_over()
if second_of_minute is not None:
while new.second_of_minute != second_of_minute:
new.second_of_minute += 1.0
new.tick_over()
if second_of_minute is not None or minute_of_hour is not None:
new.to_hour_minute_second()
if ((hour_of_day is not None or minute_of_hour is not None) and
second_of_minute is None):
second_of_minute = 0
if hour_of_day is not None and minute_of_hour is None:
minute_of_hour = 0
return new

def __add__(self, other, no_copy=False):
Expand Down

0 comments on commit 02ac23a

Please sign in to comment.