From 1f613a79ec6baced0bfcb34088d6ef58f52e81a2 Mon Sep 17 00:00:00 2001 From: Dougie Squire Date: Fri, 1 Mar 2024 15:20:09 +1100 Subject: [PATCH] parse start_ and end_date even for fx freq if there is a time coordinate --- src/access_nri_intake/source/utils.py | 12 ++++++++++-- tests/test_source_utils.py | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/access_nri_intake/source/utils.py b/src/access_nri_intake/source/utils.py index 034e0a0d..481d57b7 100644 --- a/src/access_nri_intake/source/utils.py +++ b/src/access_nri_intake/source/utils.py @@ -80,8 +80,8 @@ def _todate(t): return cftime.num2date(t, time_var.units, calendar=time_var.calendar) time_format = "%Y-%m-%d, %H:%M:%S" - start_date = "none" - end_date = "none" + ts = None + te = None frequency = "fx" has_time = time_dim in ds @@ -137,7 +137,15 @@ def _todate(t): if has_time & (frequency != "fx"): if not has_bounds: ts, te = _guess_start_end_dates(ts, te, frequency) + + if ts is None: + start_date = "none" + else: start_date = ts.strftime(time_format) + + if te is None: + end_date = "none" + else: end_date = te.strftime(time_format) if frequency[0]: diff --git a/tests/test_source_utils.py b/tests/test_source_utils.py index ab5f32fc..30347ba1 100644 --- a/tests/test_source_utils.py +++ b/tests/test_source_utils.py @@ -544,8 +544,8 @@ def test_parse_access_filename(filename, expected): "GMOM_JRA_WD_ww3_hi_XXXX_XX_XX_XXXXX", "1900-01-02-00000", "fx", # WW3 provides no time bounds - "none", - "none", + "1900-01-02, 00:00:00", + "1900-01-02, 00:00:00", ["EF", "mapsta"], ["1D spectral density", "map status"], ["", ""],