-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
No longer use arrow for datetime/timezone things - make them explicit…
… instead
- Loading branch information
Denis Krienbühl
committed
Feb 5, 2015
1 parent
9b83dd6
commit e2f257f
Showing
12 changed files
with
174 additions
and
70 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
arrow | ||
flask | ||
isodate | ||
testing.postgresql |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
from libres.modules import calendar | ||
from sqlalchemy import types | ||
from dateutil.tz import tzutc | ||
from datetime import datetime | ||
|
||
|
||
class UTCDateTime(types.TypeDecorator): | ||
""" Stores dates as UTC. | ||
Internally, they are stored as timezone naive, because Postgres takes | ||
the local timezone into account when working with timezones. We really | ||
want to have those dates in UTC at all times, though for convenience we | ||
make the dates timezone aware when retrieving the values and we make sure | ||
that timezone aware dates are converted to UTC before storing. | ||
""" | ||
|
||
impl = types.DateTime | ||
|
||
def process_bind_param(self, value, engine): | ||
if value is not None: | ||
assert value.tzinfo, 'datetimes must be timezone-aware' | ||
|
||
# ..though they are stored internally without timezone in utc | ||
# the timezone is attached again on date retrieval, see below. | ||
return value.astimezone(tzutc()).replace(tzinfo=None) | ||
return calendar.to_timezone(value, 'UTC').replace(tzinfo=None) | ||
|
||
def process_result_value(self, value, engine): | ||
if value is not None: | ||
return datetime(value.year, value.month, value.day, | ||
value.hour, value.minute, value.second, | ||
value.microsecond, tzinfo=tzutc()) | ||
return calendar.replace_timezone(value, 'UTC') |
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
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
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
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
Oops, something went wrong.