1.1 --- a/imiptools/dates.py Sun Aug 16 00:36:05 2015 +0200
1.2 +++ b/imiptools/dates.py Sun Aug 16 00:38:43 2015 +0200
1.3 @@ -473,6 +473,28 @@
1.4
1.5 # Time corrections.
1.6
1.7 +class ValidityError(Exception):
1.8 + pass
1.9 +
1.10 +def check_resolution(dt, resolution):
1.11 +
1.12 + "Check the datetime 'dt' against the 'resolution' list."
1.13 +
1.14 + if not isinstance(dt, datetime):
1.15 + raise ValidityError
1.16 +
1.17 + hours, minutes, seconds = resolution
1.18 + errors = []
1.19 +
1.20 + if hours and dt.hour not in hours:
1.21 + errors.append("hour")
1.22 + if minutes and dt.minute not in minutes:
1.23 + errors.append("minute")
1.24 + if seconds and dt.second not in seconds:
1.25 + errors.append("second")
1.26 +
1.27 + return errors
1.28 +
1.29 def correct_datetime(dt, resolution):
1.30
1.31 "Correct 'dt' using the given 'resolution' details."
1.32 @@ -528,12 +550,13 @@
1.33 else:
1.34 carry = 0
1.35
1.36 - i = bisect_left(values, v)
1.37 - if i < len(values):
1.38 - v = values[i]
1.39 - else:
1.40 - v = values[0]
1.41 - carry = 1
1.42 + if values:
1.43 + i = bisect_left(values, v)
1.44 + if i < len(values):
1.45 + v = values[i]
1.46 + else:
1.47 + v = values[0]
1.48 + carry = 1
1.49
1.50 corrected.append(v)
1.51