Created
June 24, 2015 00:05
-
-
Save inklesspen/90b554c864b99340747e to your computer and use it in GitHub Desktop.
This file contains 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
from sqlalchemy import DateTime | |
from sqlalchemy.types import TypeDecorator | |
class AwareDateTime(TypeDecorator): | |
""" | |
A DateTime type which can only store tz-aware DateTimes | |
""" | |
impl = DateTime(timezone=True) | |
def process_bind_param(self, value, dialect): | |
if isinstance(value, datetime.datetime) and value.tzinfo is None: | |
raise ValueError("{!r} must be TZ-aware".format(value)) | |
return value | |
def __repr__(self): | |
return 'AwareDateTime()' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment