pytroll / pytroll-collectors

Collector modules for Pytroll
GNU General Public License v3.0
3 stars 18 forks source link

align_time does not round sub-second time #94

Open gerritholl opened 3 years ago

gerritholl commented 3 years ago

The function pytroll_collectors.helper_functions.align_time is supposed to round times. However, if there is a subsecond timestamp present, this one gets kept and the time is not rounded.

This script:

from datetime import datetime, timedelta
from pytroll_collectors.helper_functions import align_time

t = datetime(2015, 10, 21, 22, 29, 0, 12345)
t2 = align_time(t, timedelta(minutes=5))
print(t2)
assert t2 == datetime(2015, 10, 21, 22, 25, 0, 0)

results in an AssertionError:

2015-10-21 22:25:00.012345
Traceback (most recent call last):
  File "/home/gholl/checkouts/protocode/mwe/bad-align.py", line 7, in <module>
    assert t2 == datetime(2015, 10, 21, 22, 25, 0, 0)
AssertionError

because the result of align_time is datetime(2015, 10, 21, 22, 25, 0, 12345) rather than datetime(2015, 10, 21, 22, 25, 0, 0).