Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created June 28, 2020 04:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/701319862f5f4cf8921f2db3e4526c0d to your computer and use it in GitHub Desktop.
Save parzibyte/701319862f5f4cf8921f2db3e4526c0d to your computer and use it in GitHub Desktop.
/*
Programado por Luis Cabrera Benito
____ _____ _ _ _
| _ \ | __ \ (_) | | |
| |_) |_ _ | |__) |_ _ _ __ _____| |__ _ _| |_ ___
| _ <| | | | | ___/ _` | '__|_ / | '_ \| | | | __/ _ \
| |_) | |_| | | | | (_| | | / /| | |_) | |_| | || __/
|____/ \__, | |_| \__,_|_| /___|_|_.__/ \__, |\__\___|
__/ | __/ |
|___/ |___/
Blog: https://parzibyte.me/blog
Ayuda: https://parzibyte.me/blog/contrataciones-ayuda/
Contacto: https://parzibyte.me/blog/contacto/
*/
import { Component, OnInit } from '@angular/core';
import { ClimaService } from './weather.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
cargando = false;
city = "";
region_name = "";
country_name = "";
hora = "";
detallesHoy = {};
detallesProximos = [];
constructor(private weatherService: ClimaService) {
}
comenzarReloj() {
const _this = this;
setInterval(() => {
let hora = "";
let fecha = new Date();
let horas = fecha.getHours();
let minutos = fecha.getMinutes();
let segundos = fecha.getSeconds();
let horasArregladas = horas.toString();
if (horas < 10) {
horasArregladas = "0" + horasArregladas;
}
let minutosArreglados = minutos.toString();
if (minutos < 10) {
minutosArreglados = "0" + minutosArreglados;
}
let segundosArreglados = segundos.toString();
if (segundos < 10) {
segundosArreglados = "0" + segundosArreglados;
}
_this.hora = `${horasArregladas}:${minutosArreglados}:${segundosArreglados}`;
}, 500);
}
async ngOnInit() {
// Hacer que se muestre el indicador de carga
this.cargando = true;
// Obtener los datos de ubicación
const datosDeUbicacion = await this.weatherService.obtenerDatosUbicacion();
this.city = datosDeUbicacion.city;
this.region_name = datosDeUbicacion.region_name;
this.country_name = datosDeUbicacion.country_name;
const { latitude, longitude } = datosDeUbicacion;
// Obtener, ahora, los datos del clima
const datosDeClima = await this.weatherService.obtenerDatosDeClima(latitude, longitude);
// Cortamos el arreglo para mostrar la de hoy, y también las siguientes
this.detallesHoy = datosDeClima.dataseries.slice(0, 1)[0];
this.detallesProximos = datosDeClima.dataseries.slice(1, 5);
// Ocultamos el indicador de carga y comenzamos el reloj
this.cargando = false;
this.comenzarReloj();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment