mirror of https://github.com/bastienwirtz/homer
Displaying the timezone hour near temprature for each location (#449)
Co-authored-by: Bastien Wirtz <bastien.wirtz@gmail.com>pull/540/head
parent
3ed40599e5
commit
de814b9e04
|
@ -22,7 +22,12 @@
|
||||||
<div v-else>
|
<div v-else>
|
||||||
<p class="title is-4">{{ name }}</p>
|
<p class="title is-4">{{ name }}</p>
|
||||||
<p class="subtitle is-6">
|
<p class="subtitle is-6">
|
||||||
{{ temperature }}
|
<span>
|
||||||
|
{{ temp | tempSuffix(this.item.units) }}
|
||||||
|
</span>
|
||||||
|
<span class="location-time">
|
||||||
|
{{ locationTime }}
|
||||||
|
</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -49,6 +54,7 @@ export default {
|
||||||
temp: null,
|
temp: null,
|
||||||
conditions: null,
|
conditions: null,
|
||||||
error: false,
|
error: false,
|
||||||
|
timezoneOffset: 0,
|
||||||
}),
|
}),
|
||||||
computed: {
|
computed: {
|
||||||
temperature: function () {
|
temperature: function () {
|
||||||
|
@ -66,6 +72,11 @@ export default {
|
||||||
created() {
|
created() {
|
||||||
this.fetchWeather();
|
this.fetchWeather();
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
locationTime: function () {
|
||||||
|
return this.calcTime(this.timezoneOffset);
|
||||||
|
},
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
fetchWeather: async function () {
|
fetchWeather: async function () {
|
||||||
let locationQuery;
|
let locationQuery;
|
||||||
|
@ -92,12 +103,23 @@ export default {
|
||||||
this.temp = parseInt(weather.main.temp).toFixed(1);
|
this.temp = parseInt(weather.main.temp).toFixed(1);
|
||||||
this.icon = weather.weather[0].icon;
|
this.icon = weather.weather[0].icon;
|
||||||
this.conditions = weather.weather[0].description;
|
this.conditions = weather.weather[0].description;
|
||||||
|
this.timezoneOffset = weather.timezone;
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
this.error = true;
|
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",
|
||||||
|
});
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -133,4 +155,9 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Location Time
|
||||||
|
.location-time {
|
||||||
|
margin-left: 20px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue