Skip to content

Commit

Permalink
fix tzinfo in PJM
Browse files Browse the repository at this point in the history
  • Loading branch information
aschn committed Apr 14, 2014
1 parent 3b7ceec commit 19d8223
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pyiso/pjm.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ def _get_edata(self, data_type, key):
def _utcify(self, ts_str):
naive_local_time = dateutil_parse(ts_str)
is_dst = 'EDT' in ts_str
aware_local_time = pytz.timezone('America/New_York').localize(naive_local_time, is_dst=is_dst)
if naive_local_time.tzinfo is None:
aware_local_time = pytz.timezone('America/New_York').localize(naive_local_time, is_dst=is_dst)
else:
aware_local_time = naive_local_time

aware_utc_time = aware_local_time.astimezone(pytz.utc)
return aware_utc_time

Expand Down
10 changes: 10 additions & 0 deletions tests/test_genmix.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,13 @@ def test_pjm_latest(self):
expected_fuels = ['wind', 'nonwind']
for expfuel in expected_fuels:
self.assertIn(expfuel, fuels)

def test_utcify(self):
ts_str = '04/13/14 21:45 EDT'
ts = client_factory('PJM')._utcify(ts_str)
self.assertEqual(ts.year, 2014)
self.assertEqual(ts.month, 4)
self.assertEqual(ts.day, 13+1)
self.assertEqual(ts.hour, 21-20)
self.assertEqual(ts.minute, 45)
self.assertEqual(ts.tzinfo, pytz.utc)

0 comments on commit 19d8223

Please sign in to comment.