This repository has been archived by the owner on Mar 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backdrop read api should always return UTC
Consumers of backdrop will always want datetimes to be represented as UTC. Previously they had no timezone attached, which was rather confusing as the ISODate in mongo had a timezone. This commit will force all datetime objects coming out of backdrop into UTC before writing them out to JSON.
- Loading branch information
Showing
2 changed files
with
30 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import unittest | ||
import pytz | ||
|
||
from hamcrest import * | ||
from datetime import datetime | ||
from backdrop.read.api import JsonEncoder | ||
|
||
|
||
class TestReadAPIJSONEcoder(unittest.TestCase): | ||
|
||
def test_with_utc_date(self): | ||
obj = {'date': datetime(2014, 4, 29, 1, 0, 0, 0, pytz.utc)} | ||
assert_that( | ||
JsonEncoder().encode(obj), | ||
is_('{"date": "2014-04-29T01:00:00+00:00"}')) | ||
|
||
def test_with_est_date(self): | ||
est = pytz.timezone('US/Eastern') | ||
obj = {'date': datetime(2014, 4, 29, 1, 0, 0, 0, est)} | ||
assert_that( | ||
JsonEncoder().encode(obj), | ||
is_('{"date": "2014-04-29T06:00:00+00:00"}')) | ||
|
||
def test_with_no_tz_date(self): | ||
obj = {'date': datetime(2014, 4, 29, 1, 0)} | ||
assert_that( | ||
JsonEncoder().encode(obj), | ||
is_('{"date": "2014-04-29T01:00:00+00:00"}')) |