Skip to content

Commit 60b4c24

Browse files
authored
Merge pull request #22025 from ajpinedam/fix/calendarview.incorrect.header.spanish
2 parents b86c307 + c49d6c5 commit 60b4c24

File tree

5 files changed

+146
-12
lines changed

5 files changed

+146
-12
lines changed

src/SamplesApp/UITests.Shared/UITests.Shared.projitems

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,10 @@
15501550
<SubType>Designer</SubType>
15511551
<Generator>MSBuild:Compile</Generator>
15521552
</Page>
1553+
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\CalendarView\CalendarView_Cultures.xaml">
1554+
<SubType>Designer</SubType>
1555+
<Generator>MSBuild:Compile</Generator>
1556+
</Page>
15531557
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\CommandBar\CommandBar_Native_With_AppBarButton_Binding.xaml">
15541558
<SubType>Designer</SubType>
15551559
<Generator>MSBuild:Compile</Generator>
@@ -4346,7 +4350,6 @@
43464350
<SubType>Designer</SubType>
43474351
<Generator>MSBuild:Compile</Generator>
43484352
</Page>
4349-
43504353
<Page Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\WebView2Tests\WebView2_TargetBlank.xaml">
43514354
<SubType>Designer</SubType>
43524355
<Generator>MSBuild:Compile</Generator>
@@ -6496,6 +6499,9 @@
64966499
</Compile>
64976500
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\BorderTests\BorderWithNullBrushAndNonZeroThickness.xaml.cs" />
64986501
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\BorderTests\PanelWithNullBrushAndNonZeroThickness.xaml.cs" />
6502+
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\CalendarView\CalendarView_Cultures.xaml.cs">
6503+
<DependentUpon>CalendarView_Cultures.xaml</DependentUpon>
6504+
</Compile>
64996505
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\CommandBar\CommandBar_Native_With_AppBarButton_Binding.xaml.cs">
65006506
<DependentUpon>CommandBar_Native_With_AppBarButton_Binding.xaml</DependentUpon>
65016507
</Compile>
@@ -10227,4 +10233,4 @@
1022710233
</Compile>
1022810234
</ItemGroup>
1022910235
<Import Project="ItemExclusions.props" />
10230-
</Project>
10236+
</Project>
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<Page
2+
x:Class="UITests.Windows_UI_Xaml_Controls.CalendarView.CalendarView_Cultures"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="using:UITests.Windows_UI_Xaml_Controls.CalendarView"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
9+
mc:Ignorable="d">
10+
11+
<Grid RowSpacing="12">
12+
<Grid.RowDefinitions>
13+
<RowDefinition Height="Auto" />
14+
<RowDefinition Height="Auto" />
15+
<RowDefinition Height="Auto" />
16+
</Grid.RowDefinitions>
17+
<Grid.ColumnDefinitions>
18+
<ColumnDefinition Width="*" />
19+
<ColumnDefinition Width="*" />
20+
<ColumnDefinition Width="*" />
21+
<ColumnDefinition Width="*" />
22+
</Grid.ColumnDefinitions>
23+
<TextBlock Grid.ColumnSpan="4" VerticalAlignment="Top">CalendarView with different Cultures</TextBlock>
24+
<CalendarView Grid.Row="1" HorizontalAlignment="Center" />
25+
<CalendarView
26+
Grid.Row="1"
27+
Grid.Column="1"
28+
HorizontalAlignment="Center"
29+
Language="es-ES" />
30+
<CalendarView
31+
Grid.Row="1"
32+
Grid.Column="2"
33+
HorizontalAlignment="Center"
34+
Language="zh" />
35+
<CalendarView
36+
Grid.Row="1"
37+
Grid.Column="3"
38+
HorizontalAlignment="Center"
39+
Language="ca" />
40+
<TextBlock
41+
Grid.Row="2"
42+
HorizontalAlignment="Center"
43+
VerticalAlignment="Top"
44+
Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}"
45+
Text="Default culture." />
46+
<TextBlock
47+
Grid.Row="2"
48+
Grid.Column="1"
49+
HorizontalAlignment="Center"
50+
VerticalAlignment="Top"
51+
Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}"
52+
Text="Spanish (es-ES) culture." />
53+
<TextBlock
54+
Grid.Row="2"
55+
Grid.Column="2"
56+
HorizontalAlignment="Center"
57+
VerticalAlignment="Top"
58+
Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}"
59+
Text="Chinese (zh) culture." />
60+
<TextBlock
61+
Grid.Row="2"
62+
Grid.Column="3"
63+
HorizontalAlignment="Center"
64+
VerticalAlignment="Top"
65+
Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}"
66+
Text="Catalan (ca) culture." />
67+
</Grid>
68+
</Page>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Microsoft.UI.Xaml.Controls;
2+
using Uno.UI.Samples.Controls;
3+
4+
namespace UITests.Windows_UI_Xaml_Controls.CalendarView;
5+
6+
[Sample("Pickers", IgnoreInSnapshotTests = true, IsManualTest = true, Description = """
7+
Showing CalendarView with different cultures.
8+
""")]
9+
public sealed partial class CalendarView_Cultures : Page
10+
{
11+
public CalendarView_Cultures()
12+
{
13+
this.InitializeComponent();
14+
}
15+
}

src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_CalendarView.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ public async Task SelectedDatesBorder()
201201
MinDate = DateTimeOffset.Now.AddDays(-10),
202202
MaxDate = DateTimeOffset.Now.AddDays(10)
203203
};
204+
204205
Assert.AreEqual(2, calendar.SelectedDates.Count);
205206
Assert.AreEqual(day1, calendar.SelectedDates[0]);
206207
Assert.AreEqual(day2, calendar.SelectedDates[1]);
@@ -303,5 +304,31 @@ public async Task When_NextMonth_InQuickSequence()
303304
$"should never rewind back: (v-offsets: {string.Join(", ", offsets)})"
304305
);
305306
}
307+
308+
[TestMethod]
309+
public async Task When_Spanish_Language()
310+
{
311+
var calendarView = new CalendarView()
312+
{
313+
Language = "es-ES"
314+
};
315+
calendarView.SetDisplayDate(new DateTimeOffset(new DateTime(2024, 1, 1)));
316+
TestServices.WindowHelper.WindowContent = calendarView;
317+
await TestServices.WindowHelper.WaitForLoaded(calendarView);
318+
Assert.AreEqual("enero de 2024", calendarView.TemplateSettings.HeaderText);
319+
}
320+
321+
[TestMethod]
322+
public async Task When_English_Language()
323+
{
324+
var calendarView = new CalendarView()
325+
{
326+
Language = "en-US"
327+
};
328+
calendarView.SetDisplayDate(new DateTimeOffset(new DateTime(2024, 1, 1)));
329+
TestServices.WindowHelper.WindowContent = calendarView;
330+
await TestServices.WindowHelper.WaitForLoaded(calendarView);
331+
Assert.AreEqual("January 2024", calendarView.TemplateSettings.HeaderText);
332+
}
306333
}
307334
#endif

src/Uno.UWP/Globalization/DateTimeFormatting/DateTimeFormatter.cs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -797,27 +797,45 @@ void AddToBuilder(StringBuilder builder, char lastChar, int count)
797797

798798
string ConstructPattern(string str)
799799
{
800+
if (string.IsNullOrEmpty(str))
801+
{
802+
return string.Empty;
803+
}
804+
800805
var builder = new StringBuilder();
801-
char lastChar = str[0];
802-
int count = 1;
803-
for (int i = 1; i < str.Length; i++)
806+
807+
foreach (var part in StringLiteralRegex().Split(str))
804808
{
805-
if (lastChar != str[i])
809+
// skip empty block
810+
if (part.Length == 0)
806811
{
807-
AddToBuilder(builder, lastChar, count);
808-
809-
lastChar = str[i];
810-
count = 1;
812+
continue;
813+
}
814+
// add quoted literal as is, without the quotes
815+
else if (part.StartsWith('\''))
816+
{
817+
if (part.Length > 2)
818+
{
819+
builder.Append(part[1..^1]);
820+
}
811821
}
822+
// for non-quoted parts, further segment them by grouping repeated character(s)
812823
else
813824
{
814-
count++;
825+
foreach (var segment in RepeatedCharactersRegex().EnumerateMatches(part))
826+
{
827+
AddToBuilder(builder, part[segment.Index], segment.Length);
828+
}
815829
}
816830
}
817831

818-
AddToBuilder(builder, lastChar, count);
819832
return builder.ToString();
820833
}
821834
}
822835

836+
[GeneratedRegex(@"('[^']+')")]
837+
private static partial Regex StringLiteralRegex();
838+
839+
[GeneratedRegex(@"(.)(\1+)?")]
840+
private static partial Regex RepeatedCharactersRegex();
823841
}

0 commit comments

Comments
 (0)