forked from microsoft/PowerToys
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PTRun][DateTime]Setting for
First week of year
and `First day of w…
…eek` (microsoft#33406) ## Summary of the Pull Request This PR implements two new plugin settings: - **First week of year** ![image](https://github.com/microsoft/PowerToys/assets/61519853/c866ffc2-2a21-438c-9a1a-5f4c7f68a22e) - **First day of week** ![image](https://github.com/microsoft/PowerToys/assets/61519853/b2ec125b-d87c-40c5-8793-743a1ffae237) ## Detailed Description of the Pull Request / Additional comments For both settings the users can decide to be in sync with the system settings (default) or to use their own setting. The order of days for the `first day of week` setting is based on the current system culture. PT Run respects these settings for the relevant results: - calendar week - week of month - number of day in week
- Loading branch information
Showing
9 changed files
with
483 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...ncher/Plugins/Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests/TimeAndDateHelperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Globalization; | ||
using Microsoft.PowerToys.Run.Plugin.TimeDate.Components; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
namespace Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests | ||
{ | ||
[TestClass] | ||
public class TimeAndDateHelperTests | ||
{ | ||
[DataTestMethod] | ||
[DataRow(-1, null)] // default setting | ||
[DataRow(0, CalendarWeekRule.FirstDay)] | ||
[DataRow(1, CalendarWeekRule.FirstFullWeek)] | ||
[DataRow(2, CalendarWeekRule.FirstFourDayWeek)] | ||
[DataRow(30, null)] // wrong setting | ||
public void GetCalendarWeekRuleBasedOnPluginSetting(int setting, CalendarWeekRule? valueExpected) | ||
{ | ||
// Act | ||
var result = TimeAndDateHelper.GetCalendarWeekRule(setting); | ||
|
||
// Assert | ||
if (valueExpected == null) | ||
{ | ||
// falls back to system setting. | ||
Assert.AreEqual(DateTimeFormatInfo.CurrentInfo.CalendarWeekRule, result); | ||
} | ||
else | ||
{ | ||
Assert.AreEqual(valueExpected, result); | ||
} | ||
} | ||
|
||
[DataTestMethod] | ||
[DataRow(-1, null)] // default setting | ||
[DataRow(1, DayOfWeek.Monday)] | ||
[DataRow(2, DayOfWeek.Tuesday)] | ||
[DataRow(3, DayOfWeek.Wednesday)] | ||
[DataRow(4, DayOfWeek.Thursday)] | ||
[DataRow(5, DayOfWeek.Friday)] | ||
[DataRow(6, DayOfWeek.Saturday)] | ||
[DataRow(0, DayOfWeek.Sunday)] | ||
[DataRow(70, null)] // wrong setting | ||
public void GetFirstDayOfWeekBasedOnPluginSetting(int setting, DayOfWeek? valueExpected) | ||
{ | ||
// Act | ||
var result = TimeAndDateHelper.GetFirstDayOfWeek(setting); | ||
|
||
// Assert | ||
if (valueExpected == null) | ||
{ | ||
// falls back to system setting. | ||
Assert.AreEqual(DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek, result); | ||
} | ||
else | ||
{ | ||
Assert.AreEqual(valueExpected, result); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.