Last active
July 17, 2020 00:34
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// #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}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// #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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// #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