Render UK time difference server-side and simplify trip timezone JS

This commit is contained in:
Edward Betts 2026-02-26 15:26:25 +00:00
parent 701023db59
commit f2752383f2
2 changed files with 42 additions and 32 deletions

View file

@ -114,9 +114,9 @@
<tbody>
{% for item in destination_times %}
<tr>
<td>{{ item.location }} ({{ item.country_name }}) {{ item.country_flag if trip.show_flags }}</td>
<td>{{ item.destination_label }}</td>
<td>{{ item.timezone or "Unknown" }}</td>
<td class="destination-offset" {% if item.timezone %}data-timezone="{{ item.timezone }}"{% endif %}>{{ 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>
{% endfor %}
@ -490,24 +490,6 @@ var routes = {{ routes | tojson }};
build_map("map", coordinates, routes);
function timezoneOffsetLabel(offsetMinutes) {
if (offsetMinutes === 0) {
return "No difference";
}
const sign = offsetMinutes > 0 ? "+" : "-";
const abs = Math.abs(offsetMinutes);
const hours = String(Math.floor(abs / 60)).padStart(2, "0");
const minutes = String(abs % 60).padStart(2, "0");
return `${sign}${hours}:${minutes} vs Bristol`;
}
function getOffsetMinutes(timeZone) {
const now = new Date();
const localInZone = new Date(now.toLocaleString("en-US", { timeZone }));
const localInBristol = new Date(now.toLocaleString("en-US", { timeZone: "Europe/London" }));
return Math.round((localInZone - localInBristol) / 60000);
}
function updateDestinationTimes() {
for (const el of document.querySelectorAll(".destination-time[data-timezone]")) {
const tz = el.dataset.timezone;
@ -520,12 +502,6 @@ function updateDestinationTimes() {
hour12: false
}).format(new Date());
}
for (const el of document.querySelectorAll(".destination-offset[data-timezone]")) {
const tz = el.dataset.timezone;
const offset = getOffsetMinutes(tz);
el.textContent = timezoneOffsetLabel(offset);
}
}
updateDestinationTimes();