Skip to content

Commit

Permalink
Merge pull request #1036 from xcube-dev/konstntokas-1031-support_date…
Browse files Browse the repository at this point in the history
…time_in_datadescriptor

The `xcube.core.store.DataDescriptor` class now supports specifying time ranges using both `datetime.date` and `datetime.datetime` objects
  • Loading branch information
forman authored Jul 10, 2024
2 parents 7809dd8 + e345bc5 commit da0df9e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
at its first position and will override the `date_type` argument.
To preserve backward compatibility, the keyword argument `data_type`
has not yet been added to the `open_data()` method arguments. (#1030)
* The `xcube.core.store.DataDescriptor` class now supports specifying time ranges
using both `datetime.date` and `datetime.datetime` objects. Previously,
only `datetime.date` objects were supported.

## Changes in 1.6.0

Expand Down
38 changes: 36 additions & 2 deletions test/core/store/test_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,41 @@ def test_to_dict(self):
"data_type": "dataset",
"bbox": [10.0, 20.0, 30.0, 40.0],
"spatial_res": 20.0,
"time_range": ["2017-06-05", "2017-06-27"],
"time_range": ("2017-06-05", "2017-06-27"),
"time_period": "daily",
"open_params_schema": {
"type": "object",
"properties": {"consolidated": {"type": "boolean"}},
"additionalProperties": False,
},
},
descriptor_dict,
)

def test_datetime_to_dict(self):
descriptor = DatasetDescriptor(
data_id="xyz",
crs="EPSG:9346",
bbox=(10.0, 20.0, 30.0, 40.0),
spatial_res=20.0,
time_range=("2017-06-05T12:22:45Z", "2017-06-27T18:22:45Z"),
time_period="daily",
open_params_schema=JsonObjectSchema(
properties=dict(
consolidated=JsonBooleanSchema(),
),
additional_properties=False,
),
)
descriptor_dict = descriptor.to_dict()
self.assertEqual(
{
"data_id": "xyz",
"crs": "EPSG:9346",
"data_type": "dataset",
"bbox": [10.0, 20.0, 30.0, 40.0],
"spatial_res": 20.0,
"time_range": ("2017-06-05T12:22:45Z", "2017-06-27T18:22:45Z"),
"time_period": "daily",
"open_params_schema": {
"type": "object",
Expand Down Expand Up @@ -310,7 +344,7 @@ def test_to_dict(self):
crs="EPSG:9346",
bbox=[10.0, 20.0, 30.0, 40.0],
spatial_res=20.0,
time_range=["2017-06-05", "2017-06-27"],
time_range=("2017-06-05", "2017-06-27"),
time_period="daily",
coords=dict(
rtdt=dict(
Expand Down
11 changes: 9 additions & 2 deletions xcube/core/store/descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from xcube.util.ipython import register_json_formatter
from xcube.util.jsonschema import JsonArraySchema
from xcube.util.jsonschema import JsonDateSchema
from xcube.util.jsonschema import JsonDatetimeSchema
from xcube.util.jsonschema import JsonComplexSchema
from xcube.util.jsonschema import JsonIntegerSchema
from xcube.util.jsonschema import JsonNumberSchema
from xcube.util.jsonschema import JsonObject
Expand Down Expand Up @@ -107,7 +109,7 @@ class DataDescriptor(JsonObject):
or WKT string
bbox: A bounding box of the data
time_range: Start and end time delimiting this data's temporal
extent
extent;
time_period: The data's periodicity if it is evenly temporally
resolved.
open_params_schema: A JSON schema describing the parameters that
Expand Down Expand Up @@ -155,7 +157,12 @@ def get_schema(cls) -> JsonObjectSchema:
JsonNumberSchema(),
]
),
time_range=JsonDateSchema.new_range(nullable=True),
time_range=JsonComplexSchema(
any_of=[
JsonDateSchema.new_range(nullable=True),
JsonDatetimeSchema.new_range(nullable=True),
]
),
time_period=JsonStringSchema(min_length=1),
open_params_schema=JsonObjectSchema(additional_properties=True),
),
Expand Down

0 comments on commit da0df9e

Please sign in to comment.