-
Notifications
You must be signed in to change notification settings - Fork 110
Improve RFC 3339 datetime handling #368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
moradology
merged 31 commits into
stac-utils:master
from
philvarner:pv/datetime-parsing
Apr 14, 2022
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
eb8f9b0
improve RFC 3339 datetime handling
philvarner 7a751fe
install build-essential
philvarner 15b6ff6
sudo, rearrange files
philvarner eec3971
gapt -> apt
philvarner 0c9b56e
install build-essential in docker img
philvarner 17fb42d
move ciso8601 dep
philvarner 6666af5
fix typing for parse_interval function
philvarner 1238bc1
fix import of parse_interval
philvarner 36e5bdd
more changes for datetimes
philvarner e36a8c9
get the types right
philvarner 94af4e7
remove unnecessary parens
philvarner 755220d
remove classmethod
philvarner 0f27bfc
add some interval tests
philvarner 45747f5
replace rfc3339_str with pystac.utils.datetime_to_str
philvarner d933be7
fix search datetime parameter parsing to support empty string as open…
philvarner c9f943c
rename methods
philvarner afb4176
fix accidental method name repacement for parse_rfc3339
philvarner 7b00142
update tests for double open ended temporal interval
philvarner c9b83de
fix handling of empty string open-ended interval
philvarner b9119b4
fix test that was successful with double-open-ended datetime interval…
philvarner 9f400f4
replace ciso8601 with python-dateutil
philvarner f325ebb
Revert "replace ciso8601 with python-dateutil"
philvarner a77d05e
add pystac dependency to types
philvarner d535c32
add double-open-ended tests to pgstac tests
philvarner b7a527c
skip mixed open-ended in pgstac
philvarner c7b1a8e
skip datetime interval empty string in pgstac
philvarner 11e55f7
maybe just await the test
philvarner cb2676a
Merge branch 'master' into pv/datetime-parsing
moradology 8a433e8
Bump black version to avoid https://github.com/psf/black/issues/2964
moradology 73c32d9
Merge branch 'pv/datetime-parsing' of github.com:philvarner/stac-fast…
moradology 35357e9
lint
moradology File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ | |
"License :: OSI Approved :: MIT License", | ||
], | ||
keywords="STAC FastAPI COG", | ||
author=u"Arturo Engineering", | ||
author="Arturo Engineering", | ||
author_email="[email protected]", | ||
url="https://github.com/stac-utils/stac-fastapi", | ||
license="MIT", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ | |
"License :: OSI Approved :: MIT License", | ||
], | ||
keywords="STAC FastAPI COG", | ||
author=u"Arturo Engineering", | ||
author="Arturo Engineering", | ||
author_email="[email protected]", | ||
url="https://github.com/stac-utils/stac-fastapi", | ||
license="MIT", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,7 @@ | |
"License :: OSI Approved :: MIT License", | ||
], | ||
keywords="STAC FastAPI COG", | ||
author=u"Arturo Engineering", | ||
author="Arturo Engineering", | ||
author_email="[email protected]", | ||
url="https://github.com/stac-utils/stac-fastapi", | ||
license="MIT", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
"""Serializers.""" | ||
import abc | ||
import json | ||
from datetime import datetime | ||
from typing import TypedDict | ||
|
||
import attr | ||
import geoalchemy2 as ga | ||
from stac_pydantic.shared import DATETIME_RFC339 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DATETIME_RFC339 has been deprecated in stac_pydantic. It has several problems including, not parsing fractional seconds or timezones other than Z. |
||
from pystac.utils import datetime_to_str | ||
|
||
from stac_fastapi.sqlalchemy.models import database | ||
from stac_fastapi.types import stac as stac_types | ||
from stac_fastapi.types.config import Settings | ||
from stac_fastapi.types.links import CollectionLinks, ItemLinks, resolve_links | ||
from stac_fastapi.types.rfc3339 import now_to_rfc3339_str, rfc3339_str_to_datetime | ||
|
||
|
||
@attr.s # type:ignore | ||
|
@@ -55,7 +55,7 @@ def db_to_stac(cls, db_model: database.Item, base_url: str) -> stac_types.Item: | |
# Use getattr to accommodate extension namespaces | ||
field_value = getattr(db_model, field.split(":")[-1]) | ||
if field == "datetime": | ||
field_value = field_value.strftime(DATETIME_RFC339) | ||
field_value = datetime_to_str(field_value) | ||
properties[field] = field_value | ||
item_id = db_model.id | ||
collection_id = db_model.collection_id | ||
|
@@ -101,12 +101,12 @@ def stac_to_db( | |
# Use getattr to accommodate extension namespaces | ||
field_value = stac_data["properties"][field] | ||
if field == "datetime": | ||
field_value = datetime.strptime(field_value, DATETIME_RFC339) | ||
field_value = rfc3339_str_to_datetime(field_value) | ||
indexed_fields[field.split(":")[-1]] = field_value | ||
|
||
# TODO: Exclude indexed fields from the properties jsonb field to prevent duplication | ||
|
||
now = datetime.utcnow().strftime(DATETIME_RFC339) | ||
now = now_to_rfc3339_str() | ||
if "created" not in stac_data["properties"]: | ||
stac_data["properties"]["created"] = now | ||
stac_data["properties"]["updated"] = now | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-e
isn't needed in this case, and it only affects the first package name after it (rather than all of them)