Skip to content

Instantly share code, notes, and snippets.

@potato2003
Created August 19, 2013 12:08
Show Gist options
  • Save potato2003/6268428 to your computer and use it in GitHub Desktop.
Save potato2003/6268428 to your computer and use it in GitHub Desktop.
Pretty。
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