[Bug] Android auto sleep timer window is set incorrectly #505

Closed
opened 2026-04-24 23:26:32 +02:00 by adam · 1 comment
Owner

Originally created by @advplyr on GitHub (Mar 26, 2023).

  • Start Calendar is set to right now
  • Start calendar is adjusted to the stored start hour and minute of the day the instance was created
  • End Calendar is set to right now
  • End calendar is adjusted to the stored end hour and minute of the day the instance was created
  • Check that if the end datetime is before the start datetime add a day to the end calendar

It seems like this logic might not be right.

  • Assume Start is set to 22:00
  • Assume End is set to 8:00
  • Assume checkAutoSleepTimer is run at 2023-03-27-00:30
  • Start calendar is 2023-03-27-22:00
  • End Calendar is 2023-03-27-08:00
  • 2023-03-27-08:00 is before 2023-03-27-22:00
  • End calendar becomes 2023-03-28-08:00
  • Window is now Start: 2023-03-27-22:00 - End: 2023-03-28-08:00
  • Current time is 2023-03-27-00:30
  • Current time is outside of start window
  • auto sleep time is not started

With out logs I can't verify this, but I believe this is a logic bug and is causing my sleep timer to not reset after midnight.

      val startCalendar = Calendar.getInstance()
      startCalendar.set(Calendar.HOUR_OF_DAY, deviceSettings.autoSleepTimerStartHour)
      startCalendar.set(Calendar.MINUTE, deviceSettings.autoSleepTimerStartMinute)
      val endCalendar = Calendar.getInstance()
      endCalendar.set(Calendar.HOUR_OF_DAY, deviceSettings.autoSleepTimerEndHour)
      endCalendar.set(Calendar.MINUTE, deviceSettings.autoSleepTimerEndMinute)

      // In cases where end time is earlier then start time then we add a day to end time
      //   e.g. start time 22:00 and end time 06:00. End time will be treated as 6am the next day.
      //   e.g. start time 08:00 and end time 22:00. Start and end time will be the same day.
      if (endCalendar.before(startCalendar)) {
        endCalendar.add(Calendar.DAY_OF_MONTH, 1)
      }

Originally posted by @chrishoage in https://github.com/advplyr/audiobookshelf-app/discussions/636#discussioncomment-5433912

Originally created by @advplyr on GitHub (Mar 26, 2023). - Start Calendar is set to right now - Start calendar is adjusted to the stored start hour and minute of the day the instance was created - End Calendar is set to right now - End calendar is adjusted to the stored end hour and minute of the day the instance was created - Check that if the end datetime is before the start datetime add a day to the end calendar It seems like this logic might not be right. - Assume Start is set to 22:00 - Assume End is set to 8:00 - Assume `checkAutoSleepTimer` is run at 2023-03-27-00:30 - Start calendar is 2023-03-27-22:00 - End Calendar is 2023-03-27-08:00 - 2023-03-27-08:00 is before 2023-03-27-22:00 - End calendar becomes 2023-03-28-08:00 - Window is now Start: 2023-03-27-22:00 - End: 2023-03-28-08:00 - Current time is 2023-03-27-00:30 - Current time is outside of start window - auto sleep time is not started With out logs I can't verify this, but I believe this is a logic bug and is causing my sleep timer to not reset after midnight. ```kt val startCalendar = Calendar.getInstance() startCalendar.set(Calendar.HOUR_OF_DAY, deviceSettings.autoSleepTimerStartHour) startCalendar.set(Calendar.MINUTE, deviceSettings.autoSleepTimerStartMinute) val endCalendar = Calendar.getInstance() endCalendar.set(Calendar.HOUR_OF_DAY, deviceSettings.autoSleepTimerEndHour) endCalendar.set(Calendar.MINUTE, deviceSettings.autoSleepTimerEndMinute) // In cases where end time is earlier then start time then we add a day to end time // e.g. start time 22:00 and end time 06:00. End time will be treated as 6am the next day. // e.g. start time 08:00 and end time 22:00. Start and end time will be the same day. if (endCalendar.before(startCalendar)) { endCalendar.add(Calendar.DAY_OF_MONTH, 1) } ``` _Originally posted by @chrishoage in https://github.com/advplyr/audiobookshelf-app/discussions/636#discussioncomment-5433912_
adam added the bug label 2026-04-24 23:26:32 +02:00
adam closed this issue 2026-04-24 23:26:32 +02:00
Author
Owner

@advplyr commented on GitHub (May 23, 2023):

Fixed in v0.9.64-beta

@advplyr commented on GitHub (May 23, 2023): Fixed in [v0.9.64-beta](https://github.com/advplyr/audiobookshelf-app/releases/tag/v0.9.64-beta)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf-app#505