in src/pycalendar/datetime.py [0:0]
def normalise(self):
# Normalise seconds
normalised_secs = self.mSeconds % 60
adjustment_mins = self.mSeconds / 60
if normalised_secs < 0:
normalised_secs += 60
adjustment_mins -= 1
self.mSeconds = normalised_secs
self.mMinutes += adjustment_mins
# Normalise minutes
normalised_mins = self.mMinutes % 60
adjustment_hours = self.mMinutes / 60
if normalised_mins < 0:
normalised_mins += 60
adjustment_hours -= 1
self.mMinutes = normalised_mins
self.mHours += adjustment_hours
# Normalise hours
normalised_hours = self.mHours % 24
adjustment_days = self.mHours / 24
if normalised_hours < 0:
normalised_hours += 24
adjustment_days -= 1
self.mHours = normalised_hours
self.mDay += adjustment_days
# Wipe the time if date only
if self.mDateOnly:
self.mSeconds = self.mMinutes = self.mHours = 0
# Adjust the month first, since the day adjustment is month dependent
# Normalise month
normalised_month = ((self.mMonth - 1) % 12) + 1
adjustment_year = (self.mMonth - 1) / 12
if (normalised_month - 1) < 0:
normalised_month += 12
adjustment_year -= 1
self.mMonth = normalised_month
self.mYear += adjustment_year
# Now do days
if self.mDay > 0:
while self.mDay > utils.daysInMonth(self.mMonth, self.mYear):
self.mDay -= utils.daysInMonth(self.mMonth, self.mYear)
self.mMonth += 1
if self.mMonth > 12:
self.mMonth = 1
self.mYear += 1
else:
while self.mDay <= 0:
self.mMonth -= 1
if self.mMonth < 1:
self.mMonth = 12
self.mYear -= 1
self.mDay += utils.daysInMonth(self.mMonth, self.mYear)
# Always invalidate posix time cache
self.changed()