From 949236d6148aa800970ca39bfb2fc321787677b9 Mon Sep 17 00:00:00 2001 From: angerhang <514140809@qq.com> Date: Tue, 16 Jul 2024 14:21:07 +0100 Subject: [PATCH] Fix boundary condition for start date after noon. Thanks @BernieVA (#52) This fix should address https://github.com/OxWearables/asleep/issues/43 --- src/asleep/sleep_windows.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/asleep/sleep_windows.py b/src/asleep/sleep_windows.py index 7d4e281..d570d0b 100644 --- a/src/asleep/sleep_windows.py +++ b/src/asleep/sleep_windows.py @@ -272,7 +272,10 @@ def get_day_intervals(start_date, end_date, date_format): my_day_end = pd.to_datetime(day_end_str, format=date_format) my_day_start = start_date.replace( hour=12, minute=0, second=0, microsecond=0) - my_day_start = my_day_start - timedelta(hours=24) + + # if the start date is before 12:00 noon, then the interval start is 24 hours prior + if start_date.hour < 12: + my_day_start = my_day_start - timedelta(hours=24) while my_day_end < end_date: my_day_end = my_day_start + timedelta(hours=23, minutes=59, seconds=59)