Skip to content

Instantly share code, notes, and snippets.

@AbraaoAlves
Created June 10, 2016 10:51
Show Gist options
  • Select an option

  • Save AbraaoAlves/3231d59954fe0be6a1f18b77f8a1a72a to your computer and use it in GitHub Desktop.

Select an option

Save AbraaoAlves/3231d59954fe0be6a1f18b77f8a1a72a to your computer and use it in GitHub Desktop.
custom types in #typescript
//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"));
//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