From 84b39a9edcf324da3a4d9280d196e939622f34ef Mon Sep 17 00:00:00 2001 From: Jaylyn Barbee <51131738+Jaylyn-Barbee@users.noreply.github.com> Date: Mon, 2 Feb 2026 09:33:25 -0500 Subject: [PATCH] [Light Switch] Changed the rules surrounding the max/min value of the Offset field (#45125) ## Summary of the Pull Request This PR introduces new logic that dictates the max and min value for the `Offset` field that the user can change when using Sunrise to Sunset mode. ## PR Checklist - [x] Closes: #44959 - [x] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected ## Detailed Description of the Pull Request / Additional comments The new logic is as follows: - The sunrise offset cannot go into the previous day and cannot overlap the current sunset transition time - The sunset offset cannot overlap the last sunrise time and cannot overlap into the next day. These values are dynamic and update when the VM updates with new times. ## Validation Steps Performed - Manual testing --- .../SettingsXAML/Views/LightSwitchPage.xaml | 8 ++-- .../ViewModels/LightSwitchViewModel.cs | 44 +++++++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/LightSwitchPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/LightSwitchPage.xaml index a44d482a04..e1d6d8013c 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/LightSwitchPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/LightSwitchPage.xaml @@ -112,8 +112,8 @@ @@ -121,8 +121,8 @@ diff --git a/src/settings-ui/Settings.UI/ViewModels/LightSwitchViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/LightSwitchViewModel.cs index 05aec49c9a..6d3c83c8ba 100644 --- a/src/settings-ui/Settings.UI/ViewModels/LightSwitchViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/LightSwitchViewModel.cs @@ -232,6 +232,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels NotifyPropertyChanged(); OnPropertyChanged(nameof(LightTimeTimeSpan)); + OnPropertyChanged(nameof(SunriseOffsetMin)); + OnPropertyChanged(nameof(SunsetOffsetMin)); if (ScheduleMode == "SunsetToSunrise") { @@ -252,6 +254,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels NotifyPropertyChanged(); OnPropertyChanged(nameof(DarkTimeTimeSpan)); + OnPropertyChanged(nameof(SunriseOffsetMax)); + OnPropertyChanged(nameof(SunsetOffsetMax)); if (ScheduleMode == "SunsetToSunrise") { @@ -270,6 +274,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { ModuleSettings.Properties.SunriseOffset.Value = value; OnPropertyChanged(nameof(LightTimeTimeSpan)); + OnPropertyChanged(nameof(SunsetOffsetMin)); } } } @@ -283,10 +288,49 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels { ModuleSettings.Properties.SunsetOffset.Value = value; OnPropertyChanged(nameof(DarkTimeTimeSpan)); + OnPropertyChanged(nameof(SunriseOffsetMax)); } } } + public int SunriseOffsetMin + { + get + { + // Minimum: don't let adjusted sunrise go before 00:00 + return -LightTime; + } + } + + public int SunriseOffsetMax + { + get + { + // Maximum: adjusted sunrise must stay before adjusted sunset + int adjustedSunset = DarkTime + SunsetOffset; + return Math.Max(0, adjustedSunset - LightTime - 1); + } + } + + public int SunsetOffsetMin + { + get + { + // Minimum: adjusted sunset must stay after adjusted sunrise + int adjustedSunrise = LightTime + SunriseOffset; + return Math.Min(0, adjustedSunrise - DarkTime + 1); + } + } + + public int SunsetOffsetMax + { + get + { + // Maximum: don't let adjusted sunset go past 23:59 (1439 minutes) + return 1439 - DarkTime; + } + } + // === Computed projections (OneWay bindings only) === public TimeSpan LightTimeTimeSpan {