Skip to content

Instantly share code, notes, and snippets.

@ikonst
Created July 2, 2018 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ikonst/bf494667623ad3365f212f037dd52e70 to your computer and use it in GitHub Desktop.
Save ikonst/bf494667623ad3365f212f037dd52e70 to your computer and use it in GitHub Desktop.
from datetime import datetime
import pytz
import dateutil.tz
from pynamodb.models import Model
from pynamodb.attributes import NumberAttribute, UTCDateTimeAttribute
class MyModel(Model):
class Meta:
table_name = 'my_model'
read_capacity_units = 10
write_capacity_units = 10
host = "http://localhost:8000"
k = NumberAttribute(hash_key=True)
t = UTCDateTimeAttribute()
MyModel.create_table()
m1 = MyModel()
m1.k = 123
m1.t = datetime.utcnow()
print(m1.t, m1.t.tzinfo)
m1.save()
m2 = MyModel.get(123)
print(m2.t, m2.t.tzinfo)
m2.t = datetime.utcnow().replace(tzinfo=pytz.utc)
m2.save()
m3 = MyModel.get(123)
print(m3.t, m3.t.tzinfo)
m3.t = datetime.now().replace(tzinfo=dateutil.tz.tzlocal())
print(m3.t, m3.t.tzinfo)
m3.save()
m4 = MyModel.get(123)
print(m4.t, m4.t.tzinfo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment