mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
## Summary of the Pull Request This PR implements two new plugin settings: - **First week of year**  - **First day of week**  ## 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
66 lines
2.2 KiB
C#
66 lines
2.2 KiB
C#
// 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);
|
|
}
|
|
}
|
|
}
|
|
}
|