From de814b9e04ee3cda0f14d99119e06308245dee29 Mon Sep 17 00:00:00 2001 From: apivko <67239962+apivko@users.noreply.github.com> Date: Sun, 30 Oct 2022 15:28:58 +0200 Subject: [PATCH] Displaying the timezone hour near temprature for each location (#449) Co-authored-by: Bastien Wirtz --- src/components/services/OpenWeather.vue | 29 ++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/components/services/OpenWeather.vue b/src/components/services/OpenWeather.vue index ba0be96..3169866 100644 --- a/src/components/services/OpenWeather.vue +++ b/src/components/services/OpenWeather.vue @@ -22,7 +22,12 @@

{{ name }}

- {{ temperature }} + + {{ temp | tempSuffix(this.item.units) }} + + + {{ locationTime }} +

@@ -49,6 +54,7 @@ export default { temp: null, conditions: null, error: false, + timezoneOffset: 0, }), computed: { temperature: function () { @@ -66,6 +72,11 @@ export default { created() { this.fetchWeather(); }, + computed: { + locationTime: function () { + return this.calcTime(this.timezoneOffset); + }, + }, methods: { fetchWeather: async function () { let locationQuery; @@ -92,12 +103,23 @@ export default { this.temp = parseInt(weather.main.temp).toFixed(1); this.icon = weather.weather[0].icon; this.conditions = weather.weather[0].description; + this.timezoneOffset = weather.timezone; }) .catch((e) => { console.log(e); this.error = true; }); }, + calcTime: (offset) => { + const localTime = new Date(); + const utcTime = + localTime.getTime() + localTime.getTimezoneOffset() * 60000; + const calculatedTime = new Date(utcTime + 1000 * offset); + return calculatedTime.toLocaleString([], { + hour: "2-digit", + minute: "2-digit", + }); + }, }, }; @@ -133,4 +155,9 @@ export default { } } } + +//Location Time +.location-time { + margin-left: 20px; +}