Browse Source
* Test - On empty PM/AM designator on culture info the time picker should show AM/PM * On empty PM/AM designator on culture info the time picker should show AM/PMpull/13515/merge
committed by
GitHub
5 changed files with 92 additions and 6 deletions
@ -0,0 +1,16 @@ |
|||||
|
using System.Globalization; |
||||
|
|
||||
|
namespace Avalonia.Controls.Utils; |
||||
|
|
||||
|
internal static class TimeUtils |
||||
|
{ |
||||
|
public static string GetPMDesignator() => |
||||
|
!string.IsNullOrEmpty(CultureInfo.CurrentCulture.DateTimeFormat.PMDesignator) ? |
||||
|
CultureInfo.CurrentCulture.DateTimeFormat.PMDesignator : |
||||
|
CultureInfo.InvariantCulture.DateTimeFormat.PMDesignator; |
||||
|
|
||||
|
public static string GetAMDesignator() => |
||||
|
!string.IsNullOrEmpty(CultureInfo.CurrentCulture.DateTimeFormat.AMDesignator) ? |
||||
|
CultureInfo.CurrentCulture.DateTimeFormat.AMDesignator : |
||||
|
CultureInfo.InvariantCulture.DateTimeFormat.AMDesignator; |
||||
|
} |
||||
@ -0,0 +1,37 @@ |
|||||
|
#nullable enable |
||||
|
|
||||
|
using System; |
||||
|
using System.Globalization; |
||||
|
using System.Reflection; |
||||
|
using Xunit.Sdk; |
||||
|
|
||||
|
namespace Avalonia.UnitTests; |
||||
|
|
||||
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)] |
||||
|
public sealed class UseEmptyDesignatorCultureAttribute : BeforeAfterTestAttribute |
||||
|
{ |
||||
|
private CultureInfo? _previousCulture; |
||||
|
private CultureInfo? _previousUICulture; |
||||
|
|
||||
|
private CultureInfo CultureInfo { get; } = |
||||
|
new(string.Empty, false) { DateTimeFormat = { AMDesignator = string.Empty, PMDesignator = string.Empty } }; |
||||
|
|
||||
|
public override void Before(MethodInfo methodUnderTest) |
||||
|
{ |
||||
|
base.Before(methodUnderTest); |
||||
|
|
||||
|
_previousCulture = CultureInfo.CurrentCulture; |
||||
|
_previousUICulture = CultureInfo.CurrentUICulture; |
||||
|
|
||||
|
CultureInfo.CurrentCulture = CultureInfo; |
||||
|
CultureInfo.CurrentUICulture = CultureInfo; |
||||
|
} |
||||
|
|
||||
|
public override void After(MethodInfo methodUnderTest) |
||||
|
{ |
||||
|
CultureInfo.CurrentCulture = _previousCulture!; |
||||
|
CultureInfo.CurrentUICulture = _previousUICulture!; |
||||
|
|
||||
|
base.After(methodUnderTest); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue