Skip to content

Instantly share code, notes, and snippets.

@Dafrok
Last active September 14, 2017 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dafrok/693817dd6ad3656c71b1f17b9d51fe83 to your computer and use it in GitHub Desktop.
Save Dafrok/693817dd6ad3656c71b1f17b9d51fe83 to your computer and use it in GitHub Desktop.
function timeDec(t1, t2) {
const DAY = 24 * 60 * 60 * 1000
const SPACING = DAY * 7 / 24
const t = d => ((r = new Date(d), (22<= r < 6) ? new Date(r.setHours(22)) : r >= 0 ? new Date(r - DAY) : new Date(r)).getTime())
const dec = t(t1) - t(t2)
return Math.abs(dec- ((dec / DAY) | 0) * SPACING)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment