Base trip timezone differences on trip dates and remove live local-time column
This commit is contained in:
parent
f2752383f2
commit
f0698acd59
2 changed files with 38 additions and 29 deletions
|
|
@ -108,7 +108,6 @@
|
||||||
<th>Destination</th>
|
<th>Destination</th>
|
||||||
<th>Timezone</th>
|
<th>Timezone</th>
|
||||||
<th>Difference from UK</th>
|
<th>Difference from UK</th>
|
||||||
<th>Current local time</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|
@ -117,7 +116,6 @@
|
||||||
<td>{{ item.destination_label }}</td>
|
<td>{{ item.destination_label }}</td>
|
||||||
<td>{{ item.timezone or "Unknown" }}</td>
|
<td>{{ item.timezone or "Unknown" }}</td>
|
||||||
<td class="destination-offset">{{ item.offset_display }}</td>
|
<td class="destination-offset">{{ item.offset_display }}</td>
|
||||||
<td class="destination-time" {% if item.timezone %}data-timezone="{{ item.timezone }}"{% endif %}>{{ item.current_time or "Unknown" }}</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
@ -490,22 +488,5 @@ var routes = {{ routes | tojson }};
|
||||||
|
|
||||||
build_map("map", coordinates, routes);
|
build_map("map", coordinates, routes);
|
||||||
|
|
||||||
function updateDestinationTimes() {
|
|
||||||
for (const el of document.querySelectorAll(".destination-time[data-timezone]")) {
|
|
||||||
const tz = el.dataset.timezone;
|
|
||||||
el.textContent = new Intl.DateTimeFormat("en-GB", {
|
|
||||||
timeZone: tz,
|
|
||||||
weekday: "short",
|
|
||||||
hour: "2-digit",
|
|
||||||
minute: "2-digit",
|
|
||||||
second: "2-digit",
|
|
||||||
hour12: false
|
|
||||||
}).format(new Date());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateDestinationTimes();
|
|
||||||
setInterval(updateDestinationTimes, 1000);
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
||||||
48
web_view.py
48
web_view.py
|
|
@ -790,6 +790,40 @@ def _format_offset_from_uk(offset_minutes: int) -> str:
|
||||||
return f"{sign}{hours:02d}:{mins:02d} vs UK"
|
return f"{sign}{hours:02d}:{mins:02d} vs UK"
|
||||||
|
|
||||||
|
|
||||||
|
def _trip_offset_minutes(
|
||||||
|
trip_start: date, trip_end: date, destination_timezone: str
|
||||||
|
) -> list[int]:
|
||||||
|
"""Unique UTC offset differences vs UK across the trip date range."""
|
||||||
|
destination_tz = ZoneInfo(destination_timezone)
|
||||||
|
uk_timezone = ZoneInfo("Europe/London")
|
||||||
|
current = trip_start
|
||||||
|
offsets: set[int] = set()
|
||||||
|
|
||||||
|
while current <= trip_end:
|
||||||
|
instant = datetime(
|
||||||
|
current.year, current.month, current.day, 12, tzinfo=timezone.utc
|
||||||
|
)
|
||||||
|
destination_offset = instant.astimezone(destination_tz).utcoffset()
|
||||||
|
uk_offset = instant.astimezone(uk_timezone).utcoffset()
|
||||||
|
if destination_offset is not None and uk_offset is not None:
|
||||||
|
offsets.add(int((destination_offset - uk_offset).total_seconds() // 60))
|
||||||
|
current += timedelta(days=1)
|
||||||
|
|
||||||
|
return sorted(offsets)
|
||||||
|
|
||||||
|
|
||||||
|
def _format_trip_offset_display(offsets: list[int]) -> str:
|
||||||
|
"""Format trip-range offsets; include variation if DST changes during trip."""
|
||||||
|
if not offsets:
|
||||||
|
return "Timezone unknown"
|
||||||
|
if len(offsets) == 1:
|
||||||
|
return _format_offset_from_uk(offsets[0])
|
||||||
|
return (
|
||||||
|
"Varies during trip: "
|
||||||
|
f"{_format_offset_from_uk(offsets[0])} to {_format_offset_from_uk(offsets[-1])}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _timezone_from_coordinates(latitude: float, longitude: float) -> str | None:
|
def _timezone_from_coordinates(latitude: float, longitude: float) -> str | None:
|
||||||
"""Resolve IANA timezone name from coordinates."""
|
"""Resolve IANA timezone name from coordinates."""
|
||||||
timezone_finder = _get_timezone_finder()
|
timezone_finder = _get_timezone_finder()
|
||||||
|
|
@ -853,8 +887,8 @@ def get_destination_timezones(trip: Trip) -> list[StrDict]:
|
||||||
if candidate:
|
if candidate:
|
||||||
per_location[key].append(candidate)
|
per_location[key].append(candidate)
|
||||||
|
|
||||||
home_now = datetime.now(ZoneInfo("Europe/London"))
|
|
||||||
destination_times: list[StrDict] = []
|
destination_times: list[StrDict] = []
|
||||||
|
trip_end = trip.end or trip.start
|
||||||
|
|
||||||
for location, country in trip.locations():
|
for location, country in trip.locations():
|
||||||
country_code = country.alpha_2.lower()
|
country_code = country.alpha_2.lower()
|
||||||
|
|
@ -881,15 +915,10 @@ def get_destination_timezones(trip: Trip) -> list[StrDict]:
|
||||||
timezone_name = country_timezones[0]
|
timezone_name = country_timezones[0]
|
||||||
|
|
||||||
offset_display = "Timezone unknown"
|
offset_display = "Timezone unknown"
|
||||||
current_time = None
|
|
||||||
if timezone_name:
|
if timezone_name:
|
||||||
dest_now = datetime.now(ZoneInfo(timezone_name))
|
offset_display = _format_trip_offset_display(
|
||||||
dest_offset = dest_now.utcoffset()
|
_trip_offset_minutes(trip.start, trip_end, timezone_name)
|
||||||
home_offset = home_now.utcoffset()
|
)
|
||||||
if dest_offset is not None and home_offset is not None:
|
|
||||||
offset_minutes = int((dest_offset - home_offset).total_seconds() // 60)
|
|
||||||
offset_display = _format_offset_from_uk(offset_minutes)
|
|
||||||
current_time = dest_now.strftime("%a %H:%M:%S")
|
|
||||||
|
|
||||||
destination_times.append(
|
destination_times.append(
|
||||||
{
|
{
|
||||||
|
|
@ -898,7 +927,6 @@ def get_destination_timezones(trip: Trip) -> list[StrDict]:
|
||||||
"country_flag": country.flag,
|
"country_flag": country.flag,
|
||||||
"timezone": timezone_name,
|
"timezone": timezone_name,
|
||||||
"offset_display": offset_display,
|
"offset_display": offset_display,
|
||||||
"current_time": current_time,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue