blob: bc3f127e15c4b14d07374da4d62a9e9dff06aae4 (
plain) (
tree)
|
|
# Copyright (C) 2022 Yuchen Pei.
#
# This file is part of ptvtt.
#
# ptvtt is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# ptvtt is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General
# Public License for more details.
# You should have received a copy of the GNU Affero General Public
# License along with ptvtt. If not, see <https://www.gnu.org/licenses/>.
from datetime import datetime, timezone
from zoneinfo import ZoneInfo
def parse_time(maybe_time):
if maybe_time:
return datetime.fromisoformat(maybe_time[:-1] + '+00:00')
return None
def filter_departures(departures):
return [
dep for dep in departures if dep['scheduled_departure_utc']
and parse_time(dep['scheduled_departure_utc']) >
datetime.now().astimezone(timezone.utc)
]
def format_time(maybe_time):
if maybe_time:
return str(maybe_time.astimezone(ZoneInfo('Australia/Melbourne')))[:-6]
return None
|