Fix handling of timezones (#4831)

This commit is contained in:
Nicolas Mowen 2022-12-30 16:51:13 -07:00 committed by GitHub
parent 76bbd838f7
commit da1b7c2e28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1095,11 +1095,17 @@ def vod_hour_no_timezone(year_month, day, hour, camera_name):
# TODO make this nicer when vod module is removed # TODO make this nicer when vod module is removed
@bp.route("/vod/<year_month>/<day>/<hour>/<camera_name>/<tz_name>") @bp.route("/vod/<year_month>/<day>/<hour>/<camera_name>/<tz_name>")
def vod_hour(year_month, day, hour, camera_name, tz_name): def vod_hour(year_month, day, hour, camera_name, tz_name):
tz_name = tz_name.replace(",", "/") tz_offset = int(
datetime.now(pytz.timezone(tz_name.replace(",", "/")))
.utcoffset()
.total_seconds()
/ 60
/ 60
)
parts = year_month.split("-") parts = year_month.split("-")
start_date = datetime( start_date = datetime(
int(parts[0]), int(parts[1]), int(day), int(hour), tzinfo=pytz.timezone(tz_name) int(parts[0]), int(parts[1]), int(day), int(hour), tzinfo=timezone.utc
).astimezone(timezone.utc) ) - timedelta(hours=tz_offset)
end_date = start_date + timedelta(hours=1) - timedelta(milliseconds=1) end_date = start_date + timedelta(hours=1) - timedelta(milliseconds=1)
start_ts = start_date.timestamp() start_ts = start_date.timestamp()
end_ts = end_date.timestamp() end_ts = end_date.timestamp()