Skip to content

request for consistent datetime intake for Item #710

@itcarroll

Description

@itcarroll

The datetime argument to pystac.Item expects datetime objects, while the properties argument expects a dictionary with string type for start_datetime and end_datetime when these are required. That inconsistency doesn't seem necessary, and likely leads to extra work handling conversions and time-zone ambiguity.

Why not let the datetime argument handle both cases, and not ask users to mess with the properties?

To elaborate, the code below works, but probably shouldn't. But rathern than setting datetime=None, I'd like to set datetime=tspan and skip setting properties.

import pystac
import pandas as pd

tspan = pd.to_datetime(('2022-01-01T00:00:00 -05:00', '2022-01-31T00:00:00 -05:00'))

c = pystac.Collection(id='Test', description=None, extent=None)
i = pystac.Item(
    id='Test-Item',
    geometry={'type': 'Polygon', 'coordinates': (
        ((1, 0),(1, 1),(0, 1),(0, 0),(1, 0)),
    )},
    bbox=(0, 0, 1, 1),
    datetime=tspan[0],
    properties={'start_datetime': tspan[0].isoformat(), 'end_datetime': tspan[1].isoformat()},
)
c.add_item(i)
c.update_extent_from_items()

Would you be interested in a PR that makes the datetime argument handle one or a two-tuple datetime and sets properties as appropriate? Fair warning ... I'd have to learn typing.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions