11from datetime import datetime , timedelta , timezone
2+ from gc import freeze
23from shutil import rmtree
34from tempfile import mkdtemp
45from unittest import TestCase
56from unittest .mock import ANY , patch
67
78import numpy as np
9+ from freezegun import freeze_time
810from harmony_service_lib .message import Message
911from netCDF4 import Dataset
1012from numpy .testing import assert_array_equal
1113from varinfo import VarInfoFromDmr
1214
1315from hoss .exceptions import UnsupportedTemporalUnits
1416from hoss .temporal import (
17+ DEFAULT_TIME_START ,
18+ default_time_end ,
1519 get_datetime_with_timezone ,
1620 get_temporal_index_ranges ,
1721 get_time_ref ,
@@ -130,6 +134,7 @@ def test_get_time_ref(self):
130134 with self .assertRaises (UnsupportedTemporalUnits ):
131135 get_time_ref ('fortnights since 2021-12-08 00:30:00' )
132136
137+ @freeze_time ("2025-10-21 16:15:00 UTC" )
133138 def test_get_datetime_with_timezone (self ):
134139 """Ensure the string is parsed to datetime with timezone."""
135140 expected_datetime = datetime (2021 , 12 , 8 , 0 , 30 , tzinfo = timezone .utc )
@@ -153,3 +158,21 @@ def test_get_datetime_with_timezone(self):
153158 self .assertEqual (
154159 get_datetime_with_timezone ('2021-12-08 00:30:00Z' ), expected_datetime
155160 )
161+
162+ with self .subTest ('ISO with fractional seconds Z' ):
163+ self .assertEqual (
164+ get_datetime_with_timezone ('2021-12-08T00:30:00.000Z' ),
165+ expected_datetime ,
166+ )
167+
168+ with self .subTest ('DEFAULT_TIME_START' ):
169+ expected_start_time = datetime (1 , 1 , 1 , 0 , 0 , tzinfo = timezone .utc )
170+ self .assertEqual (
171+ get_datetime_with_timezone (DEFAULT_TIME_START ), expected_start_time
172+ )
173+
174+ with self .subTest ('default_end_time()' ):
175+ expected_stop_time = datetime (2025 , 10 , 21 , 16 , 15 , tzinfo = timezone .utc )
176+ self .assertEqual (
177+ get_datetime_with_timezone (default_time_end ()), expected_stop_time
178+ )
0 commit comments