Commit d5528c2e authored by g-weatherill's avatar g-weatherill
Browse files

Another fix to the datetime isoformat

parent ce87885f
Pipeline #23464 passed with stage
in 11 minutes and 22 seconds
...@@ -214,7 +214,7 @@ class Earthquake(object): ...@@ -214,7 +214,7 @@ class Earthquake(object):
) )
# Time is not necessarily in ISO format, so fix this for use with datetime object # Time is not necessarily in ISO format, so fix this for use with datetime object
hh, mm, ss = event["time"].split(":") hh, mm, ss = event["time"].split(":")
ss = "{:2.6f}".format(float(ss.replace("Z", ""))) ss = "%09.6f" % float(ss.replace("Z", ""))
event_time = ":".join([hh, mm, ss]) event_time = ":".join([hh, mm, ss])
d_t = datetime.datetime.fromisoformat(" ".join([event["date"], event_time])) d_t = datetime.datetime.fromisoformat(" ".join([event["date"], event_time]))
# If the event has a focal mechanism then parse this into the correct format # If the event has a focal mechanism then parse this into the correct format
......
...@@ -208,3 +208,16 @@ class EarthquakeTestCase(unittest.TestCase): ...@@ -208,3 +208,16 @@ class EarthquakeTestCase(unittest.TestCase):
ns_distance = Point(0.0, bbox[1], 0.0).distance(Point(0.0, bbox[3], 0.0)) ns_distance = Point(0.0, bbox[1], 0.0).distance(Point(0.0, bbox[3], 0.0))
self.assertAlmostEqual(max_dist, ew_distance, 5) self.assertAlmostEqual(max_dist, ew_distance, 5)
self.assertAlmostEqual(max_dist, ns_distance, 5) self.assertAlmostEqual(max_dist, ns_distance, 5)
def test_from_quakeml(self):
# Verifies that the earthquake object can be built from different GEOFON events
event_id_set = ["gfz2021kdvq", "gfz2021keus", "gfz2021kduj"]
target_string_set = [
"gfz2021kdvq 2021-05-25 09:41:17.200000 (29.35200E, -1.74600N, 10.00 km) M 4.39",
"gfz2021keus 2021-05-25 22:21:36.400000 (122.49800E, 24.83200N, 10.00 km) M 4.56",
"gfz2021kduj 2021-05-25 09:03:03.393825 (29.48394E, -1.78596N, 10.00 km) M 4.59",
]
results = []
for event_id in event_id_set:
results.append(str(Earthquake.from_quakeml(event_id)))
self.assertListEqual(results, target_string_set)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment