Skip to content

Instantly share code, notes, and snippets.

@aaronjorbin
Created April 26, 2016 01:32
Show Gist options
  • Save aaronjorbin/308d4cf204f605e943adb9ad16720e5e to your computer and use it in GitHub Desktop.
Save aaronjorbin/308d4cf204f605e943adb9ad16720e5e to your computer and use it in GitHub Desktop.
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