From c8e70a39868578082a6fcc593ae0bf6d5e610e97 Mon Sep 17 00:00:00 2001 From: Paul van Schayck Date: Fri, 8 Sep 2023 16:25:52 +0200 Subject: [PATCH] KDP-1761: Force t-axis to be timezone aware --- example.py | 5 +++-- src/covjson_pydantic/domain.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/example.py b/example.py index d5d96f6..32140ae 100644 --- a/example.py +++ b/example.py @@ -1,4 +1,5 @@ -import datetime +from datetime import datetime +from datetime import timezone from covjson_pydantic.coverage import Coverage from covjson_pydantic.domain import Domain @@ -10,7 +11,7 @@ axes={ "x": {"dataType": "float", "values": [1.23]}, "y": {"values": [4.56]}, - "t": {"dataType": "datetime", "values": [datetime.datetime.now()]}, + "t": {"dataType": "datetime", "values": [datetime.now(tz=timezone.utc)]}, }, ), ranges={"temperature": NdArray(axisNames=["x", "y", "t"], shape=[1, 1, 1], values=[42.0])}, diff --git a/src/covjson_pydantic/domain.py b/src/covjson_pydantic/domain.py index a735f0e..c59a51a 100644 --- a/src/covjson_pydantic/domain.py +++ b/src/covjson_pydantic/domain.py @@ -1,4 +1,3 @@ -from datetime import datetime from enum import Enum from typing import Generic from typing import List @@ -8,6 +7,7 @@ from typing import TypeVar from typing import Union +from pydantic import AwareDatetime from pydantic import ConfigDict from pydantic import model_validator from pydantic import PositiveInt @@ -61,7 +61,7 @@ class Axes(BaseModel): x: Optional[Union[ValuesAxis[float], CompactAxis]] = None y: Optional[Union[ValuesAxis[float], CompactAxis]] = None z: Optional[Union[ValuesAxis[float], CompactAxis]] = None - t: Optional[ValuesAxis[datetime]] = None + t: Optional[ValuesAxis[AwareDatetime]] = None composite: Optional[ValuesAxis[Tuple]] = None @model_validator(mode="after")