diff --git a/jumpapp/assets/js/index.bundle.js b/jumpapp/assets/js/index.bundle.js index 5ef5083..3276265 100644 --- a/jumpapp/assets/js/index.bundle.js +++ b/jumpapp/assets/js/index.bundle.js @@ -1 +1,2 @@ -(()=>{"use strict";class t{constructor(t=0){this.utcshift=1e3*t,this.shiftedtimestamp=(new Date).getTime()+this.utcshift,this.shifteddate=new Date(this.shiftedtimestamp)}get_formatted_time(){return String(this.shifteddate.getHours()).padStart(2,"0")+":"+String(this.shifteddate.getMinutes()).padStart(2,"0")}get_hour(){return this.shifteddate.getHours()}}class e{constructor(t){this.hour=t.get_hour(),this.greetings={0:"morning",12:"afternoon",16:"evening",19:"night"}}get_greeting(){let t=Object.keys(this.greetings).reverse();for(let e of t)if(this.hour>=e)return this.greetings[e]}}class i{constructor(t,e){this.owmapiurlbase="https://api.openweathermap.org/data/2.5/weather",this.owmapikey=t,this.latlong=e}async fetch_owm_data(){const t=this.owmapiurlbase+"?lat="+this.latlong[0]+"&lon="+this.latlong[1]+"&appid="+this.owmapikey;return await fetch(t).then((t=>t.json())).then((t=>{401===t.cod&&alert("The OWM API key is invalid, check config.php");var e="night";return t.dt>t.sys.sunrise&&t.dt{this.timezoneshift=t.timezoneshift,this.refresh_basic_content(),this.holderelm.href+="city/"+t.locationcode,this.weatherelm.classList.add(t.iconclass),this.clientlocationelm.innerHTML=t.locationname,this.clientlocationelm.addEventListener("click",(t=>{navigator.geolocation.getCurrentPosition((t=>{this.latlong=[t.coords.latitude,t.coords.longitude],this.storage.setItem("lastrequestedlocation",JSON.stringify(this.latlong)),this.init()}),null,{enableHighAccuracy:!0})}),{once:!0}),this.clientlocationelm.classList.add("enable"),this.show_content()}))}show_content(){document.querySelectorAll(".hidden").forEach((function(t){t.classList.remove("hidden")}))}update_basic_content(){let i=new t(this.timezoneshift),s=new e(i);this.timeelm.innerHTML=i.get_formatted_time(),this.greetingelm.innerHTML=s.get_greeting()}refresh_basic_content(){this.contentintervalid&&clearInterval(this.contentintervalid),this.update_basic_content(),this.contentintervalid=setInterval((()=>{this.update_basic_content()}),this.updatefrequency)}}).init()})(); \ No newline at end of file +/*! For license information please see index.bundle.js.LICENSE.txt */ +(()=>{"use strict";class t{constructor(t=0){this.utcshift=1e3*t,this.shiftedtimestamp=(new Date).getTime()+this.utcshift,this.shifteddate=new Date(this.shiftedtimestamp)}get_formatted_time(){return String(this.shifteddate.getUTCHours()).padStart(2,"0")+":"+String(this.shifteddate.getUTCMinutes()).padStart(2,"0")}get_hour(){return this.shifteddate.getUTCHours()}}class e{constructor(t){this.hour=t.get_hour(),this.greetings={0:"morning",12:"afternoon",16:"evening",19:"night"}}get_greeting(){let t=Object.keys(this.greetings).reverse();for(let e of t)if(this.hour>=e)return this.greetings[e]}}class i{constructor(t,e){this.owmapiurlbase="https://api.openweathermap.org/data/2.5/weather",this.owmapikey=t,this.latlong=e}async fetch_owm_data(){const t=this.owmapiurlbase+"?lat="+this.latlong[0]+"&lon="+this.latlong[1]+"&appid="+this.owmapikey;return await fetch(t).then((t=>t.json())).then((t=>{401===t.cod&&alert("The OWM API key is invalid, check config.php");var e="night";return t.dt>t.sys.sunrise&&t.dt{this.timezoneshift=t.timezoneshift,this.refresh_basic_content(),this.holderelm.href+="city/"+t.locationcode,this.weatherelm.classList.add(t.iconclass),this.clientlocationelm.innerHTML=t.locationname,this.clientlocationelm.addEventListener("click",(t=>{navigator.geolocation.getCurrentPosition((t=>{this.latlong=[t.coords.latitude,t.coords.longitude],this.storage.setItem("lastrequestedlocation",JSON.stringify(this.latlong)),this.init()}),null,{enableHighAccuracy:!0})}),{once:!0}),this.clientlocationelm.classList.add("enable"),this.show_content()}))}show_content(){document.querySelectorAll(".hidden").forEach((function(t){t.classList.remove("hidden")}))}update_basic_content(){let i=new t(this.timezoneshift),s=new e(i);this.timeelm.innerHTML=i.get_formatted_time(),this.greetingelm.innerHTML=s.get_greeting()}refresh_basic_content(){this.contentintervalid&&clearInterval(this.contentintervalid),this.update_basic_content(),this.contentintervalid=setInterval((()=>{this.update_basic_content()}),this.updatefrequency)}}).init()})(); \ No newline at end of file diff --git a/jumpapp/assets/js/src/classes/Clock.js b/jumpapp/assets/js/src/classes/Clock.js index a683593..328a55c 100644 --- a/jumpapp/assets/js/src/classes/Clock.js +++ b/jumpapp/assets/js/src/classes/Clock.js @@ -1,18 +1,45 @@ +/** + * Calculate the time, local to the requested location from + * the OpenWeather API, by passing in the number of seconds + * that location has shifted from UTC based on the timezones. + * + * @author Dale Davies + * @license MIT + */ + export default class Clock { + /** + * Calculate the time shifted from UTC. + * + * @param number utcshift Number of seconds to shift time from UTC. + */ constructor(utcshift = 0) { this.utcshift = utcshift*1000; this.shiftedtimestamp = new Date().getTime()+this.utcshift; this.shifteddate = new Date(this.shiftedtimestamp); } + /** + * Return a string representing time in HH:MM format. + * + * @returns string The time string. + */ get_formatted_time() { - const hour = String(this.shifteddate.getHours()).padStart(2, "0"); - const minutes = String(this.shifteddate.getMinutes()).padStart(2, "0"); + // We need to use getUTCHours and getUTC Minutes here to stop + // the Date() object adjusting the returned time relative to the + // browser's local timezone. + const hour = String(this.shifteddate.getUTCHours()).padStart(2, "0"); + const minutes = String(this.shifteddate.getUTCMinutes()).padStart(2, "0"); return hour + ":" + minutes; } + /** + * Returns just the hour. + * + * @returns number The hour. + */ get_hour() { - return this.shifteddate.getHours(); + return this.shifteddate.getUTCHours(); } }