Skip to content
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

Represent the datetime objects as UTC in RFC3339 format #333

Merged
merged 6 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ conda create -n optimade python=3.7
conda activate optimade

# Install package and dependencies in editable mode (including "dev" requirements).
pip install -e .[dev]
pip install -e ".[dev]"
CasperWA marked this conversation as resolved.
Show resolved Hide resolved

# Run the tests with pytest
py.test
Expand Down
8 changes: 8 additions & 0 deletions optimade/models/jsonapi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""This module should reproduce JSON API v1.0 https://jsonapi.org/format/1.0/"""
# pylint: disable=no-self-argument
from typing import Optional, Union, List
from datetime import datetime, timezone
from pydantic import ( # pylint: disable=no-name-in-module
BaseModel,
AnyUrl,
Expand Down Expand Up @@ -286,3 +287,10 @@ def either_data_meta_or_errors_must_be_set(cls, values):
f"At least one of {required_fields} MUST be specified in the top-level response"
)
return values

class Config:
json_encoders = {
datetime: lambda v: v.astimezone(timezone.utc).strftime(
"%Y-%m-%dT%H:%M:%SZ"
),
}
2 changes: 1 addition & 1 deletion optimade/server/routers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def meta_values(
return ResponseMeta(
query=ResponseMetaQuery(representation=f"{url_path}?{parse_result.query}"),
api_version=f"v{__api_version__}",
time_stamp=datetime.utcnow(),
time_stamp=datetime.now(),
CasperWA marked this conversation as resolved.
Show resolved Hide resolved
data_returned=data_returned,
more_data_available=more_data_available,
provider=CONFIG.provider,
Expand Down