Created
June 10, 2016 10:51
-
-
Save AbraaoAlves/3231d59954fe0be6a1f18b77f8a1a72a to your computer and use it in GitHub Desktop.
custom types in #typescript
This file contains hidden or 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
| //enums não são necessarios, types strings não sujam o seu JS | |
| function timeParse(date, format) { | |
| if(format === "unixparse"){ | |
| return JSON.stringify({"unixtime": date.getTime()}); | |
| } | |
| if(format === "parsetime"){ | |
| var summary = { | |
| "hour": date.getHours(), | |
| "minute":date.getMinutes(), | |
| "second": date.getSeconds() | |
| }; | |
| return JSON.stringify(summary); | |
| } | |
| } | |
| console.log(timeParse(new Date(), "unixparse")); | |
| //console.log(timeParse(new Date(), "parsetiem")); |
This file contains hidden or 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
| //enums não são necessarios, types strings não sujam o seu JS | |
| types formats = "unixparse" | "parsetime"; | |
| function timeParse(date: Date, format: formats): string { | |
| if(format === "unixparse"){ | |
| return JSON.stringify({"unixtime": date.getTime()}); | |
| } | |
| if(format === "parsetime"){ | |
| var summary = { | |
| "hour": date.getHours(), | |
| "minute":date.getMinutes(), | |
| "second": date.getSeconds() | |
| }; | |
| return JSON.stringify(summary); | |
| } | |
| } | |
| console.log(timeParse(new Date(), "unixparse")); | |
| //console.log(timeParse(new Date(), "parsetiem")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment