Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Fixes DatePicker format #9924

Merged
merged 3 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ internal static string GetDayFormat(string format)
var day = format.Count(x => x == 'd');

if (day == 3)
return "{day dayofweek.abbreviated}";
return "{day.integer} {dayofweek.abbreviated}";
else if (day == 4)
return "{dayofweek.full}";
else
return "{day.integer}";
return $"{{day.integer({day})}}";
}
}

Expand All @@ -112,10 +112,10 @@ internal static string GetMonthFormat(string format)
}
else
{
var month = format.Count(x => x == 'M');
var month = format.Count(x => string.Equals(new string(new char[] { x }), "M", StringComparison.OrdinalIgnoreCase));

if (month <= 2)
return "{month.integer}";
return $"{{month.integer({month})}}";
else if (month == 3)
return "{month.abbreviated}";
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ async protected Task ValidatePropertyInitValue<TValue>(
Assert.Equal(expectedValue, values.PlatformViewValue);
}

async protected Task ValidatePropertyInitValue<TValue>(
IView view,
Func<TValue> GetValue,
Func<THandler, TValue> GetPlatformValue,
TValue expectedValue,
TValue expectedPlatformValue)
{
var values = await GetValueAsync(view, (handler) =>
{
return new
{
ViewValue = GetValue(),
PlatformViewValue = GetPlatformValue(handler)
};
});

Assert.Equal(expectedValue, values.ViewValue);
Assert.Equal(expectedPlatformValue, values.PlatformViewValue);
}

async protected Task ValidatePropertyUpdatesValue<TValue>(
IView view,
string property,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
using System;
using System.Threading.Tasks;
using Microsoft.Maui.Controls;
using Microsoft.Maui.DeviceTests.Stubs;
using Microsoft.UI.Xaml.Controls;
using Xunit;

namespace Microsoft.Maui.DeviceTests
{
public partial class DatePickerHandlerTests
{
[Theory(DisplayName = "Format Initializes Correctly")]
[InlineData("dd/MM/yyyy", "{day.integer(2)}/{month.integer(2)}/{year.full}")]
[InlineData("d/M/yy", "{day.integer}/{month.integer(1)}/{year.abbreviated}")]
[InlineData("ddd/MMM/yyyy", "{day.integer} {dayofweek.abbreviated}/{month.abbreviated}/{year.full}")]
[InlineData("dddd/MMMM/yyyy", "{dayofweek.full}/{month.full}/{year.full}")]
public async Task FormatInitializesCorrectly(string format, string nativeFormat)
{
var datePicker = new DatePickerStub();

datePicker.Date = DateTime.Today;
datePicker.Format = format;

await ValidatePropertyInitValue(datePicker, () => datePicker.Format, GetNativeFormat, format, nativeFormat);
}

CalendarDatePicker GetNativeDatePicker(DatePickerHandler datePickerHandler) =>
datePickerHandler.PlatformView;

string GetNativeFormat(DatePickerHandler datePickerHandler)
{
var plaformDatePicker = GetNativeDatePicker(datePickerHandler);
return plaformDatePicker.DateFormat;
}

DateTime GetNativeDate(DatePickerHandler datePickerHandler)
{
var plaformDatePicker = GetNativeDatePicker(datePickerHandler);
Expand Down