Skip to content

Instantly share code, notes, and snippets.

@yorickvP
Created January 20, 2019 22:47
Show Gist options
  • Select an option

  • Save yorickvP/5941a2b07d789e21584533d3812d2982 to your computer and use it in GitHub Desktop.

Select an option

Save yorickvP/5941a2b07d789e21584533d3812d2982 to your computer and use it in GitHub Desktop.
// from https://sleep-cloud.appspot.com/fetchRecords
var sleeps = require('./sleeps.json').sleeps
const todate = n => {
const d = new Date(n)
return `${d.getFullYear()}-${d.getMonth()+1}-${d.getDate()}`
}
//var earliest = todate(sleeps[sleeps.length - 1].toTime)
//console.log(earliest)
const all = {}
sleeps.forEach(({fromTime, toTime}) => {
const from = new Date(fromTime)
const target = new Date(fromTime)
target.setHours(4, 0, 0, 0)
// if from is after 4am, move 4am to next day
if (from > target) target.setDate(target.getDate()+1)
const key = todate(target)
if (toTime < target) {
if (!all[key]) all[key] = false
} else {
all[key] = true
}
})
console.log(all)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment