diff --git a/geomagio/TimeseriesUtility.py b/geomagio/TimeseriesUtility.py index 9aa99a895cb99f28fbfb70bef33e16add2aae32d..adecbcb06cfeebed720fc4e313d0da9fe717686c 100644 --- a/geomagio/TimeseriesUtility.py +++ b/geomagio/TimeseriesUtility.py @@ -550,9 +550,9 @@ def round_usecs(time): time: UTCDateTime time containing rounded(or non-rounded) microsecond values """ - usecs = time.microsecond / 1000 + usecs = time.microsecond # round microseconds to nearest millisecond - rounded_usecs = int(round(usecs, 0)) * 1000 + rounded_usecs = int(round(usecs / 1000, 0)) * 1000 # reset microseconds to 0 at top of second, add second to input time if rounded_usecs > 999000: rounded_usecs = 0 diff --git a/test/TimeseriesUtility_test.py b/test/TimeseriesUtility_test.py index 512db7edf871b8a2aac2a3152f5916bafc3dbfc1..a664b2e28a718e42e57553ca9c57d29aa02bae15 100644 --- a/test/TimeseriesUtility_test.py +++ b/test/TimeseriesUtility_test.py @@ -460,6 +460,9 @@ def test_round_usecs(): # test case with residual microseconds time = TimeseriesUtility.round_usecs(UTCDateTime("2020-10-07T00:00:00.995600Z")) assert_equal(time, UTCDateTime("2020-10-07T00:00:00.996000Z")) + # test case with rounding to next second + time = TimeseriesUtility.round_usecs(UTCDateTime("2020-10-07T00:00:00.9995Z")) + assert_equal(time, UTCDateTime("2020-10-07T00:00:01.000Z")) def _create_trace(data, channel, starttime, delta=60.0):