diff --git a/01-basics/20-weather/WeatherApp.js b/01-basics/20-weather/WeatherApp.js index 54dbfd6..aa9e5c8 100644 --- a/01-basics/20-weather/WeatherApp.js +++ b/01-basics/20-weather/WeatherApp.js @@ -1,47 +1,77 @@ -import { defineComponent } from 'vue' +import { defineComponent, ref } from 'vue' import { getWeatherData, WeatherConditionIcons } from './weather.service.ts' export default defineComponent({ name: 'WeatherApp', + + setup() { + const weatherData = ref(getWeatherData()) + + const kelvinToCelsius = (temp) => { + return (temp - 273.15).toFixed(1) + } + + const isNightTime = (currentDt, sunrise, sunset) => { + const currentTime = new Date(`1970-01-01T${currentDt}:00`).getHours() + const sunriseHour = parseInt(sunrise.split(':')[0], 10) + const sunsetHour = parseInt(sunset.split(':')[0], 10) + + return currentTime < sunriseHour || currentTime >= sunsetHour + } + + return { + weatherData, + kelvinToCelsius, + WeatherConditionIcons, + isNightTime, + } + }, template: `