Created
April 26, 2016 01:32
-
-
Save aaronjorbin/308d4cf204f605e943adb9ad16720e5e to your computer and use it in GitHub Desktop.
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
let t1 = 1433116798; // 2 seconds before midnight d1 | |
let t2 = 1433116799; // 1 second before midnight d1 | |
let t3 = 1433116801; // 1 seoncd after midnight d2 | |
let t4 = 1433203201; // 1 second after midnight d3 | |
const DAY_IN_SECONDS = 86400; | |
let days_since_epoch = t => { | |
return Math.floor( t / DAY_IN_SECONDS ); | |
} | |
let days_span = ( start, end ) =>{ | |
return Math.abs( days_since_epoch( start ) - days_since_epoch( end ) ) + 1 | |
} | |
// 1 | |
console.log( days_span( t1, t2 ) ); | |
// 2 | |
console.log( days_span( t1, t3 ) ); | |
// 3 | |
console.log( days_span( t1, t4 ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment