Skip to content

Add unicode datetime attribute #33

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
merged 6 commits into from
Jul 14, 2021

Conversation

NazarioJL
Copy link
Contributor

@NazarioJL NazarioJL commented Jun 26, 2021

This PR adds the UnicodeDatetimeAttribute attribute type for storing datetimes as 8601 ISO strings with offset.

Usage

from datetime import datetime

from pynamodb.models import Model
from pynamodb_attributes import UnicodeDatetimeAttribute


class MyModel(Model):
    key = UnicodeDatetimeAttribute(hash_key=True)


model = MyModel()
model.key = datetime(1980, 11, 20)
model.save()  # There is now a record with value "1980-11-20T00:00:00.000000-00:00"

The storage representation of this format will look something like:

{"key": {"S": "2020-11-22T03:22:33.444444-08:00"}}

The attribute by default will add an offset to UTC if not present and make it timezone aware. It also as options for normalizing the date to UTC (for caching purposes) and adds support for custom formatting.

@NazarioJL
Copy link
Contributor Author

@ikonst are we ok with running black on the whole project? If so, I'll go ahead and do that.

@ikonst
Copy link
Contributor

ikonst commented Jun 27, 2021

Let's black it in a separate PR first? Totally supportive of black btw.

@NazarioJL NazarioJL force-pushed the add_unicodedatetime_attr branch from f344fd6 to 0af89ea Compare June 28, 2021 21:07
@NazarioJL
Copy link
Contributor Author

@ikonst done! I will ship another PR where this gets blacked.

@NazarioJL
Copy link
Contributor Author

@ikonst added 3.9 in the test matrix. I signed the CLA but it is not passing. Let me know if there's anything else I can do.

@NazarioJL
Copy link
Contributor Author

@ikonst I will break this PR into 3 separate PRs

  1. blacken the repo and fix the mypy tests
  2. Address Python 3.9 deprecates _field_types from NamedTuple #32
  3. Add the UnicodeDatetimeAttribute attribute

@NazarioJL NazarioJL force-pushed the add_unicodedatetime_attr branch 4 times, most recently from 5fd112d to 7277aa3 Compare July 9, 2021 22:28
@NazarioJL
Copy link
Contributor Author

💨

@NazarioJL NazarioJL force-pushed the add_unicodedatetime_attr branch from 7277aa3 to e5bf90e Compare July 13, 2021 16:53
@NazarioJL
Copy link
Contributor Author

@ikonst this should be ready for release 0.3.1

Co-authored-by: Ilya Konstantinov <[email protected]>
@NazarioJL
Copy link
Contributor Author

🚢

ikonst
ikonst previously approved these changes Jul 13, 2021
@ikonst ikonst merged commit 7a8ea99 into lyft:master Jul 14, 2021
@ikonst
Copy link
Contributor

ikonst commented Jul 14, 2021

Thanks for bearing with me! :)

@NazarioJL NazarioJL deleted the add_unicodedatetime_attr branch August 17, 2021 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants