Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
advplyr opened this issue Mar 26, 2023 · 1 comment
Closed

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

advplyr opened this issue Mar 26, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@advplyr
Copy link
Owner

advplyr commented 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 #636 (reply in thread)

@advplyr advplyr added the bug Something isn't working label Mar 26, 2023
@advplyr
Copy link
Owner Author

advplyr commented May 23, 2023

Fixed in v0.9.64-beta

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant