Thanks for your comment @fil!
If I understand your suggestion, I believe I’m already doing this! Here’s a bit more detail:
The bulk of the data processing happens in https://observablehq.com/@cydneyn/sleep-data-processing
Most sleeps span midnight such that they start on one date and end on the next date. For plotting convenience, I want all my sleep segments from a given night’s sleep to have the same date. I can then use that date to group the sleep segments and easily do things like make a line per night, etc.
The function timeToMidnight() in my data processing notebook contains the logic for (1) calculating the sleep segment’s start in terms of hours from midnight (0 for midnight itself, negative numbers for before midnight, and positive ones for after midnight) and (2) assigning a consistent date to all sleep segments from a night’s sleep.
In the resulting processed data used here, it looks like all the sleep segments from a night’s sleep have the same date, but the series is indeed cut in the daytime hours not midnight.
Hope this makes sense!
Totally makes sense! My confusion comes from the fact that I'm viewing this notebook from Europe, and the charts are wrong. But when I set my computer to TZ America/Los_Angeles, they look perfect. Tweaking the timeToMidnight function so that it works independently of the viewer's (browser) timezone is… hard.
Ah interesting. I considered this problem originally and it was in part why I decided to convert the times into hours from midnight, but I overlooked that the raw data parsing converts times into the local time zone.
I've updated the data processing notebook to preserve the original time zone and the plots now look good when I change my computer's time zone. Let me know if this works for you and thanks again for the helpful feedback!