[Light Switch] Changed the rules surrounding the max/min value of the Offset field (#45125)

<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## 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.

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [x] Closes: #44959
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [x] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## 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.
<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
- Manual testing
This commit is contained in:
Jaylyn Barbee
2026-02-02 09:33:25 -05:00
committed by GitHub
parent 67d96b0a13
commit 84b39a9edc
2 changed files with 48 additions and 4 deletions

View File

@@ -112,8 +112,8 @@
<controls:IsEnabledTextBlock x:Uid="LightSwitch_SunriseText" VerticalAlignment="Center" />
<NumberBox
AutomationProperties.AutomationId="SunriseOffset_LightSwitch"
Maximum="60"
Minimum="-60"
Maximum="{x:Bind ViewModel.SunriseOffsetMax, Mode=OneWay}"
Minimum="{x:Bind ViewModel.SunriseOffsetMin, Mode=OneWay}"
SpinButtonPlacementMode="Compact"
Value="{x:Bind ViewModel.SunriseOffset, Mode=TwoWay}" />
</StackPanel>
@@ -121,8 +121,8 @@
<controls:IsEnabledTextBlock x:Uid="LightSwitch_SunsetText" VerticalAlignment="Center" />
<NumberBox
AutomationProperties.AutomationId="SunsetOffset_LightSwitch"
Maximum="60"
Minimum="-60"
Maximum="{x:Bind ViewModel.SunsetOffsetMax, Mode=OneWay}"
Minimum="{x:Bind ViewModel.SunsetOffsetMin, Mode=OneWay}"
SpinButtonPlacementMode="Compact"
Value="{x:Bind ViewModel.SunsetOffset, Mode=TwoWay}" />
</StackPanel>

View File

@@ -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
{