Skip to content

Commit

Permalink
Fix the timezone issues when pulling records from file db. (#829)
Browse files Browse the repository at this point in the history
Explicitly convert both times to utc before arithmetic.

Closes #821
  • Loading branch information
wtgee authored May 8, 2019
1 parent 4971b68 commit eb2eb15
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions bin/peas_shell
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import os
import readline
import sys

from pytz import utc
from astropy.utils import console
from threading import Timer
from pprint import pprint
Expand Down Expand Up @@ -75,9 +76,12 @@ class PanSensorShell(cmd.Cmd):
print("{}:".format(device.upper()))
pprint(rec)
print_info('*' * 80)

# Display the age in seconds of the record
if isinstance(rec.get('date'), datetime.datetime):
now = current_time(datetime=True)
age = (now - rec['date']).total_seconds()
now = current_time(datetime=True).astimezone(utc)
record_date = rec['date'].astimezone(utc)
age = (now - record_date).total_seconds()
if age < 120:
print_info('{:.1f} seconds old'.format(age))
else:
Expand Down

0 comments on commit eb2eb15

Please sign in to comment.