Skip to content

Commit 37a09d8

Browse files
Merge pull request #9 from LouisSzeto/master
Update timezone info in processor and data class
2 parents ae9ad39 + 5917992 commit 37a09d8

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

RegalyticsRegulatoryArticle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public override List<Resolution> SupportedResolutions()
199199
/// <returns>The <see cref="T:NodaTime.DateTimeZone" /> of this data type</returns>
200200
public override DateTimeZone DataTimeZone()
201201
{
202-
return TimeZones.NewYork;
202+
return TimeZones.Utc;
203203
}
204204
}
205205
}

process.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22
import pathlib
3-
from datetime import datetime
3+
from datetime import datetime, timezone
44
import os
55
import requests
66

@@ -82,12 +82,13 @@
8282
article['states'] = states
8383
article['agencies'] = [agency['name'] for agency in article['agencies']]
8484

85-
# remove timezone info (-04:00) [NewYork]
86-
article['created_at'] = article['created_at'][:-6]
87-
88-
# all data received during day T would confer into day T+1 00:00
89-
date = datetime.strptime(article['created_at'], '%Y-%m-%dT%H:%M:%S.%f').date()
90-
date_key = date.strftime('%Y%m%d')
85+
# search using `created_at` returns all with UTC time between 00:00-23:59 in a single day,
86+
# so it include some articles created at 20:00-00:00 in EST of the "previous day" (-04:00).
87+
# Adjust timezone info of `created_at` field into UTC time to avoid overwriting the previous day file
88+
article['created_at'] = article['created_at'][:-3] + article['created_at'][-2:] # %z only accepts `-0400` instead of `-04:00` in Python3.6
89+
created_at = datetime.strptime(article['created_at'], '%Y-%m-%dT%H:%M:%S.%f%z').astimezone(timezone.utc)
90+
article['created_at'] = created_at.strftime('%Y-%m-%dT%H:%M:%S.%f')
91+
date_key = created_at.date().strftime('%Y%m%d')
9192

9293
if date_key not in articles_by_date:
9394
date_articles = []

0 commit comments

Comments
 (0)