Find the time between two dates in seconds, minutes, etc.
Created
December 28, 2013 03:57
-
-
Save joyrexus/8155981 to your computer and use it in GitHub Desktop.
Time between two dates
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
# Find the time between two dates | |
module.exports = (begin, end) -> | |
end ?= new Date() | |
time = | |
end: end | |
begin: begin | |
time.secs = (end - begin) / 1000 | |
time.mins = time.secs / 60 | |
time.hours = time.mins / 60 | |
time.days = time.hours / 24 | |
time.months = time.days / 30 | |
time.years = time.days / 365 | |
time |
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
assert = require 'assert' | |
duration = require '../duration' | |
from = new Date("Jan 20, 2009") | |
to = new Date("Feb 20, 2011") | |
time = duration(from, to) | |
assert.ok time.days is 761 | |
assert.ok 2 < time.years < 3 | |
assert.ok 25 < time.months < 26 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment