Skip to content

Commit

Permalink
convert from UTC to CST timezone
Browse files Browse the repository at this point in the history
datetime is returned in UTC timezone, need to convert to CST timezone.
  • Loading branch information
haileyhoyat authored Nov 27, 2023
1 parent e7a7992 commit 04a6c44
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions city_scrapers/spiders/chi_citycouncil.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from datetime import datetime

from city_scrapers_core.constants import NOT_CLASSIFIED
from city_scrapers_core.items import Meeting
from city_scrapers_core.spiders import CityScrapersSpider
from dateutil import tz
from dateutil.parser import parser


Expand Down Expand Up @@ -47,18 +50,30 @@ def _parse_classification(self, item):

def _parse_start(self, item):
"""Parse start datetime as a naive datetime object."""
full_date = item["date"]

date = full_date.split("T")[0]
time = full_date.split("T")[1]
time = time.split("+")[0]
# as of 11/10/2023, the returned time is in UTC timezone

# as of 11/10/2023 the returned time is 5 hrs ahead of actual meeting time

adjusted_hour = int(time.split(":")[0]) - 5
adjusted_time = str(adjusted_hour) + ":" + time.split(":", 1)[1]
# print(adjusted_time)
return parser().parse(date + " " + adjusted_time)
# retieve meeting date and time
full_date = item["date"]
# print(full_date)

# convert datetime from UTC to CST time
# turn datetime object into datetime timzone aware object
from_zone = tz.gettz("UTC")
to_zone = tz.gettz("CST")

utc = datetime.strptime(full_date.split("+")[0] + "Z", "%Y-%m-%dT%H:%M:%SZ")
utc = utc.replace(tzinfo=from_zone)
cst = utc.astimezone(to_zone)
# print(utc)
# print(cst)

# extract the individual date and time as strings
# get date component
date = cst.strftime("%m/%d/%Y %H:%M:%S").split(" ")[0]
# get time component
time = cst.strftime("%m/%d/%Y %H:%M:%S").split(" ")[1]

return parser().parse(date + " " + time)

def _parse_end(self, item):
"""Parse end datetime as a naive datetime object. Added by pipeline if None"""
Expand Down

0 comments on commit 04a6c44

Please sign in to comment.