From f7df44998934c94f43e93d1c2414d80e99414b02 Mon Sep 17 00:00:00 2001 From: Jeremy M Fee <jmfee@usgs.gov> Date: Wed, 7 Oct 2020 18:47:17 +0000 Subject: [PATCH] Update `usecs` value to match variable name. Add test for round-to-next-second branch. --- geomagio/TimeseriesUtility.py | 4 ++-- test/TimeseriesUtility_test.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/geomagio/TimeseriesUtility.py b/geomagio/TimeseriesUtility.py index 9aa99a895..adecbcb06 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 512db7edf..a664b2e28 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): -- GitLab