Skip to content

Commit 638f000

Browse files
committed
Fix RPG timestamp bug
1 parent d74328b commit 638f000

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

cloudnetpy/instruments/rpg.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,14 @@ def linear_to_db(self, variables_to_log):
328328
self.data[name].lin2db()
329329

330330
def _get_date(self):
331-
epoch = datetime.datetime(2001, 1, 1).timestamp()
332331
time_median = float(ma.median(self.raw_data['time']))
333-
time_median += epoch
334-
return datetime.datetime.utcfromtimestamp(time_median).strftime('%Y %m %d').split()
332+
return _get_rpg_time(time_median)
333+
334+
335+
def _get_rpg_time(timestamp: float) -> list:
336+
epoch = datetime.datetime(2001, 1, 1).timestamp()
337+
timestamp += epoch
338+
return datetime.datetime.fromtimestamp(timestamp).strftime('%Y %m %d').split()
335339

336340

337341
def _save_rpg(rpg, output_file, keep_uuid):

cloudnetpy/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
MAJOR = 1
22
MINOR = 3
3-
PATCH = 1
3+
PATCH = 2
44
__version__ = '%d.%d.%d' % (MAJOR, MINOR, PATCH)

tests/unit/test_rpg.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,10 @@ def test_2(self):
3232
with pytest.raises(AssertionError):
3333
assert_array_equal(rpg._reduce_header(self.header),
3434
{'a': 1, 'b': 2, 'c': 3})
35+
36+
37+
def test_get_rpg_time():
38+
secs_in_day = 24 * 60 * 60
39+
assert rpg._get_rpg_time(0) == ['2001', '01', '01']
40+
assert rpg._get_rpg_time(secs_in_day - 1) == ['2001', '01', '01']
41+
assert rpg._get_rpg_time(secs_in_day) == ['2001', '01', '02']

0 commit comments

Comments
 (0)