Bug 511293

Summary: Setting night light sunset time after midnight, but before sunrise time causes it to turn on when it shouldn't
Product: [Plasma] plasmashell Reporter: Stian <evokeglorybottling>
Component: Day/night scheduleAssignee: Plasma Bugs List <plasma-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: nate, vlad.zahorodnii
Priority: NOR Keywords: regression
Version First Reported In: 6.5.0   
Target Milestone: 1.0   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed/Implemented In: 6.5.2
Sentry Crash Report:

Description Stian 2025-10-28 22:21:45 UTC
SUMMARY
Setting night light sunset time after midnight, but before sunrise time causes it to turn on when it shouldn't

STEPS TO REPRODUCE
1. Set Night Light to 'Sunrise and sunset'
2. Use custom sunrise and sunset times
3. Set sunset time to midnight or after, but before the sunrise time and after current time.
4. Hit apply

OBSERVED RESULT
Night light turns on immidiately after hitting apply, despite it being too early. (E.G. current time is 18:00, sunset time is set to 01:00 and night mode turns on) 

EXPECTED RESULT
Night light turns on after sunset time has passed

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 6.5.0
KDE Frameworks Version: 6.19.0
Qt Version: 6.10.0
Kernel Version: 6.17.5-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 16 × AMD Ryzen 7 3700X 8-Core Processor
Memory: 48 GiB of RAM (47.0 GiB usable)
Graphics Processor: NVIDIA GeForce RTX 2070 SUPER

ADDITIONAL INFORMATION
Transition duration seemingly doesn't matter
Comment 1 Bug Janitor Service 2025-10-29 08:43:31 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/knighttime/-/merge_requests/13
Comment 2 Vlad Zahorodnii 2025-10-29 11:05:47 UTC
Git commit ce36931b53817c761540d099646b71c6458300d7 by Vlad Zahorodnii.
Committed on 29/10/2025 at 09:21.
Pushed by vladz into branch 'master'.

Fix daylight duration with flipped morning and evening times

If the evening time is before the morning time, QTime::secsTo() will
return a negative value. In that case, morning.secsTo(evening) is going
to actualy specify the time between evening and morning. For example,
witb the following times

  - evening: 1:00 AM
  - morning: 6:00 AM

morning.secsTo(evening) is going to return -18000, which is not what we
really expect. The issue can be addressed by applying a modulo operator.
But in order to make the code slightly more readable, this change goes
with an explicit "seconds in a day - time from evening to morning" formula.

M  +39   -16   autotests/schedule_test.cpp
M  +11   -1    src/kdarklightschedule.cpp

https://invent.kde.org/plasma/knighttime/-/commit/ce36931b53817c761540d099646b71c6458300d7
Comment 3 Vlad Zahorodnii 2025-10-29 11:16:40 UTC
Git commit d906175dbf792b4a363b059c00bfe7677dd28517 by Vlad Zahorodnii.
Committed on 29/10/2025 at 11:06.
Pushed by vladz into branch 'Plasma/6.5'.

Fix daylight duration with flipped morning and evening times

If the evening time is before the morning time, QTime::secsTo() will
return a negative value. In that case, morning.secsTo(evening) is going
to actualy specify the time between evening and morning. For example,
witb the following times

  - evening: 1:00 AM
  - morning: 6:00 AM

morning.secsTo(evening) is going to return -18000, which is not what we
really expect. The issue can be addressed by applying a modulo operator.
But in order to make the code slightly more readable, this change goes
with an explicit "seconds in a day - time from evening to morning" formula.


(cherry picked from commit ce36931b53817c761540d099646b71c6458300d7)

Co-authored-by: Vlad Zahorodnii <vlad.zahorodnii@kde.org>

M  +39   -16   autotests/schedule_test.cpp
M  +11   -1    src/kdarklightschedule.cpp

https://invent.kde.org/plasma/knighttime/-/commit/d906175dbf792b4a363b059c00bfe7677dd28517