Skip to content

Instantly share code, notes, and snippets.

@lucasreta
Last active July 17, 2020 00:34
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 lucasreta/839b167b1f52e760edb26873210b5952 to your computer and use it in GitHub Desktop.
Save lucasreta/839b167b1f52e760edb26873210b5952 to your computer and use it in GitHub Desktop.
GIST hecho por #AwsomEntrepriseCouding VIDEOS INCORPORATED todos los derechos RESERVADOS (pero codigo abierto y no recomendable)
// #AwsomEntrepriseCouding version 1.0
// mi clase de tiempo
bisi = (ano) => ano%400 == 0 || (ano%4 == 0 && ano%100 != 0)
messi = [null,31,28,31,30,31,30,31,31,30,31,30,31]
validate = (ano, mes, dia) => dia > 0 && ((mes == 2 && bisi(ano) && messi[mes]+1 >= dia) || ((!bisi(ano) || mes != 2) && messi[mes] >= dia))
class fecha {#ano;#mes;#dia; constructor(ano, mes, dia) { if (validate(ano,mes,dia)) {this.#ano=ano; this.#mes=mes; this.#dia=dia;} else {throw new Error('fecha invalida mostro')}} getdia(){return this.#dia} getmes(){return this.#mes} getano(){return this.#ano}}
// #AwsomEntrepriseCouding version 1.0
// mi clase de tiempo
bisi = (ano) => ano % 400 == 0 || (ano % 4 == 0 && ano % 100 != 0)
messi = [null,31,28,31,30,31,30,31,31,30,31,30,31];
validate = (ano, mes, dia) => {
return dia > 0 &&
((mes == 2 && bisi(ano) && messi[mes]+1 >= dia) ||
((!bisi(ano) || mes != 2) && messi[mes] >= dia))
};
class fecha {
#ano; #mes; #dia;
constructor(ano, mes, dia) {
if (validate(ano,mes,dia)) {
this.#ano=ano;
this.#mes=mes;
this.#dia=dia;
} else {
throw new Error('fecha invalida mostro')
}
}
getdia(){
return this.#dia
}
getmes(){
return this.#mes
}
getano(){
return this.#ano
}
}
// #NotAwsomEntrepriseCouding
// o "como haria esto si de verdad tuviera motivo
// para crear una clase propia para manejar fechas simples"
class SimpleDate {
#year; #month; #day;
constructor(year, month, day) {
if (!this.isValid(year, month, day))
throw new Error('SimpleDate.constructor Error: Invalid Date')
this.#year = year;
this.#month = month;
this.#day = day;
}
months = [31,28,31,30,31,30,31,31,30,31,30,31];
isLeap = (year) => year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
isValid = (year, month, day) => day > 0 &&
(month == 2 && this.isLeap(year) && day <= 29) ||
((month != 2 || !this.isLeap(year)) && day <= this.months[month-1]);
getYear = () => this.#year;
getMonth = () => this.#month;
getDay = () => this.#day;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment