File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
marble_api/versions/v1/data_request
test/unit/versions/v1/data_request Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 11from collections .abc import Sized
2+ from datetime import timezone
23from typing import Required , TypedDict
34
45from bson import ObjectId
@@ -124,11 +125,11 @@ def stac_item(self) -> Item:
124125
125126 # STAC spec recommends including datetime even if using start_datetime and end_datetime
126127 # See: https://github.com/radiantearth/stac-spec/blob/master/best-practices.md#datetime-selection
127- item ["properties" ]["datetime" ] = self .temporal [0 ].isoformat ()
128+ item ["properties" ]["datetime" ] = self .temporal [0 ].astimezone ( timezone . utc ). isoformat ()
128129
129130 if len (set (self .temporal )) > 1 :
130131 item ["properties" ]["start_datetime" ], item ["properties" ]["end_datetime" ] = [
131- t .isoformat () for t in self .temporal
132+ t .astimezone ( timezone . utc ). isoformat () for t in self .temporal
132133 ]
133134
134135 if self .geometry :
Original file line number Diff line number Diff line change @@ -132,6 +132,28 @@ def test_range_temporal(self, fake_class):
132132 assert request .stac_item ["properties" ]["start_datetime" ] == temporal [0 ].isoformat ()
133133 assert request .stac_item ["properties" ]["end_datetime" ] == temporal [1 ].isoformat ()
134134
135+ def test_temporal_to_utc (self , fake_class ):
136+ now = datetime .datetime .now (tz = datetime .timezone .utc )
137+ offset = datetime .timezone (datetime .timedelta (hours = 3 ))
138+ temporal = [now , now + datetime .timedelta (hours = 1 )]
139+ temporal_offset = [t .astimezone (offset ) for t in temporal ]
140+ request = fake_class (temporal = temporal_offset )
141+ assert (
142+ request .stac_item ["properties" ]["datetime" ]
143+ == temporal [0 ].isoformat ()
144+ == temporal_offset [0 ].astimezone (datetime .timezone .utc ).isoformat ()
145+ )
146+ assert (
147+ request .stac_item ["properties" ]["start_datetime" ]
148+ == temporal [0 ].isoformat ()
149+ == temporal_offset [0 ].astimezone (datetime .timezone .utc ).isoformat ()
150+ )
151+ assert (
152+ request .stac_item ["properties" ]["end_datetime" ]
153+ == temporal [1 ].isoformat ()
154+ == temporal_offset [1 ].astimezone (datetime .timezone .utc ).isoformat ()
155+ )
156+
135157 def test_extra_properties (self , fake_class ):
136158 request = fake_class ()
137159 item = request .stac_item
You can’t perform that action at this time.
0 commit comments