Created
June 7, 2012 20:11
-
-
Save bolshakov/2891275 to your computer and use it in GitHub Desktop.
Humaniser usage
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
# First, we'll need a bunch of helpers -- `m()` for minutes | |
# and `s()` for seconds: | |
s = (sec) -> sec * 1000 | |
m = (min) -> min * s(60) | |
# Humanizer.between(from, to, includeSeconds) | |
# | |
# Returns the approximate distance in time between | |
# two given objects, which can either be `Date` or | |
# `Number` instances. When `includeSeconds` is `true`, | |
# `Humanizer` calculates a more precise approximation, for | |
# intervals under one and a half minutes. | |
from = new Date() | |
# => Sat, 23 Jul 2011 00:52:59 GMT | |
Humanizer.between(from, from - m(65)) | |
# => "about 1 hour" | |
Humanizer.between(from, from + s(15), true) | |
# => "less than 20 seconds" | |
# Humanizer.since(from, to, includeSeconds) | |
# | |
# Just like `#between()`, but the second | |
# argument is fixed to `new Date()`. | |
Humanizer.since(new Date() + m(3)) | |
# => "3 minutes" | |
Humanizer.since(new Date()) | |
# =>"less than a minute" |
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
<head> | |
<script src="lib/humanizer.js"></script> | |
<script src="lib/locales/humanizer.fr.js"></script> | |
<script src="lib/locales/humanizer.en.js"></script> | |
<script> | |
var bicycleDay = Date.parse("November 16, 1938"); | |
Humanizer.locale("fr").since(bicycleDay); | |
</script> | |
</head> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment