Skip to content

Commit 8f74f68

Browse files
committed
Fixing ISO-8601 times output.
1 parent c04e96f commit 8f74f68

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

metadata/profiles/common.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,36 @@
2929
#-------------------------------------------------------------------------------
3030

3131
import os.path
32+
import re
33+
34+
RE_ISO_8601 = re.compile(
35+
r"^(?P<year>\d{4,4})-?(?P<month>\d{2,2})-?(?P<day>\d{2,2})"
36+
r"(?:[ T](?P<hour>\d{2,2})"
37+
r"(?::?(?P<min>\d{2,2})(?::?(?P<sec>\d{2,2}(?:\.\d+)?))?)?"
38+
r"(?P<tzone>(?:(?P<tzhour>[+-]\d{2,2})(?::?(?P<tzmin>\d{2,2}))?)|(?P<tzzero>Z))?"
39+
r")?$"
40+
)
41+
42+
def isodt(dtstr):
43+
"""Fix ISO 8601 date-time string."""
44+
def _dic2str(year, month, day, hour=None, min=None, sec=None,
45+
tzone=None, tzhour=None, tzmin=None, tzzero=None, **kwarg):
46+
tzhour = tzhour or '+00'
47+
tzmin = tzmin or '00'
48+
if tzone is None or tzzero == 'Z':
49+
tzone = 'Z'
50+
elif tzhour in ('+00', '-00') and tzmin == '00':
51+
tzone = 'Z'
52+
else:
53+
tzone = "%s:%s"%(tzhour, tzmin)
54+
return "%s-%s-%sT%s:%s:%s%s"%(
55+
year, month, day, hour or '00', min or '00', sec or '00', tzone
56+
)
57+
m = RE_ISO_8601.match(dtstr)
58+
if m is None:
59+
raise ValueError("Invalid ISO8601 date/time '%s'!"%dtstr)
60+
return _dic2str(**m.groupdict())
61+
3262

3363
GDAL_TYPES = {
3464
'uint8' : "Byte",

metadata/profiles/spot6_ortho.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
from .common import (
3232
GDAL_TYPES, OGC_TYPE_DEFS,
33-
check, extract, extattr,
33+
check, extract, extattr, isodt
3434
)
3535

3636
import os.path
@@ -341,14 +341,20 @@ def extract_eop_metadata(cls, xml, ns_opt=None, file_name=None, **kwarg):
341341
OM = ns_om.E
342342
#GML = ns_gml.E
343343

344-
time_acq_start = "%sT%sZ"%(
344+
time_acq_start = isodt("%sT%s"%(
345345
extract(xml, "//Source_Identification/Strip_Source/IMAGING_DATE"),
346-
extract(xml, "//Source_Identification/Strip_Source/IMAGING_TIME"))
346+
extract(xml, "//Source_Identification/Strip_Source/IMAGING_TIME")
347+
))
347348
time_acq_stop = time_acq_start
348-
time_prod = extract(xml, "//Delivery_Identification/PRODUCTION_DATE")
349+
time_prod = isodt(extract(xml, "//Delivery_Identification/PRODUCTION_DATE"))
349350

350-
# extracting angles
351+
# extracting angles and times
351352
for elm in xml.iterfind("//Geometric_Data/Use_Area/Located_Geometric_Values"):
353+
time = isodt(extract(elm, "./TIME"))
354+
if time < time_acq_start:
355+
time_acq_start = time
356+
elif time > time_acq_stop:
357+
time_acq_stop = time
352358
if "Center" != extract(elm, "./LOCATION_TYPE"):
353359
continue
354360
#cnt_row = int(extract(elm, "./ROW"))

0 commit comments

Comments
 (0)