Created
August 19, 2013 12:08
-
-
Save potato2003/6268428 to your computer and use it in GitHub Desktop.
Pretty。
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
module.exports = (time) -> | |
elapse = | |
if time instanceof Date | |
time.getTime() - Date.now() | |
else if typeof time == "number" | |
time - Date.now() | |
else | |
console.warn "Given a invalid date type(\"#{typeof time}\") arguments. expected date type is Date or Number." | |
"" | |
if elapse < 10.sec | |
return "たった今" | |
if elapse < 30.sec | |
return "30秒前" | |
if elapse < 1.hour | |
return "#{Math.floor(elapse / 1.min)}分前" | |
if elapse < 1.day | |
return "#{Math.floor(elapse / 1.hour)}時間前" | |
if elapse < 1.week | |
return "#{Math.floor(elapse / 1.day)}日前" | |
if elapse < 1.year | |
return "x月x日" | |
return "x年x月x日" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment