Skip to content

Commit

Permalink
Dropping seconds-level precision from frontend to match backend (#21)
Browse files Browse the repository at this point in the history
* Dropping seconds-level precision from frontend to match backend

See JeetShetty/GreenPiThumb#122

* Fixing seconds parameter
  • Loading branch information
mtlynch committed Apr 8, 2017
1 parent 185d354 commit 1ad56a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions server/json_encoder.py
Expand Up @@ -4,8 +4,8 @@


def _encode_time(time):
"""Encodes time in YYYYMMDDTHHMMSSZ format (assumes UTC time zone)."""
return datetime.datetime.strftime(time, '%Y%m%dT%H%M%SZ')
"""Encodes time in YYYYMMDDTHHMMZ format (assumes UTC time zone)."""
return datetime.datetime.strftime(time, '%Y%m%dT%H%MZ')


class Encoder(simplejson.JSONEncoder):
Expand Down
20 changes: 10 additions & 10 deletions tests/test_json_encoder.py
Expand Up @@ -22,60 +22,60 @@ def test_encodes_records_correctly(self):
self.assertJsonEqual(
"""
{
"timestamp": "20170319T150123Z",
"timestamp": "20170319T1501Z",
"soil_moisture": 305
}
""".strip(),
self.encoder.encode(
db_store.SoilMoistureRecord(
timestamp=datetime.datetime(
2017, 3, 19, 15, 1, 23, 924000, tzinfo=pytz.utc),
2017, 3, 19, 15, 1, tzinfo=pytz.utc),
soil_moisture=305)))
self.assertJsonEqual(
"""
{
"timestamp": "20170319T150123Z",
"timestamp": "20170319T1501Z",
"ambient_light": 87.3
}
""".strip(),
self.encoder.encode(
db_store.AmbientLightRecord(
timestamp=datetime.datetime(
2017, 3, 19, 15, 1, 23, 924000, tzinfo=pytz.utc),
2017, 3, 19, 15, 1, tzinfo=pytz.utc),
ambient_light=87.3)))
self.assertJsonEqual(
"""
{
"timestamp": "20170319T150123Z",
"timestamp": "20170319T1501Z",
"humidity": 21.5
}
""".strip(),
self.encoder.encode(
db_store.HumidityRecord(
timestamp=datetime.datetime(
2017, 3, 19, 15, 1, 23, 924000, tzinfo=pytz.utc),
2017, 3, 19, 15, 1, tzinfo=pytz.utc),
humidity=21.5)))
self.assertJsonEqual(
"""
{
"timestamp": "20170319T150123Z",
"timestamp": "20170319T1501Z",
"temperature": 21.5
}
""".strip(),
self.encoder.encode(
db_store.TemperatureRecord(
timestamp=datetime.datetime(
2017, 3, 19, 15, 1, 23, 924000, tzinfo=pytz.utc),
2017, 3, 19, 15, 1, tzinfo=pytz.utc),
temperature=21.5)))
self.assertJsonEqual(
"""
{
"timestamp": "20170319T150123Z",
"timestamp": "20170319T1501Z",
"water_pumped": 302.5
}
""".strip(),
self.encoder.encode(
db_store.WateringEventRecord(
timestamp=datetime.datetime(
2017, 3, 19, 15, 1, 23, 924000, tzinfo=pytz.utc),
2017, 3, 19, 15, 1, tzinfo=pytz.utc),
water_pumped=302.5)))

0 comments on commit 1ad56a4

Please sign in to comment.