fix time zones close #21

This commit is contained in:
Matt Walsh 2022-12-21 15:17:50 -06:00
parent 20ba3ddaac
commit fc4cbc1415
6 changed files with 19 additions and 15 deletions

View file

@ -43,7 +43,7 @@ const incrementInterval = () => {
const drawScreen = async () => { const drawScreen = async () => {
// get the conditions // get the conditions
const data = await getCurrentWeather(() => this.stillWaiting()); const data = await getCurrentWeather();
// nothing to do if there's no data yet // nothing to do if there's no data yet
if (!data) return; if (!data) return;

View file

@ -77,7 +77,7 @@ const getWeather = async (latLon, haveDataCallback) => {
weatherParameters.weatherOffice = point.properties.cwa; weatherParameters.weatherOffice = point.properties.cwa;
weatherParameters.city = city; weatherParameters.city = city;
weatherParameters.state = point.properties.relativeLocation.properties.state; weatherParameters.state = point.properties.relativeLocation.properties.state;
weatherParameters.timeZone = point.properties.relativeLocation.properties.timeZone; weatherParameters.timeZone = point.properties.timeZone;
weatherParameters.forecast = point.properties.forecast; weatherParameters.forecast = point.properties.forecast;
weatherParameters.forecastGridData = point.properties.forecastGridData; weatherParameters.forecastGridData = point.properties.forecastGridData;
weatherParameters.stations = stations.features; weatherParameters.stations = stations.features;
@ -400,6 +400,8 @@ const registerRefreshData = (callback) => {
loadTwcData.callback = callback; loadTwcData.callback = callback;
}; };
const timeZone = () => weatherParameters.timeZone;
export { export {
updateStatus, updateStatus,
displayNavMessage, displayNavMessage,
@ -415,4 +417,5 @@ export {
latLonReceived, latLonReceived,
stopAutoRefreshTimer, stopAutoRefreshTimer,
registerRefreshData, registerRefreshData,
timeZone,
}; };

View file

@ -5,7 +5,7 @@ import { loadImg } from './utils/image.mjs';
import { text } from './utils/fetch.mjs'; import { text } from './utils/fetch.mjs';
import { rewriteUrl } from './utils/cors.mjs'; import { rewriteUrl } from './utils/cors.mjs';
import WeatherDisplay from './weatherdisplay.mjs'; import WeatherDisplay from './weatherdisplay.mjs';
import { registerDisplay } from './navigation.mjs'; import { registerDisplay, timeZone } from './navigation.mjs';
import * as utils from './radar-utils.mjs'; import * as utils from './radar-utils.mjs';
class Radar extends WeatherDisplay { class Radar extends WeatherDisplay {
@ -159,7 +159,7 @@ class Radar extends WeatherDisplay {
zone: 'UTC', zone: 'UTC',
}).setZone(); }).setZone();
} else { } else {
time = DateTime.fromHTTP(response.headers.get('last-modified')).setZone(); time = DateTime.fromHTTP(response.headers.get('last-modified')).setZone(timeZone());
} }
// assign to an html image element // assign to an html image element

View file

@ -2,9 +2,8 @@
import STATUS, { calcStatusClass, statusClasses } from './status.mjs'; import STATUS, { calcStatusClass, statusClasses } from './status.mjs';
import { DateTime } from '../vendor/auto/luxon.mjs'; import { DateTime } from '../vendor/auto/luxon.mjs';
import { elemForEach } from './utils/elem.mjs';
import { import {
msg, displayNavMessage, isPlaying, updateStatus, msg, displayNavMessage, isPlaying, updateStatus, timeZone,
} from './navigation.mjs'; } from './navigation.mjs';
class WeatherDisplay { class WeatherDisplay {
@ -173,20 +172,22 @@ class WeatherDisplay {
// only draw if canvas is active to conserve battery // only draw if canvas is active to conserve battery
if (!this.active) return; if (!this.active) return;
// Get the current date and time. // Get the current date and time.
const now = DateTime.local(); const now = DateTime.local().setZone(timeZone());
// time = "11:35:08 PM"; // time = "11:35:08 PM";
const time = now.toLocaleString(DateTime.TIME_WITH_SECONDS).padStart(11, ' '); const time = now.toLocaleString(DateTime.TIME_WITH_SECONDS).padStart(11, ' ');
const date = now.toFormat(' ccc LLL ') + now.day.toString().padStart(2, ' ');
if (this.lastTime !== time) { const dateElem = this.elem.querySelector('.date-time.date');
elemForEach('.date-time.time', (elem) => { elem.innerHTML = time.toUpperCase(); }); const timeElem = this.elem.querySelector('.date-time.time');
if (timeElem && this.lastTime !== time) {
timeElem.innerHTML = time.toUpperCase();
} }
this.lastTime = time; this.lastTime = time;
const date = now.toFormat(' ccc LLL ') + now.day.toString().padStart(2, ' '); if (dateElem && this.lastDate !== date) {
dateElem.innerHTML = date.toUpperCase();
if (this.lastDate !== date) {
elemForEach('.date-time.date', (elem) => { elem.innerHTML = date.toUpperCase(); });
} }
this.lastDate = date; this.lastDate = date;
} }

View file

@ -1,4 +1,4 @@
<%- include('header.ejs', {titleDual:{ top: 'Current' , bottom: 'Conditions' }, noaaLogo: true}) %> <%- include('header.ejs', {titleDual:{ top: 'Current' , bottom: 'Conditions' }, noaaLogo: true, hasTime: true}) %>
<div class="main has-scroll has-box current-weather"> <div class="main has-scroll has-box current-weather">
<div class="weather template"> <div class="weather template">
<div class="left col"> <div class="left col">

View file

@ -1,4 +1,4 @@
<%- include('header.ejs', {titleDual:{ top: 'Latest' , bottom: 'Observations' }, noaaLogo: true }) %> <%- include('header.ejs', {titleDual:{ top: 'Latest' , bottom: 'Observations' }, noaaLogo: true, hasTime: true }) %>
<div class="main has-scroll latest-observations has-box"> <div class="main has-scroll latest-observations has-box">
<div class="container"> <div class="container">
<div class="column-headers"> <div class="column-headers">