Skip to content

Commit

Permalink
Update item.py
Browse files Browse the repository at this point in the history
  • Loading branch information
alukach committed Jul 21, 2022
1 parent 2c14a00 commit 53d66d8
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions stac_pydantic/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ class ItemProperties(StacCommonMetadata):
https://github.com/radiantearth/stac-spec/blob/v1.0.0/item-spec/item-spec.md#properties-object
"""

datetime: Union[dt, str, None] = Field(..., alias="datetime")
datetime: Optional[dt] = Field(..., alias="datetime")

@validator("datetime")
def validate_datetime(cls, v: Union[dt, str, None], values: Dict[str, Any]) -> dt:
if v in ("null", None):
def validate_datetime(cls, v: Optional[dt], values: Dict[str, Any]) -> dt:
if v is None:
if not values["start_datetime"] and not values["end_datetime"]:
raise ValueError(
"start_datetime and end_datetime must be specified when datetime is null"
)

if isinstance(v, str):
return parse_datetime(v)

return v

class Config:
Expand Down

0 comments on commit 53d66d8

Please sign in to comment.