Created
January 20, 2019 22:47
-
-
Save yorickvP/5941a2b07d789e21584533d3812d2982 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // 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