From abd6902bff7dc2855a2cf1c2bfb7c4eb0ca044f6 Mon Sep 17 00:00:00 2001 From: Marvin E Date: Fri, 28 Jul 2023 20:17:09 +0100 Subject: [PATCH 01/16] Refactor "DayOfWeek" method in "DateTimeExtensions" --- XCalendar.Core/Extensions/DateTimeExtensions.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/XCalendar.Core/Extensions/DateTimeExtensions.cs b/XCalendar.Core/Extensions/DateTimeExtensions.cs index f32ff9a..f449290 100644 --- a/XCalendar.Core/Extensions/DateTimeExtensions.cs +++ b/XCalendar.Core/Extensions/DateTimeExtensions.cs @@ -304,8 +304,9 @@ public static int DayOfWeek(this DateTime self) /// The number representing the position of this instance's day in this instance's week. public static int DayOfWeek(this DateTime self, DayOfWeek startingDayOfWeek) { - List currentWeek = self.DaysOfWeek(startingDayOfWeek); - return currentWeek.IndexOf(self.Date) + 1; + IList weekAsFirst = startingDayOfWeek.GetWeekAsFirst(); + + return weekAsFirst.IndexOf(self.Date.DayOfWeek) + 1; } /// /// Gets which week of this instance's month this instance is in. From d766c0f9f5801856dccf54233364924d101146fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Barrera?= Date: Mon, 4 Sep 2023 13:18:38 +0200 Subject: [PATCH 02/16] add test for DayOfWeekExtensions --- .../Extensions/DayOfWeekExtensionsTests.cs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 XCalendar.Core.Tests/Extensions/DayOfWeekExtensionsTests.cs diff --git a/XCalendar.Core.Tests/Extensions/DayOfWeekExtensionsTests.cs b/XCalendar.Core.Tests/Extensions/DayOfWeekExtensionsTests.cs new file mode 100644 index 0000000..bdd761d --- /dev/null +++ b/XCalendar.Core.Tests/Extensions/DayOfWeekExtensionsTests.cs @@ -0,0 +1,44 @@ +using System; +using Xunit; +using XCalendar.Core.Extensions; +using FluentAssertions; + +namespace XCalendar.Core.Tests.Extensions +{ + public class DayOfWeekExtensionsTests + { + [Theory] + [InlineData(DayOfWeek.Sunday, new[] { DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday })] + [InlineData(DayOfWeek.Monday, new[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday })] + [InlineData(DayOfWeek.Tuesday, new[] { DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday, DayOfWeek.Monday })] + [InlineData(DayOfWeek.Wednesday, new[] { DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday })] + [InlineData(DayOfWeek.Thursday, new[] { DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday })] + [InlineData(DayOfWeek.Friday, new[] { DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday })] + [InlineData(DayOfWeek.Saturday, new[] { DayOfWeek.Saturday, DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday })] + public void GetWeekAsFirst_Should_Return_Correct_Order(DayOfWeek inputDayOfWeek, DayOfWeek[] expectedOrder) + { + // Act + var week = inputDayOfWeek.GetWeekAsFirst(); + + // Assert + week.Should().ContainInOrder(expectedOrder); + } + + [Theory] + [InlineData(DayOfWeek.Sunday, new[] { DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday })] + [InlineData(DayOfWeek.Monday, new[] { DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday })] + [InlineData(DayOfWeek.Tuesday, new[] { DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday, DayOfWeek.Monday })] + [InlineData(DayOfWeek.Wednesday, new[] { DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday })] + [InlineData(DayOfWeek.Thursday, new[] { DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday })] + [InlineData(DayOfWeek.Friday, new[] { DayOfWeek.Saturday, DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday })] + [InlineData(DayOfWeek.Saturday, new[] { DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday })] + public void GetWeekAsLast_Should_Return_Correct_Order(DayOfWeek inputDayOfWeek, DayOfWeek[] expectedOrder) + { + // Act + var week = inputDayOfWeek.GetWeekAsLast(); + + // Assert + week.Should().ContainInOrder(expectedOrder); + } + } +} From ef0f973878077dec3b22084429e06cf8309f2042 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Barrera?= Date: Mon, 4 Sep 2023 13:50:08 +0200 Subject: [PATCH 03/16] add test for DateTimeExtensions --- .../Extensions/DateTimeExtensionsTests.cs | 83 +++++++++++++++++++ .../Extensions/DayOfWeekExtensionsTests.cs | 4 +- 2 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 XCalendar.Core.Tests/Extensions/DateTimeExtensionsTests.cs diff --git a/XCalendar.Core.Tests/Extensions/DateTimeExtensionsTests.cs b/XCalendar.Core.Tests/Extensions/DateTimeExtensionsTests.cs new file mode 100644 index 0000000..521c6d7 --- /dev/null +++ b/XCalendar.Core.Tests/Extensions/DateTimeExtensionsTests.cs @@ -0,0 +1,83 @@ +using System; +using XCalendar.Core.Extensions; +using Xunit; + +namespace XCalendar.Core.Tests.Extensions +{ + public class DateTimeExtensionsTests + { + [Theory] + [InlineData(2023, 9, 15, 2023, 9, 29)] + [InlineData(2024, 1, 7, 2024, 1, 21)] + [InlineData(2022, 12, 25, 2023, 1, 8)] + public void AddWeeksShouldReturnCorrectDate( + int year, int month, int day, + int expectedYear, int expectedMonth, int expectedDay) + { + var date = new DateTime(year, month, day); + + var result = date.AddWeeks(2); + + Assert.Equal(new DateTime(expectedYear, expectedMonth, expectedDay), result); + } + + [Theory] + [InlineData(2023, 9, 15, 2023, 9, 29)] + [InlineData(2024, 1, 7, 2024, 1, 21)] + [InlineData(2022, 12, 25, 2023, 1, 8)] + public void TryAddWeeksShouldReturnTrue( + int year, int month, int day, + int expectedYear, int expectedMonth, int expectedDay) + { + var date = new DateTime(year, month, day); + + var success = date.TryAddWeeks(2, out DateTime result); + + Assert.True(success); + Assert.Equal(new DateTime(expectedYear, expectedMonth, expectedDay), result); + } + + [Theory] + [InlineData(2023, 9, 15, 2023, 9, 10)] + [InlineData(2024, 1, 7, 2024, 1, 7)] + [InlineData(2022, 12, 25, 2022, 12, 25)] + public void FirstDayOfWeekShouldReturnCorrectDate( + int year, int month, int day, + int expectedYear, int expectedMonth, int expectedDay) + { + var date = new DateTime(year, month, day); + + var result = date.FirstDayOfWeek(); + + Assert.Equal(new DateTime(expectedYear, expectedMonth, expectedDay), result); + } + + [Theory] + [InlineData(2023, 9, 15, 2023, 9, 16)] + [InlineData(2024, 1, 7, 2024, 1, 13)] + [InlineData(2022, 12, 25, 2022, 12, 31)] + public void LastDayOfWeekShouldReturnCorrectDate( + int year, int month, int day, + int expectedYear, int expectedMonth, int expectedDay) + { + var date = new DateTime(year, month, day); + + var result = date.LastDayOfWeek(); + + Assert.Equal(new DateTime(expectedYear, expectedMonth, expectedDay), result); + } + + [Theory] + [InlineData(2023, 9, 15, 3)] + [InlineData(2024, 1, 7, 2)] + [InlineData(2022, 12, 25, 5)] + public void CalendarWeekOfMonthShouldReturnCorrectWeek(int year, int month, int day, int expectedWeekOfMonth) + { + var date = new DateTime(year, month, day); + + var result = date.CalendarWeekOfMonth(); + + Assert.Equal(expectedWeekOfMonth, result); + } + } +} diff --git a/XCalendar.Core.Tests/Extensions/DayOfWeekExtensionsTests.cs b/XCalendar.Core.Tests/Extensions/DayOfWeekExtensionsTests.cs index bdd761d..b1ca503 100644 --- a/XCalendar.Core.Tests/Extensions/DayOfWeekExtensionsTests.cs +++ b/XCalendar.Core.Tests/Extensions/DayOfWeekExtensionsTests.cs @@ -15,7 +15,7 @@ public class DayOfWeekExtensionsTests [InlineData(DayOfWeek.Thursday, new[] { DayOfWeek.Thursday, DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday })] [InlineData(DayOfWeek.Friday, new[] { DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday })] [InlineData(DayOfWeek.Saturday, new[] { DayOfWeek.Saturday, DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday })] - public void GetWeekAsFirst_Should_Return_Correct_Order(DayOfWeek inputDayOfWeek, DayOfWeek[] expectedOrder) + public void GetWeekAsFirstShouldReturnCorrectOrder(DayOfWeek inputDayOfWeek, DayOfWeek[] expectedOrder) { // Act var week = inputDayOfWeek.GetWeekAsFirst(); @@ -32,7 +32,7 @@ public void GetWeekAsFirst_Should_Return_Correct_Order(DayOfWeek inputDayOfWeek, [InlineData(DayOfWeek.Thursday, new[] { DayOfWeek.Friday, DayOfWeek.Saturday, DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday })] [InlineData(DayOfWeek.Friday, new[] { DayOfWeek.Saturday, DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday })] [InlineData(DayOfWeek.Saturday, new[] { DayOfWeek.Sunday, DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday })] - public void GetWeekAsLast_Should_Return_Correct_Order(DayOfWeek inputDayOfWeek, DayOfWeek[] expectedOrder) + public void GetWeekAsLastShouldReturnCorrectOrder(DayOfWeek inputDayOfWeek, DayOfWeek[] expectedOrder) { // Act var week = inputDayOfWeek.GetWeekAsLast(); From 13f5b1b33cdeb86e2308c183116580caacaabbd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Barrera?= Date: Tue, 5 Sep 2023 13:31:07 +0200 Subject: [PATCH 04/16] Add support to multi-localization Add ES,EN,PT,IT,FR,DE languages --- .../Models/StringsExtensionsTests.cs | 46 ++++++ .../Extensions/StringsExtensions.cs | 39 +++++ .../LocalizeDayOfWeekAndCharLimitConverter.cs | 39 +++++ .../Converters/StringCharLimitConverter.cs | 43 ------ .../Resources/XCalendarResource.Designer.cs | 126 ++++++++++++++++ .../Resources/XCalendarResource.de.resx | 141 ++++++++++++++++++ .../Resources/XCalendarResource.es.resx | 141 ++++++++++++++++++ .../Resources/XCalendarResource.fr.resx | 141 ++++++++++++++++++ .../Resources/XCalendarResource.it.resx | 141 ++++++++++++++++++ .../Resources/XCalendarResource.pt.resx | 141 ++++++++++++++++++ .../Resources/XCalendarResource.resx | 141 ++++++++++++++++++ XCalendar.Forms/Views/CalendarView.xaml | 4 +- XCalendar.Forms/XCalendar.Forms.csproj | 9 ++ .../LocalizeDayOfWeekAndCharLimitConverter.cs | 37 +++++ .../Converters/StringCharLimitConverter.cs | 42 ------ .../Resources/XCalendarResource.Designer.cs | 126 ++++++++++++++++ .../Resources/XCalendarResource.de.resx | 141 ++++++++++++++++++ .../Resources/XCalendarResource.es.resx | 141 ++++++++++++++++++ .../Resources/XCalendarResource.fr.resx | 141 ++++++++++++++++++ .../Resources/XCalendarResource.it.resx | 141 ++++++++++++++++++ .../Resources/XCalendarResource.pt.resx | 141 ++++++++++++++++++ .../Resources/XCalendarResource.resx | 141 ++++++++++++++++++ XCalendar.Maui/Views/CalendarView.xaml | 6 +- XCalendar.Maui/XCalendar.Maui.csproj | 12 ++ .../Popups/DatePickerDialogPopup.xaml | 4 +- .../DuolingoStreakCalendarExamplePage.xaml | 6 +- .../Popups/DatePickerDialogPopup.xaml | 4 +- .../DuolingoStreakCalendarExamplePage.xaml | 4 +- 28 files changed, 2140 insertions(+), 99 deletions(-) create mode 100644 XCalendar.Core.Tests/Models/StringsExtensionsTests.cs create mode 100644 XCalendar.Core/Extensions/StringsExtensions.cs create mode 100644 XCalendar.Forms/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs delete mode 100644 XCalendar.Forms/Converters/StringCharLimitConverter.cs create mode 100644 XCalendar.Forms/Resources/XCalendarResource.Designer.cs create mode 100644 XCalendar.Forms/Resources/XCalendarResource.de.resx create mode 100644 XCalendar.Forms/Resources/XCalendarResource.es.resx create mode 100644 XCalendar.Forms/Resources/XCalendarResource.fr.resx create mode 100644 XCalendar.Forms/Resources/XCalendarResource.it.resx create mode 100644 XCalendar.Forms/Resources/XCalendarResource.pt.resx create mode 100644 XCalendar.Forms/Resources/XCalendarResource.resx create mode 100644 XCalendar.Maui/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs delete mode 100644 XCalendar.Maui/Converters/StringCharLimitConverter.cs create mode 100644 XCalendar.Maui/Resources/XCalendarResource.Designer.cs create mode 100644 XCalendar.Maui/Resources/XCalendarResource.de.resx create mode 100644 XCalendar.Maui/Resources/XCalendarResource.es.resx create mode 100644 XCalendar.Maui/Resources/XCalendarResource.fr.resx create mode 100644 XCalendar.Maui/Resources/XCalendarResource.it.resx create mode 100644 XCalendar.Maui/Resources/XCalendarResource.pt.resx create mode 100644 XCalendar.Maui/Resources/XCalendarResource.resx diff --git a/XCalendar.Core.Tests/Models/StringsExtensionsTests.cs b/XCalendar.Core.Tests/Models/StringsExtensionsTests.cs new file mode 100644 index 0000000..9e321e2 --- /dev/null +++ b/XCalendar.Core.Tests/Models/StringsExtensionsTests.cs @@ -0,0 +1,46 @@ +using FluentAssertions; +using Xunit; +using XCalendar.Core.Extensions; + +namespace XCalendar.Core.Tests.Models +{ + public class StringsExtensionsTests + { + [Theory] + [InlineData("Hello, World!", 5, "Hello")] + [InlineData("Testing", 7, "Testing")] + [InlineData("12345", 3, "123")] + [InlineData("Short", 10, "Short")] + [InlineData("", 5, "")] + [InlineData(null, 5, "")] + public void TruncateStringToMaxLengthWithValidInputReturnsTruncatedString(string input, int maxLength, string expected) + { + string result = input.TruncateStringToMaxLength(maxLength); + + result.Should().Be(expected); + } + + [Theory] + [InlineData("Hello, World!", 0, "")] + [InlineData("Testing", -1, "")] + [InlineData("12345", 0, "")] + [InlineData("", 0, "")] + public void TruncateStringToMaxLengthWithZeroOrNegativeMaxLengthReturnsEmptyString(string input, int maxLength, string expected) + { + string result = input.TruncateStringToMaxLength(maxLength); + + result.Should().Be(expected); + } + + [Theory] + [InlineData("Hello, World!", "invalid", "")] + [InlineData("12345", true, "")] + [InlineData(null, "5", "")] + public void TruncateStringToMaxLengthWithInvalidParameterReturnsEmptyString(string input, object maxLength, string expected) + { + string result = input.TruncateStringToMaxLength(maxLength); + + result.Should().Be(expected); + } + } +} diff --git a/XCalendar.Core/Extensions/StringsExtensions.cs b/XCalendar.Core/Extensions/StringsExtensions.cs new file mode 100644 index 0000000..9fb2dfc --- /dev/null +++ b/XCalendar.Core/Extensions/StringsExtensions.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace XCalendar.Core.Extensions +{ + public static class StringsExtensions + { + public static string TruncateStringToMaxLength(this string value, object parameter) + { + try + { + string stringValue = value.ToString(); + + if (!int.TryParse(parameter.ToString(), out int maxLength)) + { + return string.Empty; + } + + if (maxLength == 0) + { + return string.Empty; + } + else if (maxLength >= stringValue.Length) + { + return stringValue; + } + else + { + return stringValue.Substring(0, maxLength); + } + } + catch + { + return string.Empty; + } + } + } +} diff --git a/XCalendar.Forms/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs b/XCalendar.Forms/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs new file mode 100644 index 0000000..85f9230 --- /dev/null +++ b/XCalendar.Forms/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs @@ -0,0 +1,39 @@ +using System; +using System.Globalization; +using Xamarin.Forms; +using XCalendar.Core.Extensions; +using XCalendar.Forms.Resources; + +namespace XCalendar.Forms.Converters +{ + public class LocalizeDayOfWeekAndCharLimitConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (!(value is DayOfWeek dayOfWeek)) + { + return string.Empty; + } + + string resourceName = $"{dayOfWeek}"; + + string dayName = XCalendarResource.ResourceManager.GetString(resourceName, culture); + + if (string.IsNullOrWhiteSpace(dayName)) + { + dayName = dayOfWeek.ToString().Substring(0, 3); + } + else + { + dayName = dayName.TruncateStringToMaxLength(parameter); + } + + return dayName; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/XCalendar.Forms/Converters/StringCharLimitConverter.cs b/XCalendar.Forms/Converters/StringCharLimitConverter.cs deleted file mode 100644 index 59dd666..0000000 --- a/XCalendar.Forms/Converters/StringCharLimitConverter.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Globalization; -using Xamarin.Forms; - -namespace XCalendar.Forms.Converters -{ - public class StringCharLimitConverter : IValueConverter - { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - try - { - if (value == null) { - return null; - } - - string stringValue = value.ToString(); - int targetLength = System.Convert.ToInt32(parameter); - - if (targetLength == 0) - { - return ""; - } - else if (targetLength >= stringValue.Length) - { - return stringValue; - } - else - { - return stringValue.Substring(0, targetLength); - } - } - catch - { - return ""; - } - } - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotSupportedException(); - } - } -} diff --git a/XCalendar.Forms/Resources/XCalendarResource.Designer.cs b/XCalendar.Forms/Resources/XCalendarResource.Designer.cs new file mode 100644 index 0000000..3e6e630 --- /dev/null +++ b/XCalendar.Forms/Resources/XCalendarResource.Designer.cs @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace XCalendar.Forms.Resources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class XCalendarResource { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal XCalendarResource() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("XCalendar.Forms.Resources.XCalendarResource", typeof(XCalendarResource).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Friday. + /// + internal static string Friday { + get { + return ResourceManager.GetString("Friday", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Monday. + /// + internal static string Monday { + get { + return ResourceManager.GetString("Monday", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Saturday. + /// + internal static string Saturday { + get { + return ResourceManager.GetString("Saturday", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Sunday. + /// + internal static string Sunday { + get { + return ResourceManager.GetString("Sunday", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Thursday. + /// + internal static string Thursday { + get { + return ResourceManager.GetString("Thursday", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Tuesday. + /// + internal static string Tuesday { + get { + return ResourceManager.GetString("Tuesday", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Wednesday. + /// + internal static string Wednesday { + get { + return ResourceManager.GetString("Wednesday", resourceCulture); + } + } + } +} diff --git a/XCalendar.Forms/Resources/XCalendarResource.de.resx b/XCalendar.Forms/Resources/XCalendarResource.de.resx new file mode 100644 index 0000000..07b25b7 --- /dev/null +++ b/XCalendar.Forms/Resources/XCalendarResource.de.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Freitag + + + Montag + + + Samstag + + + Sonntag + + + Donnerstag + + + Dienstag + + + Mittwoch + + \ No newline at end of file diff --git a/XCalendar.Forms/Resources/XCalendarResource.es.resx b/XCalendar.Forms/Resources/XCalendarResource.es.resx new file mode 100644 index 0000000..1cd441c --- /dev/null +++ b/XCalendar.Forms/Resources/XCalendarResource.es.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Viernes + + + Lunes + + + Sábado + + + Domingo + + + Jueves + + + Martes + + + Miércoles + + \ No newline at end of file diff --git a/XCalendar.Forms/Resources/XCalendarResource.fr.resx b/XCalendar.Forms/Resources/XCalendarResource.fr.resx new file mode 100644 index 0000000..43dccc4 --- /dev/null +++ b/XCalendar.Forms/Resources/XCalendarResource.fr.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Vendredi + + + Lundi + + + Samedi + + + Diamanche + + + Jeudi + + + Mardi + + + Mercredi + + \ No newline at end of file diff --git a/XCalendar.Forms/Resources/XCalendarResource.it.resx b/XCalendar.Forms/Resources/XCalendarResource.it.resx new file mode 100644 index 0000000..857e498 --- /dev/null +++ b/XCalendar.Forms/Resources/XCalendarResource.it.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Venerdì + + + Lunedì + + + Sabato + + + Domenica + + + Giovedì + + + Martedì + + + Mercoledì + + \ No newline at end of file diff --git a/XCalendar.Forms/Resources/XCalendarResource.pt.resx b/XCalendar.Forms/Resources/XCalendarResource.pt.resx new file mode 100644 index 0000000..0c2e1ee --- /dev/null +++ b/XCalendar.Forms/Resources/XCalendarResource.pt.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Sexta-feira + + + Segunda-feira + + + Sábado + + + Domingo + + + Terça-feira + + + Quinta-feira + + + Quarta-feira + + \ No newline at end of file diff --git a/XCalendar.Forms/Resources/XCalendarResource.resx b/XCalendar.Forms/Resources/XCalendarResource.resx new file mode 100644 index 0000000..db68056 --- /dev/null +++ b/XCalendar.Forms/Resources/XCalendarResource.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Friday + + + Monday + + + Saturday + + + Sunday + + + Thursday + + + Tuesday + + + Wednesday + + \ No newline at end of file diff --git a/XCalendar.Forms/Views/CalendarView.xaml b/XCalendar.Forms/Views/CalendarView.xaml index be6e96e..b5848f6 100644 --- a/XCalendar.Forms/Views/CalendarView.xaml +++ b/XCalendar.Forms/Views/CalendarView.xaml @@ -14,7 +14,7 @@ False - + diff --git a/XCalendar.Forms/XCalendar.Forms.csproj b/XCalendar.Forms/XCalendar.Forms.csproj index f9db234..c94cfed 100644 --- a/XCalendar.Forms/XCalendar.Forms.csproj +++ b/XCalendar.Forms/XCalendar.Forms.csproj @@ -27,6 +27,11 @@ + + XCalendarResource.resx + True + True + DayView.xaml @@ -36,6 +41,10 @@ + + XCalendarResource.Designer.cs + ResXFileCodeGenerator + MSBuild:Compile diff --git a/XCalendar.Maui/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs b/XCalendar.Maui/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs new file mode 100644 index 0000000..3931ccb --- /dev/null +++ b/XCalendar.Maui/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs @@ -0,0 +1,37 @@ +using System.Globalization; +using XCalendar.Maui.Resources; +using XCalendar.Core.Extensions; + +namespace XCalendar.Maui.Converters +{ + public class LocalizeDayOfWeekAndCharLimitConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is not DayOfWeek dayOfWeek) + { + return string.Empty; + } + + string resourceName = $"{dayOfWeek}"; + + string dayName = XCalendarResource.ResourceManager.GetString(resourceName, culture); + + if (string.IsNullOrWhiteSpace(dayName)) + { + dayName = dayOfWeek.ToString().Substring(0, 3); + } + else + { + dayName = dayName.TruncateStringToMaxLength(parameter); + } + + return dayName; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/XCalendar.Maui/Converters/StringCharLimitConverter.cs b/XCalendar.Maui/Converters/StringCharLimitConverter.cs deleted file mode 100644 index 1f106d0..0000000 --- a/XCalendar.Maui/Converters/StringCharLimitConverter.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Globalization; - -namespace XCalendar.Maui.Converters -{ - public class StringCharLimitConverter : IValueConverter - { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) - { - try - { - if (value == null) { - return null; - } - - string stringValue = value.ToString(); - int targetLength = System.Convert.ToInt32(parameter); - - if (targetLength == 0) - { - return ""; - } - else if (targetLength >= stringValue.Length) - { - return stringValue; - } - else - { - return stringValue.Substring(0, targetLength); - } - } - catch - { - return ""; - } - } - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) - { - throw new NotSupportedException(); - } - } -} - diff --git a/XCalendar.Maui/Resources/XCalendarResource.Designer.cs b/XCalendar.Maui/Resources/XCalendarResource.Designer.cs new file mode 100644 index 0000000..002e2f8 --- /dev/null +++ b/XCalendar.Maui/Resources/XCalendarResource.Designer.cs @@ -0,0 +1,126 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace XCalendar.Maui.Resources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class XCalendarResource { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal XCalendarResource() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("XCalendar.Maui.Resources.XCalendarResource", typeof(XCalendarResource).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Friday. + /// + internal static string Friday { + get { + return ResourceManager.GetString("Friday", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Monday. + /// + internal static string Monday { + get { + return ResourceManager.GetString("Monday", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Saturday. + /// + internal static string Saturday { + get { + return ResourceManager.GetString("Saturday", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Sunday. + /// + internal static string Sunday { + get { + return ResourceManager.GetString("Sunday", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Thursday. + /// + internal static string Thursday { + get { + return ResourceManager.GetString("Thursday", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Tuesday. + /// + internal static string Tuesday { + get { + return ResourceManager.GetString("Tuesday", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Wednesday. + /// + internal static string Wednesday { + get { + return ResourceManager.GetString("Wednesday", resourceCulture); + } + } + } +} diff --git a/XCalendar.Maui/Resources/XCalendarResource.de.resx b/XCalendar.Maui/Resources/XCalendarResource.de.resx new file mode 100644 index 0000000..07b25b7 --- /dev/null +++ b/XCalendar.Maui/Resources/XCalendarResource.de.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Freitag + + + Montag + + + Samstag + + + Sonntag + + + Donnerstag + + + Dienstag + + + Mittwoch + + \ No newline at end of file diff --git a/XCalendar.Maui/Resources/XCalendarResource.es.resx b/XCalendar.Maui/Resources/XCalendarResource.es.resx new file mode 100644 index 0000000..1cd441c --- /dev/null +++ b/XCalendar.Maui/Resources/XCalendarResource.es.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Viernes + + + Lunes + + + Sábado + + + Domingo + + + Jueves + + + Martes + + + Miércoles + + \ No newline at end of file diff --git a/XCalendar.Maui/Resources/XCalendarResource.fr.resx b/XCalendar.Maui/Resources/XCalendarResource.fr.resx new file mode 100644 index 0000000..43dccc4 --- /dev/null +++ b/XCalendar.Maui/Resources/XCalendarResource.fr.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Vendredi + + + Lundi + + + Samedi + + + Diamanche + + + Jeudi + + + Mardi + + + Mercredi + + \ No newline at end of file diff --git a/XCalendar.Maui/Resources/XCalendarResource.it.resx b/XCalendar.Maui/Resources/XCalendarResource.it.resx new file mode 100644 index 0000000..857e498 --- /dev/null +++ b/XCalendar.Maui/Resources/XCalendarResource.it.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Venerdì + + + Lunedì + + + Sabato + + + Domenica + + + Giovedì + + + Martedì + + + Mercoledì + + \ No newline at end of file diff --git a/XCalendar.Maui/Resources/XCalendarResource.pt.resx b/XCalendar.Maui/Resources/XCalendarResource.pt.resx new file mode 100644 index 0000000..0c2e1ee --- /dev/null +++ b/XCalendar.Maui/Resources/XCalendarResource.pt.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Sexta-feira + + + Segunda-feira + + + Sábado + + + Domingo + + + Terça-feira + + + Quinta-feira + + + Quarta-feira + + \ No newline at end of file diff --git a/XCalendar.Maui/Resources/XCalendarResource.resx b/XCalendar.Maui/Resources/XCalendarResource.resx new file mode 100644 index 0000000..db68056 --- /dev/null +++ b/XCalendar.Maui/Resources/XCalendarResource.resx @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Friday + + + Monday + + + Saturday + + + Sunday + + + Thursday + + + Tuesday + + + Wednesday + + \ No newline at end of file diff --git a/XCalendar.Maui/Views/CalendarView.xaml b/XCalendar.Maui/Views/CalendarView.xaml index ccc7461..0db4c12 100644 --- a/XCalendar.Maui/Views/CalendarView.xaml +++ b/XCalendar.Maui/Views/CalendarView.xaml @@ -15,8 +15,8 @@ False - - + + diff --git a/XCalendar.Maui/XCalendar.Maui.csproj b/XCalendar.Maui/XCalendar.Maui.csproj index 04acc7a..637aedc 100644 --- a/XCalendar.Maui/XCalendar.Maui.csproj +++ b/XCalendar.Maui/XCalendar.Maui.csproj @@ -45,6 +45,11 @@ + + True + True + XCalendarResource.resx + DayView.xaml @@ -53,6 +58,13 @@ + + + ResXFileCodeGenerator + XCalendarResource.Designer.cs + + + MSBuild:Compile diff --git a/XCalendarFormsSample/XCalendarFormsSample/Popups/DatePickerDialogPopup.xaml b/XCalendarFormsSample/XCalendarFormsSample/Popups/DatePickerDialogPopup.xaml index 9f1e8ca..d228ca5 100644 --- a/XCalendarFormsSample/XCalendarFormsSample/Popups/DatePickerDialogPopup.xaml +++ b/XCalendarFormsSample/XCalendarFormsSample/Popups/DatePickerDialogPopup.xaml @@ -17,7 +17,7 @@ - + @@ -84,7 +84,7 @@ - - - ConstructListDialogPopup.xaml - - - DuolingoStreakCalendarExamplePage.xaml - - - DuolingoStreakCalendarExamplePage.xaml - - - EventCalendarExamplePage.xaml - - - CustomDatePickerDialogExamplePage.xaml - - - PlaygroundPage.xaml - - - CustomisingADayExamplePage.xaml - - - CustomisingADayExamplePage.xaml - - - ConnectingSelectedDaysExamplePage.xaml - - - ConnectingSelectedDaysExamplePage.xaml - - - SwipableCalendarExamplePage.xaml - - - UsingDayViewExamplePage.xaml - - - - - - MSBuild:UpdateDesignTimeXaml - - - MSBuild:UpdateDesignTimeXaml - - - MSBuild:UpdateDesignTimeXaml - - - MSBuild:Compile - - - MSBuild:UpdateDesignTimeXaml - - - MSBuild:UpdateDesignTimeXaml - - - MSBuild:UpdateDesignTimeXaml - - - MSBuild:UpdateDesignTimeXaml - - - MSBuild:UpdateDesignTimeXaml - - \ No newline at end of file diff --git a/XCalendarMauiSample/XCalendarMauiSample.csproj b/XCalendarMauiSample/XCalendarMauiSample.csproj index 4e717ad..25dc320 100644 --- a/XCalendarMauiSample/XCalendarMauiSample.csproj +++ b/XCalendarMauiSample/XCalendarMauiSample.csproj @@ -74,97 +74,4 @@ - - - CustomControls\ColorEditor.xaml - - - Popups\ColorDialogPopup.xaml - - - Popups\ConstructListDialogPopup.xaml - - - Popups\DatePickerDialogPopup.xaml - - - Popups\SelectItemDialogPopup.xaml - - - Views\CustomDatePickerDialogExamplePage.xaml - - - Views\EventCalendarExamplePage.xaml - - - Views\ExamplesPage.xaml - - - Views\AppShell.xaml - - - Views\PlaygroundPage.xaml - - - ConnectingSelectedDaysExamplePage.xaml - - - Views\SelectionExamplePage.xamlSelectionExamplePage.xaml - - - %(Filename) - - - UsingDayViewExamplePage.xaml - - - Views\CustomisingADayExamplePage.xaml - - - - - - Designer - - - - Designer - - - - Designer - - - - Designer - - - - Designer - - - - MSBuild:Compile - - - MSBuild:Compile - - - Designer - - - - Designer - - - - Designer - - - - Designer - - - - From 4fc6c7ab5c48f5b1885430de4085a6209a9a2702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Barrera?= Date: Thu, 7 Sep 2023 01:06:35 +0200 Subject: [PATCH 06/16] Refactor StringExtensions : PR Comments --- .../StringsExtensionsTests.cs | 22 +++++++-- .../Extensions/StringsExtensions.cs | 45 +++++++++---------- .../Converters/StringCharLimitConverter.cs | 20 +++++++++ .../Converters/StringCharLimitConverter.cs | 18 ++++++++ 4 files changed, 78 insertions(+), 27 deletions(-) rename XCalendar.Core.Tests/{Models => Extensions}/StringsExtensionsTests.cs (60%) create mode 100644 XCalendar.Forms/Converters/StringCharLimitConverter.cs create mode 100644 XCalendar.Maui/Converters/StringCharLimitConverter.cs diff --git a/XCalendar.Core.Tests/Models/StringsExtensionsTests.cs b/XCalendar.Core.Tests/Extensions/StringsExtensionsTests.cs similarity index 60% rename from XCalendar.Core.Tests/Models/StringsExtensionsTests.cs rename to XCalendar.Core.Tests/Extensions/StringsExtensionsTests.cs index 9e321e2..b873a68 100644 --- a/XCalendar.Core.Tests/Models/StringsExtensionsTests.cs +++ b/XCalendar.Core.Tests/Extensions/StringsExtensionsTests.cs @@ -2,7 +2,7 @@ using Xunit; using XCalendar.Core.Extensions; -namespace XCalendar.Core.Tests.Models +namespace XCalendar.Core.Tests.Extensions { public class StringsExtensionsTests { @@ -13,7 +13,22 @@ public class StringsExtensionsTests [InlineData("Short", 10, "Short")] [InlineData("", 5, "")] [InlineData(null, 5, "")] - public void TruncateStringToMaxLengthWithValidInputReturnsTruncatedString(string input, int maxLength, string expected) + public void TruncateStringToMaxLengthWithValidInputIntReturnsTruncatedString(string input, int maxLength, string expected) + { + string result = input.TruncateStringToMaxLength(maxLength); + + result.Should().Be(expected); + } + + [Theory] + [InlineData("Hello, World!", "5", "Hello")] + [InlineData("Testing", "7", "Testing")] + [InlineData("12345", "3", "123")] + [InlineData("Short", "10", "Short")] + [InlineData("", "5", "")] + [InlineData("Hello, World!", "3", "Hel")] + [InlineData("Hello, World!", "4", "Hell")] + public void TruncateStringToMaxLengthWithValidInputObjectReturnsTruncatedString(string input, object maxLength, string expected) { string result = input.TruncateStringToMaxLength(maxLength); @@ -35,7 +50,8 @@ public void TruncateStringToMaxLengthWithZeroOrNegativeMaxLengthReturnsEmptyStri [Theory] [InlineData("Hello, World!", "invalid", "")] [InlineData("12345", true, "")] - [InlineData(null, "5", "")] + [InlineData(null, "5L", "")] + [InlineData(null, null, "")] public void TruncateStringToMaxLengthWithInvalidParameterReturnsEmptyString(string input, object maxLength, string expected) { string result = input.TruncateStringToMaxLength(maxLength); diff --git a/XCalendar.Core/Extensions/StringsExtensions.cs b/XCalendar.Core/Extensions/StringsExtensions.cs index 9fb2dfc..9b6f7ca 100644 --- a/XCalendar.Core/Extensions/StringsExtensions.cs +++ b/XCalendar.Core/Extensions/StringsExtensions.cs @@ -1,39 +1,36 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace XCalendar.Core.Extensions +namespace XCalendar.Core.Extensions { public static class StringsExtensions { public static string TruncateStringToMaxLength(this string value, object parameter) { - try + if (parameter != null && int.TryParse(parameter.ToString(), out int maxLength)) { - string stringValue = value.ToString(); + return value.TruncateStringToMaxLength(maxLength); + } - if (!int.TryParse(parameter.ToString(), out int maxLength)) - { - return string.Empty; - } + return string.Empty; + } - if (maxLength == 0) - { - return string.Empty; - } - else if (maxLength >= stringValue.Length) - { - return stringValue; - } - else - { - return stringValue.Substring(0, maxLength); - } + public static string TruncateStringToMaxLength(this string value, int maxLength) + { + if (value == null) + { + return string.Empty; } - catch + + if (maxLength <= 0) { return string.Empty; } + else if (maxLength >= value.Length) + { + return value; + } + else + { + return value.Substring(0, maxLength); + } } } } diff --git a/XCalendar.Forms/Converters/StringCharLimitConverter.cs b/XCalendar.Forms/Converters/StringCharLimitConverter.cs new file mode 100644 index 0000000..d8295d9 --- /dev/null +++ b/XCalendar.Forms/Converters/StringCharLimitConverter.cs @@ -0,0 +1,20 @@ +using System; +using System.Globalization; +using Xamarin.Forms; +using XCalendar.Core.Extensions; + +namespace XCalendar.Forms.Converters +{ + public class StringCharLimitConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return value?.ToString().TruncateStringToMaxLength(parameter); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/XCalendar.Maui/Converters/StringCharLimitConverter.cs b/XCalendar.Maui/Converters/StringCharLimitConverter.cs new file mode 100644 index 0000000..70bf26b --- /dev/null +++ b/XCalendar.Maui/Converters/StringCharLimitConverter.cs @@ -0,0 +1,18 @@ +using System.Globalization; +using XCalendar.Core.Extensions; + +namespace XCalendar.Maui.Converters +{ + public class StringCharLimitConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return value?.ToString().TruncateStringToMaxLength(parameter); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} From d13b8d15ae2718a8d74019af64f9b70e8eee2943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Barrera?= Date: Thu, 7 Sep 2023 01:24:34 +0200 Subject: [PATCH 07/16] culture.DateTimeFormat.GetDayName instead resource --- .../LocalizeDayOfWeekAndCharLimitConverter.cs | 16 +- .../Resources/XCalendarResource.Designer.cs | 126 ---------------- .../Resources/XCalendarResource.de.resx | 141 ------------------ .../Resources/XCalendarResource.es.resx | 141 ------------------ .../Resources/XCalendarResource.fr.resx | 141 ------------------ .../Resources/XCalendarResource.it.resx | 141 ------------------ .../Resources/XCalendarResource.pt.resx | 141 ------------------ .../Resources/XCalendarResource.resx | 141 ------------------ XCalendar.Forms/XCalendar.Forms.csproj | 9 -- .../LocalizeDayOfWeekAndCharLimitConverter.cs | 18 +-- .../Resources/XCalendarResource.Designer.cs | 126 ---------------- .../Resources/XCalendarResource.de.resx | 141 ------------------ .../Resources/XCalendarResource.es.resx | 141 ------------------ .../Resources/XCalendarResource.fr.resx | 141 ------------------ .../Resources/XCalendarResource.it.resx | 141 ------------------ .../Resources/XCalendarResource.pt.resx | 141 ------------------ .../Resources/XCalendarResource.resx | 141 ------------------ XCalendar.Maui/XCalendar.Maui.csproj | 12 -- 18 files changed, 5 insertions(+), 1994 deletions(-) delete mode 100644 XCalendar.Forms/Resources/XCalendarResource.Designer.cs delete mode 100644 XCalendar.Forms/Resources/XCalendarResource.de.resx delete mode 100644 XCalendar.Forms/Resources/XCalendarResource.es.resx delete mode 100644 XCalendar.Forms/Resources/XCalendarResource.fr.resx delete mode 100644 XCalendar.Forms/Resources/XCalendarResource.it.resx delete mode 100644 XCalendar.Forms/Resources/XCalendarResource.pt.resx delete mode 100644 XCalendar.Forms/Resources/XCalendarResource.resx delete mode 100644 XCalendar.Maui/Resources/XCalendarResource.Designer.cs delete mode 100644 XCalendar.Maui/Resources/XCalendarResource.de.resx delete mode 100644 XCalendar.Maui/Resources/XCalendarResource.es.resx delete mode 100644 XCalendar.Maui/Resources/XCalendarResource.fr.resx delete mode 100644 XCalendar.Maui/Resources/XCalendarResource.it.resx delete mode 100644 XCalendar.Maui/Resources/XCalendarResource.pt.resx delete mode 100644 XCalendar.Maui/Resources/XCalendarResource.resx diff --git a/XCalendar.Forms/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs b/XCalendar.Forms/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs index 85f9230..e0f59a0 100644 --- a/XCalendar.Forms/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs +++ b/XCalendar.Forms/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs @@ -2,7 +2,6 @@ using System.Globalization; using Xamarin.Forms; using XCalendar.Core.Extensions; -using XCalendar.Forms.Resources; namespace XCalendar.Forms.Converters { @@ -15,20 +14,9 @@ public object Convert(object value, Type targetType, object parameter, CultureIn return string.Empty; } - string resourceName = $"{dayOfWeek}"; + string dayName = culture.DateTimeFormat.GetDayName(dayOfWeek); - string dayName = XCalendarResource.ResourceManager.GetString(resourceName, culture); - - if (string.IsNullOrWhiteSpace(dayName)) - { - dayName = dayOfWeek.ToString().Substring(0, 3); - } - else - { - dayName = dayName.TruncateStringToMaxLength(parameter); - } - - return dayName; + return dayName.TruncateStringToMaxLength(parameter); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/XCalendar.Forms/Resources/XCalendarResource.Designer.cs b/XCalendar.Forms/Resources/XCalendarResource.Designer.cs deleted file mode 100644 index 3e6e630..0000000 --- a/XCalendar.Forms/Resources/XCalendarResource.Designer.cs +++ /dev/null @@ -1,126 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace XCalendar.Forms.Resources { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class XCalendarResource { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal XCalendarResource() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("XCalendar.Forms.Resources.XCalendarResource", typeof(XCalendarResource).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to Friday. - /// - internal static string Friday { - get { - return ResourceManager.GetString("Friday", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Monday. - /// - internal static string Monday { - get { - return ResourceManager.GetString("Monday", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Saturday. - /// - internal static string Saturday { - get { - return ResourceManager.GetString("Saturday", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Sunday. - /// - internal static string Sunday { - get { - return ResourceManager.GetString("Sunday", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Thursday. - /// - internal static string Thursday { - get { - return ResourceManager.GetString("Thursday", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Tuesday. - /// - internal static string Tuesday { - get { - return ResourceManager.GetString("Tuesday", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Wednesday. - /// - internal static string Wednesday { - get { - return ResourceManager.GetString("Wednesday", resourceCulture); - } - } - } -} diff --git a/XCalendar.Forms/Resources/XCalendarResource.de.resx b/XCalendar.Forms/Resources/XCalendarResource.de.resx deleted file mode 100644 index 07b25b7..0000000 --- a/XCalendar.Forms/Resources/XCalendarResource.de.resx +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Freitag - - - Montag - - - Samstag - - - Sonntag - - - Donnerstag - - - Dienstag - - - Mittwoch - - \ No newline at end of file diff --git a/XCalendar.Forms/Resources/XCalendarResource.es.resx b/XCalendar.Forms/Resources/XCalendarResource.es.resx deleted file mode 100644 index 1cd441c..0000000 --- a/XCalendar.Forms/Resources/XCalendarResource.es.resx +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Viernes - - - Lunes - - - Sábado - - - Domingo - - - Jueves - - - Martes - - - Miércoles - - \ No newline at end of file diff --git a/XCalendar.Forms/Resources/XCalendarResource.fr.resx b/XCalendar.Forms/Resources/XCalendarResource.fr.resx deleted file mode 100644 index 43dccc4..0000000 --- a/XCalendar.Forms/Resources/XCalendarResource.fr.resx +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Vendredi - - - Lundi - - - Samedi - - - Diamanche - - - Jeudi - - - Mardi - - - Mercredi - - \ No newline at end of file diff --git a/XCalendar.Forms/Resources/XCalendarResource.it.resx b/XCalendar.Forms/Resources/XCalendarResource.it.resx deleted file mode 100644 index 857e498..0000000 --- a/XCalendar.Forms/Resources/XCalendarResource.it.resx +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Venerdì - - - Lunedì - - - Sabato - - - Domenica - - - Giovedì - - - Martedì - - - Mercoledì - - \ No newline at end of file diff --git a/XCalendar.Forms/Resources/XCalendarResource.pt.resx b/XCalendar.Forms/Resources/XCalendarResource.pt.resx deleted file mode 100644 index 0c2e1ee..0000000 --- a/XCalendar.Forms/Resources/XCalendarResource.pt.resx +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Sexta-feira - - - Segunda-feira - - - Sábado - - - Domingo - - - Terça-feira - - - Quinta-feira - - - Quarta-feira - - \ No newline at end of file diff --git a/XCalendar.Forms/Resources/XCalendarResource.resx b/XCalendar.Forms/Resources/XCalendarResource.resx deleted file mode 100644 index db68056..0000000 --- a/XCalendar.Forms/Resources/XCalendarResource.resx +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Friday - - - Monday - - - Saturday - - - Sunday - - - Thursday - - - Tuesday - - - Wednesday - - \ No newline at end of file diff --git a/XCalendar.Forms/XCalendar.Forms.csproj b/XCalendar.Forms/XCalendar.Forms.csproj index c94cfed..f9db234 100644 --- a/XCalendar.Forms/XCalendar.Forms.csproj +++ b/XCalendar.Forms/XCalendar.Forms.csproj @@ -27,11 +27,6 @@ - - XCalendarResource.resx - True - True - DayView.xaml @@ -41,10 +36,6 @@ - - XCalendarResource.Designer.cs - ResXFileCodeGenerator - MSBuild:Compile diff --git a/XCalendar.Maui/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs b/XCalendar.Maui/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs index 3931ccb..6fbd40a 100644 --- a/XCalendar.Maui/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs +++ b/XCalendar.Maui/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs @@ -1,5 +1,4 @@ using System.Globalization; -using XCalendar.Maui.Resources; using XCalendar.Core.Extensions; namespace XCalendar.Maui.Converters @@ -8,25 +7,14 @@ public class LocalizeDayOfWeekAndCharLimitConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - if (value is not DayOfWeek dayOfWeek) + if (!(value is DayOfWeek dayOfWeek)) { return string.Empty; } - string resourceName = $"{dayOfWeek}"; + string dayName = culture.DateTimeFormat.GetDayName(dayOfWeek); - string dayName = XCalendarResource.ResourceManager.GetString(resourceName, culture); - - if (string.IsNullOrWhiteSpace(dayName)) - { - dayName = dayOfWeek.ToString().Substring(0, 3); - } - else - { - dayName = dayName.TruncateStringToMaxLength(parameter); - } - - return dayName; + return dayName.TruncateStringToMaxLength(parameter); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/XCalendar.Maui/Resources/XCalendarResource.Designer.cs b/XCalendar.Maui/Resources/XCalendarResource.Designer.cs deleted file mode 100644 index 002e2f8..0000000 --- a/XCalendar.Maui/Resources/XCalendarResource.Designer.cs +++ /dev/null @@ -1,126 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace XCalendar.Maui.Resources { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class XCalendarResource { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal XCalendarResource() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("XCalendar.Maui.Resources.XCalendarResource", typeof(XCalendarResource).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to Friday. - /// - internal static string Friday { - get { - return ResourceManager.GetString("Friday", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Monday. - /// - internal static string Monday { - get { - return ResourceManager.GetString("Monday", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Saturday. - /// - internal static string Saturday { - get { - return ResourceManager.GetString("Saturday", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Sunday. - /// - internal static string Sunday { - get { - return ResourceManager.GetString("Sunday", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Thursday. - /// - internal static string Thursday { - get { - return ResourceManager.GetString("Thursday", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Tuesday. - /// - internal static string Tuesday { - get { - return ResourceManager.GetString("Tuesday", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Wednesday. - /// - internal static string Wednesday { - get { - return ResourceManager.GetString("Wednesday", resourceCulture); - } - } - } -} diff --git a/XCalendar.Maui/Resources/XCalendarResource.de.resx b/XCalendar.Maui/Resources/XCalendarResource.de.resx deleted file mode 100644 index 07b25b7..0000000 --- a/XCalendar.Maui/Resources/XCalendarResource.de.resx +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Freitag - - - Montag - - - Samstag - - - Sonntag - - - Donnerstag - - - Dienstag - - - Mittwoch - - \ No newline at end of file diff --git a/XCalendar.Maui/Resources/XCalendarResource.es.resx b/XCalendar.Maui/Resources/XCalendarResource.es.resx deleted file mode 100644 index 1cd441c..0000000 --- a/XCalendar.Maui/Resources/XCalendarResource.es.resx +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Viernes - - - Lunes - - - Sábado - - - Domingo - - - Jueves - - - Martes - - - Miércoles - - \ No newline at end of file diff --git a/XCalendar.Maui/Resources/XCalendarResource.fr.resx b/XCalendar.Maui/Resources/XCalendarResource.fr.resx deleted file mode 100644 index 43dccc4..0000000 --- a/XCalendar.Maui/Resources/XCalendarResource.fr.resx +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Vendredi - - - Lundi - - - Samedi - - - Diamanche - - - Jeudi - - - Mardi - - - Mercredi - - \ No newline at end of file diff --git a/XCalendar.Maui/Resources/XCalendarResource.it.resx b/XCalendar.Maui/Resources/XCalendarResource.it.resx deleted file mode 100644 index 857e498..0000000 --- a/XCalendar.Maui/Resources/XCalendarResource.it.resx +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Venerdì - - - Lunedì - - - Sabato - - - Domenica - - - Giovedì - - - Martedì - - - Mercoledì - - \ No newline at end of file diff --git a/XCalendar.Maui/Resources/XCalendarResource.pt.resx b/XCalendar.Maui/Resources/XCalendarResource.pt.resx deleted file mode 100644 index 0c2e1ee..0000000 --- a/XCalendar.Maui/Resources/XCalendarResource.pt.resx +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Sexta-feira - - - Segunda-feira - - - Sábado - - - Domingo - - - Terça-feira - - - Quinta-feira - - - Quarta-feira - - \ No newline at end of file diff --git a/XCalendar.Maui/Resources/XCalendarResource.resx b/XCalendar.Maui/Resources/XCalendarResource.resx deleted file mode 100644 index db68056..0000000 --- a/XCalendar.Maui/Resources/XCalendarResource.resx +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - Friday - - - Monday - - - Saturday - - - Sunday - - - Thursday - - - Tuesday - - - Wednesday - - \ No newline at end of file diff --git a/XCalendar.Maui/XCalendar.Maui.csproj b/XCalendar.Maui/XCalendar.Maui.csproj index 637aedc..04acc7a 100644 --- a/XCalendar.Maui/XCalendar.Maui.csproj +++ b/XCalendar.Maui/XCalendar.Maui.csproj @@ -45,11 +45,6 @@ - - True - True - XCalendarResource.resx - DayView.xaml @@ -58,13 +53,6 @@ - - - ResXFileCodeGenerator - XCalendarResource.Designer.cs - - - MSBuild:Compile From 76128ff377f1cb7183719fecaa971acbdbb40d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Barrera?= Date: Thu, 7 Sep 2023 10:39:15 +0200 Subject: [PATCH 08/16] unify logic of converters refactor LocalizeDayOfWeekAndCharLimitConverter and StringCharLimitConverter --- .../Extensions/StringsExtensionsTests.cs | 25 +++++++++++++++++++ .../Extensions/DayOfWeekExtensions.cs | 6 +++++ .../Extensions/StringsExtensions.cs | 16 +++++++++++- .../LocalizeDayOfWeekAndCharLimitConverter.cs | 6 ++--- .../Converters/StringCharLimitConverter.cs | 4 ++- .../LocalizeDayOfWeekAndCharLimitConverter.cs | 6 ++--- .../Converters/StringCharLimitConverter.cs | 4 ++- 7 files changed, 58 insertions(+), 9 deletions(-) diff --git a/XCalendar.Core.Tests/Extensions/StringsExtensionsTests.cs b/XCalendar.Core.Tests/Extensions/StringsExtensionsTests.cs index b873a68..00807d5 100644 --- a/XCalendar.Core.Tests/Extensions/StringsExtensionsTests.cs +++ b/XCalendar.Core.Tests/Extensions/StringsExtensionsTests.cs @@ -58,5 +58,30 @@ public void TruncateStringToMaxLengthWithInvalidParameterReturnsEmptyString(stri result.Should().Be(expected); } + + [Theory] + [InlineData("hello", "Hello")] + [InlineData("world", "World")] + [InlineData("t", "T")] + [InlineData("123", "123")] + [InlineData("", "")] + [InlineData(null, "")] + public void UppercaseFirstShouldReturnStringWithFirstLetterUppercased(string input, string expectedOutput) + { + var result = input.UppercaseFirst(); + + result.Should().Be(expectedOutput); + } + + [Theory] + [InlineData("Hello", "Hello")] + [InlineData("WOrld", "WOrld")] + [InlineData("123abc", "123abc")] + public void UppercaseFirstShouldNotChangeStringStartingWithUppercaseLetter(string input, string expectedOutput) + { + var result = input.UppercaseFirst(); + + result.Should().Be(expectedOutput); + } } } diff --git a/XCalendar.Core/Extensions/DayOfWeekExtensions.cs b/XCalendar.Core/Extensions/DayOfWeekExtensions.cs index 5d29b20..c14846a 100644 --- a/XCalendar.Core/Extensions/DayOfWeekExtensions.cs +++ b/XCalendar.Core/Extensions/DayOfWeekExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Globalization; namespace XCalendar.Core.Extensions { @@ -55,6 +56,11 @@ public static List GetWeekAsLast(this DayOfWeek self) return week; } + + public static string LocalizeDayOfWeek(this DayOfWeek self, CultureInfo culture) + { + return culture.DateTimeFormat.GetDayName(self); + } #endregion } } diff --git a/XCalendar.Core/Extensions/StringsExtensions.cs b/XCalendar.Core/Extensions/StringsExtensions.cs index 9b6f7ca..7b80f98 100644 --- a/XCalendar.Core/Extensions/StringsExtensions.cs +++ b/XCalendar.Core/Extensions/StringsExtensions.cs @@ -4,7 +4,11 @@ public static class StringsExtensions { public static string TruncateStringToMaxLength(this string value, object parameter) { - if (parameter != null && int.TryParse(parameter.ToString(), out int maxLength)) + int maxLength = 0; + + bool parameterIsNotNullAndIsAInt = parameter != null && int.TryParse(parameter.ToString(), out maxLength); + + if (parameterIsNotNullAndIsAInt) { return value.TruncateStringToMaxLength(maxLength); } @@ -32,5 +36,15 @@ public static string TruncateStringToMaxLength(this string value, int maxLength) return value.Substring(0, maxLength); } } + + public static string UppercaseFirst(this string text) + { + if (string.IsNullOrEmpty(text)) + { + return string.Empty; + } + + return char.ToUpper(text[0]) + text.Substring(1); + } } } diff --git a/XCalendar.Forms/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs b/XCalendar.Forms/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs index e0f59a0..6aa54fa 100644 --- a/XCalendar.Forms/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs +++ b/XCalendar.Forms/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs @@ -14,9 +14,9 @@ public object Convert(object value, Type targetType, object parameter, CultureIn return string.Empty; } - string dayName = culture.DateTimeFormat.GetDayName(dayOfWeek); - - return dayName.TruncateStringToMaxLength(parameter); + return dayOfWeek.LocalizeDayOfWeek(culture) + .TruncateStringToMaxLength(parameter) + .UppercaseFirst(); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/XCalendar.Forms/Converters/StringCharLimitConverter.cs b/XCalendar.Forms/Converters/StringCharLimitConverter.cs index d8295d9..4716aa8 100644 --- a/XCalendar.Forms/Converters/StringCharLimitConverter.cs +++ b/XCalendar.Forms/Converters/StringCharLimitConverter.cs @@ -9,7 +9,9 @@ public class StringCharLimitConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - return value?.ToString().TruncateStringToMaxLength(parameter); + return value? + .ToString() + .TruncateStringToMaxLength(parameter) ?? string.Empty; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/XCalendar.Maui/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs b/XCalendar.Maui/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs index 6fbd40a..c460b9b 100644 --- a/XCalendar.Maui/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs +++ b/XCalendar.Maui/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs @@ -12,9 +12,9 @@ public object Convert(object value, Type targetType, object parameter, CultureIn return string.Empty; } - string dayName = culture.DateTimeFormat.GetDayName(dayOfWeek); - - return dayName.TruncateStringToMaxLength(parameter); + return dayOfWeek.LocalizeDayOfWeek(culture) + .TruncateStringToMaxLength(parameter) + .UppercaseFirst(); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/XCalendar.Maui/Converters/StringCharLimitConverter.cs b/XCalendar.Maui/Converters/StringCharLimitConverter.cs index 70bf26b..c1426bd 100644 --- a/XCalendar.Maui/Converters/StringCharLimitConverter.cs +++ b/XCalendar.Maui/Converters/StringCharLimitConverter.cs @@ -7,7 +7,9 @@ public class StringCharLimitConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { - return value?.ToString().TruncateStringToMaxLength(parameter); + return value? + .ToString() + .TruncateStringToMaxLength(parameter) ?? string.Empty; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) From ca63c222e877509b0e19ba94d92d50918218fc0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Barrera?= Date: Thu, 7 Sep 2023 23:02:59 +0200 Subject: [PATCH 09/16] pr comments --- .../Extensions/StringsExtensionsTests.cs | 12 ++++++------ XCalendar.Core/Extensions/DayOfWeekExtensions.cs | 2 +- XCalendar.Core/Extensions/StringsExtensions.cs | 8 +++++--- .../LocalizeDayOfWeekAndCharLimitConverter.cs | 4 ++-- .../LocalizeDayOfWeekAndCharLimitConverter.cs | 4 ++-- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/XCalendar.Core.Tests/Extensions/StringsExtensionsTests.cs b/XCalendar.Core.Tests/Extensions/StringsExtensionsTests.cs index 00807d5..9291439 100644 --- a/XCalendar.Core.Tests/Extensions/StringsExtensionsTests.cs +++ b/XCalendar.Core.Tests/Extensions/StringsExtensionsTests.cs @@ -1,6 +1,7 @@ using FluentAssertions; using Xunit; using XCalendar.Core.Extensions; +using System.Globalization; namespace XCalendar.Core.Tests.Extensions { @@ -66,20 +67,19 @@ public void TruncateStringToMaxLengthWithInvalidParameterReturnsEmptyString(stri [InlineData("123", "123")] [InlineData("", "")] [InlineData(null, "")] - public void UppercaseFirstShouldReturnStringWithFirstLetterUppercased(string input, string expectedOutput) + public void ToTitleCaseShouldReturnStringWithFirstLetterUppercased(string input, string expectedOutput) { - var result = input.UppercaseFirst(); + var result = input.ToTitleCase(CultureInfo.CurrentCulture); result.Should().Be(expectedOutput); } [Theory] [InlineData("Hello", "Hello")] - [InlineData("WOrld", "WOrld")] - [InlineData("123abc", "123abc")] - public void UppercaseFirstShouldNotChangeStringStartingWithUppercaseLetter(string input, string expectedOutput) + [InlineData("World", "World")] + public void ToTitleCaseShouldNotChangeStringStartingWithUppercaseLetter(string input, string expectedOutput) { - var result = input.UppercaseFirst(); + var result = input.ToTitleCase(CultureInfo.CurrentCulture); result.Should().Be(expectedOutput); } diff --git a/XCalendar.Core/Extensions/DayOfWeekExtensions.cs b/XCalendar.Core/Extensions/DayOfWeekExtensions.cs index c14846a..b9e0184 100644 --- a/XCalendar.Core/Extensions/DayOfWeekExtensions.cs +++ b/XCalendar.Core/Extensions/DayOfWeekExtensions.cs @@ -57,7 +57,7 @@ public static List GetWeekAsLast(this DayOfWeek self) return week; } - public static string LocalizeDayOfWeek(this DayOfWeek self, CultureInfo culture) + public static string Localize(this DayOfWeek self, CultureInfo culture) { return culture.DateTimeFormat.GetDayName(self); } diff --git a/XCalendar.Core/Extensions/StringsExtensions.cs b/XCalendar.Core/Extensions/StringsExtensions.cs index 7b80f98..62b6ce3 100644 --- a/XCalendar.Core/Extensions/StringsExtensions.cs +++ b/XCalendar.Core/Extensions/StringsExtensions.cs @@ -1,4 +1,6 @@ -namespace XCalendar.Core.Extensions +using System.Globalization; + +namespace XCalendar.Core.Extensions { public static class StringsExtensions { @@ -37,14 +39,14 @@ public static string TruncateStringToMaxLength(this string value, int maxLength) } } - public static string UppercaseFirst(this string text) + public static string ToTitleCase(this string text, CultureInfo culture) { if (string.IsNullOrEmpty(text)) { return string.Empty; } - return char.ToUpper(text[0]) + text.Substring(1); + return culture.TextInfo.ToTitleCase(text); } } } diff --git a/XCalendar.Forms/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs b/XCalendar.Forms/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs index 6aa54fa..75ca53a 100644 --- a/XCalendar.Forms/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs +++ b/XCalendar.Forms/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs @@ -14,9 +14,9 @@ public object Convert(object value, Type targetType, object parameter, CultureIn return string.Empty; } - return dayOfWeek.LocalizeDayOfWeek(culture) + return dayOfWeek.Localize(culture) .TruncateStringToMaxLength(parameter) - .UppercaseFirst(); + .ToTitleCase(culture); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) diff --git a/XCalendar.Maui/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs b/XCalendar.Maui/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs index c460b9b..adad5c0 100644 --- a/XCalendar.Maui/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs +++ b/XCalendar.Maui/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs @@ -12,9 +12,9 @@ public object Convert(object value, Type targetType, object parameter, CultureIn return string.Empty; } - return dayOfWeek.LocalizeDayOfWeek(culture) + return dayOfWeek.Localize(culture) .TruncateStringToMaxLength(parameter) - .UppercaseFirst(); + .ToTitleCase(culture); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) From 534e5b5f6fe4d0e42dbcee6595bc13207ed4b3b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Barrera?= Date: Fri, 8 Sep 2023 00:19:33 +0200 Subject: [PATCH 10/16] refactor test --- .../Extensions/StringsExtensionsTests.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/XCalendar.Core.Tests/Extensions/StringsExtensionsTests.cs b/XCalendar.Core.Tests/Extensions/StringsExtensionsTests.cs index 9291439..7b1ae12 100644 --- a/XCalendar.Core.Tests/Extensions/StringsExtensionsTests.cs +++ b/XCalendar.Core.Tests/Extensions/StringsExtensionsTests.cs @@ -69,7 +69,22 @@ public void TruncateStringToMaxLengthWithInvalidParameterReturnsEmptyString(stri [InlineData(null, "")] public void ToTitleCaseShouldReturnStringWithFirstLetterUppercased(string input, string expectedOutput) { - var result = input.ToTitleCase(CultureInfo.CurrentCulture); + var result = input.ToTitleCase(CultureInfo.InvariantCulture); + + result.Should().Be(expectedOutput); + } + + [Theory] + [InlineData("monday tuesday wednesday thursday friday saturday sunday", "en-US", "Monday Tuesday Wednesday Thursday Friday Saturday Sunday")] + [InlineData("lundi mardi mercredi jeudi vendredi samedi dimanche", "fr-FR", "Lundi Mardi Mercredi Jeudi Vendredi Samedi Dimanche")] + [InlineData("lunes martes miércoles jueves viernes sábado domingo", "es-ES", "Lunes Martes Miércoles Jueves Viernes Sábado Domingo")] + [InlineData("الاثنين الثلاثاء الأربعاء الخميس الجمعة السبت الأحد", "ar-SA", "الاثنين الثلاثاء الأربعاء الخميس الجمعة السبت الأحد")] + [InlineData("星期一 星期二 星期三 星期四 星期五 星期六 星期日", "zh-CN", "星期一 星期二 星期三 星期四 星期五 星期六 星期日")] + public void ToTitleCaseShouldConvertToTitleCaseWithDifferentCultures(string input, string cultureName, string expectedOutput) + { + CultureInfo culture = new CultureInfo(cultureName); + + string result = input.ToTitleCase(culture); result.Should().Be(expectedOutput); } @@ -79,7 +94,7 @@ public void ToTitleCaseShouldReturnStringWithFirstLetterUppercased(string input, [InlineData("World", "World")] public void ToTitleCaseShouldNotChangeStringStartingWithUppercaseLetter(string input, string expectedOutput) { - var result = input.ToTitleCase(CultureInfo.CurrentCulture); + var result = input.ToTitleCase(CultureInfo.InvariantCulture); result.Should().Be(expectedOutput); } From d2e0f6faf5de845f3b37562bc93321ca21e1d972 Mon Sep 17 00:00:00 2001 From: Marvin E Date: Fri, 8 Sep 2023 16:54:59 +0100 Subject: [PATCH 11/16] Fix variable type not matching result of method --- XCalendar.Core/Extensions/DateTimeExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XCalendar.Core/Extensions/DateTimeExtensions.cs b/XCalendar.Core/Extensions/DateTimeExtensions.cs index f449290..508770f 100644 --- a/XCalendar.Core/Extensions/DateTimeExtensions.cs +++ b/XCalendar.Core/Extensions/DateTimeExtensions.cs @@ -304,7 +304,7 @@ public static int DayOfWeek(this DateTime self) /// The number representing the position of this instance's day in this instance's week. public static int DayOfWeek(this DateTime self, DayOfWeek startingDayOfWeek) { - IList weekAsFirst = startingDayOfWeek.GetWeekAsFirst(); + List weekAsFirst = startingDayOfWeek.GetWeekAsFirst(); return weekAsFirst.IndexOf(self.Date.DayOfWeek) + 1; } From e537debe1ed3c0efdf6b8d64c3df498b1da81da2 Mon Sep 17 00:00:00 2001 From: Marvin E Date: Fri, 8 Sep 2023 16:58:17 +0100 Subject: [PATCH 12/16] Change "DateTimeExtensions" to use "CurentCulture" instead of "CurrentUICulture" --- .../Extensions/DateTimeExtensions.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/XCalendar.Core/Extensions/DateTimeExtensions.cs b/XCalendar.Core/Extensions/DateTimeExtensions.cs index 508770f..d210ffa 100644 --- a/XCalendar.Core/Extensions/DateTimeExtensions.cs +++ b/XCalendar.Core/Extensions/DateTimeExtensions.cs @@ -203,7 +203,7 @@ public static bool TryAddYears(this DateTime self, int value, out DateTime resul /// A representing the first day of the week. public static DateTime FirstDayOfWeek(this DateTime self) { - return self.FirstDayOfWeek(CultureInfo.CurrentUICulture.DateTimeFormat.FirstDayOfWeek); + return self.FirstDayOfWeek(CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek); } /// /// Gets the first day of this instance's week using the specified as the week start. @@ -233,7 +233,7 @@ public static DateTime FirstDayOfWeek(this DateTime self, DayOfWeek startingDayO /// A representing the first day of the week. public static DateTime LastDayOfWeek(this DateTime self) { - return self.LastDayOfWeek(CultureInfo.CurrentUICulture.DateTimeFormat.FirstDayOfWeek); + return self.LastDayOfWeek(CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek); } /// /// Gets the last day of this instance's week using the specified as the week start. @@ -295,7 +295,7 @@ public static DateTime LastDayOfYear(this DateTime self) /// The number representing the position of this instance's day in this instance's week. public static int DayOfWeek(this DateTime self) { - return self.DayOfWeek(CultureInfo.CurrentUICulture.DateTimeFormat.FirstDayOfWeek); + return self.DayOfWeek(CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek); } /// /// Gets the position of this instance's day in this instance's week using the specified as the week start. @@ -314,7 +314,7 @@ public static int DayOfWeek(this DateTime self, DayOfWeek startingDayOfWeek) /// The number corresponding to which week of this instance's month it is in public static int CalendarWeekOfMonth(this DateTime self) { - return self.CalendarWeekOfMonth(CultureInfo.CurrentUICulture.DateTimeFormat.FirstDayOfWeek); + return self.CalendarWeekOfMonth(CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek); } /// /// Gets which week of this instance's month this instance is in using the specified as the week start. @@ -380,7 +380,7 @@ public static List CalendarWeekInMonth(this DateTime self, int week, D /// The number of weeks in this instance's month counting the weeks that span into the previous or next year. public static int CalendarWeeksInMonth(this DateTime self) { - return self.CalendarWeeksInMonth(CultureInfo.CurrentUICulture.DateTimeFormat.FirstDayOfWeek); + return self.CalendarWeeksInMonth(CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek); } /// /// Gets the number of weeks in this instance's month counting the weeks that span into the previous or next month using the specified as the week start. @@ -423,7 +423,7 @@ public static List CalendarDaysInMonth(this DateTime self, DayOfWeek s /// The list of days which are before this instance's month and within the same week as its first day. public static List CalendarPreviousDaysInMonth(this DateTime self) { - return self.CalendarPreviousDaysInMonth(CultureInfo.CurrentUICulture.DateTimeFormat.FirstDayOfWeek); + return self.CalendarPreviousDaysInMonth(CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek); } /// /// Gets the days which are before this instance's month and within the same week as its first day using the specified as the week start. @@ -447,7 +447,7 @@ public static List CalendarPreviousDaysInMonth(this DateTime self, Day /// The list of days which are after this instance's month and within the same week as its last day. public static List CalendarNextDaysInMonth(this DateTime self) { - return self.CalendarNextDaysInMonth(CultureInfo.CurrentUICulture.DateTimeFormat.FirstDayOfWeek); + return self.CalendarNextDaysInMonth(CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek); } /// /// Gets the days which are after this instance's month and within the same week as its last day using the specified as the week start. @@ -477,7 +477,7 @@ public static List CalendarNextDaysInMonth(this DateTime self, DayOfWe /// The highest number of weeks that occur inside a month within this instance's year. public static int CalendarHighestMonthWeekCountOfYear(this DateTime self) { - return self.CalendarHighestMonthWeekCountOfYear(CultureInfo.CurrentUICulture.DateTimeFormat.FirstDayOfWeek); + return self.CalendarHighestMonthWeekCountOfYear(CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek); } /// /// Gets the highest number of weeks that occur inside a month within this instance's year using the specified as the week start. @@ -508,7 +508,7 @@ public static int CalendarHighestMonthWeekCountOfYear(this DateTime self, DayOfW /// The lowest number of weeks that occur inside a month within this instance's year. public static int CalendarLowestMonthWeekCountOfYear(this DateTime self) { - return self.CalendarLowestMonthWeekCountOfYear(CultureInfo.CurrentUICulture.DateTimeFormat.FirstDayOfWeek); + return self.CalendarLowestMonthWeekCountOfYear(CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek); } /// /// Gets the lowest number of weeks that occur inside a month within this instance's year using the specified as the week start. @@ -540,7 +540,7 @@ public static int CalendarLowestMonthWeekCountOfYear(this DateTime self, DayOfWe /// The list of dates in this instance's week. public static List DaysOfWeek(this DateTime self, int weekOffset = 0) { - return self.DaysOfWeek(CultureInfo.CurrentUICulture.DateTimeFormat.FirstDayOfWeek, weekOffset); + return self.DaysOfWeek(CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek, weekOffset); } /// /// Gets the dates in this instance's week using the specified as the week start. From 88ad9711b1f3c216902c05c57e06f5171c3ffd2c Mon Sep 17 00:00:00 2001 From: Marvin E Date: Fri, 8 Sep 2023 16:59:01 +0100 Subject: [PATCH 13/16] Change Calendar StartOfWeek default to be obtained from CultureInfo.CurrentCulture instead of CultureInfo.CurrentUICulture --- XCalendar.Core/Models/Calendar.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XCalendar.Core/Models/Calendar.cs b/XCalendar.Core/Models/Calendar.cs index a38fcb0..063afd6 100644 --- a/XCalendar.Core/Models/Calendar.cs +++ b/XCalendar.Core/Models/Calendar.cs @@ -33,7 +33,7 @@ public class Calendar : Calendar private DateTime _todayDate = DateTime.Today; private DateTime _navigationLowerBound = DateTime.MinValue; private DateTime _navigationUpperBound = DateTime.MaxValue; - private DayOfWeek _startOfWeek = CultureInfo.CurrentUICulture.DateTimeFormat.FirstDayOfWeek; + private DayOfWeek _startOfWeek = CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek; private bool _autoRows = true; private bool _autoRowsIsConsistent = true; private SelectionAction _selectionAction = SelectionAction.Modify; From b7a98e7016e3ff461287206738a45aa068028087 Mon Sep 17 00:00:00 2001 From: Marvin E Date: Fri, 8 Sep 2023 17:45:36 +0100 Subject: [PATCH 14/16] Fix DateTimeExtensions tests failing due to culture-specific parameters not being passed --- .../Extensions/DateTimeExtensionsTests.cs | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/XCalendar.Core.Tests/Extensions/DateTimeExtensionsTests.cs b/XCalendar.Core.Tests/Extensions/DateTimeExtensionsTests.cs index 521c6d7..1dbee39 100644 --- a/XCalendar.Core.Tests/Extensions/DateTimeExtensionsTests.cs +++ b/XCalendar.Core.Tests/Extensions/DateTimeExtensionsTests.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using XCalendar.Core.Extensions; using Xunit; @@ -38,44 +39,44 @@ public void TryAddWeeksShouldReturnTrue( } [Theory] - [InlineData(2023, 9, 15, 2023, 9, 10)] - [InlineData(2024, 1, 7, 2024, 1, 7)] - [InlineData(2022, 12, 25, 2022, 12, 25)] + [InlineData(2023, 9, 15, DayOfWeek.Sunday, 2023, 9, 10)] + [InlineData(2024, 1, 7, DayOfWeek.Sunday, 2024, 1, 7)] + [InlineData(2022, 12, 25, DayOfWeek.Sunday, 2022, 12, 25)] public void FirstDayOfWeekShouldReturnCorrectDate( - int year, int month, int day, + int year, int month, int day, DayOfWeek dayOfWeek, int expectedYear, int expectedMonth, int expectedDay) { var date = new DateTime(year, month, day); - var result = date.FirstDayOfWeek(); + var result = date.FirstDayOfWeek(dayOfWeek); Assert.Equal(new DateTime(expectedYear, expectedMonth, expectedDay), result); } [Theory] - [InlineData(2023, 9, 15, 2023, 9, 16)] - [InlineData(2024, 1, 7, 2024, 1, 13)] - [InlineData(2022, 12, 25, 2022, 12, 31)] + [InlineData(2023, 9, 15, DayOfWeek.Sunday, 2023, 9, 16)] + [InlineData(2024, 1, 7, DayOfWeek.Sunday, 2024, 1, 13)] + [InlineData(2022, 12, 25, DayOfWeek.Sunday, 2022, 12, 31)] public void LastDayOfWeekShouldReturnCorrectDate( - int year, int month, int day, + int year, int month, int day, DayOfWeek dayOfWeek, int expectedYear, int expectedMonth, int expectedDay) { var date = new DateTime(year, month, day); - var result = date.LastDayOfWeek(); + var result = date.LastDayOfWeek(dayOfWeek); Assert.Equal(new DateTime(expectedYear, expectedMonth, expectedDay), result); } [Theory] - [InlineData(2023, 9, 15, 3)] - [InlineData(2024, 1, 7, 2)] - [InlineData(2022, 12, 25, 5)] - public void CalendarWeekOfMonthShouldReturnCorrectWeek(int year, int month, int day, int expectedWeekOfMonth) + [InlineData(2023, 9, 15, DayOfWeek.Sunday, 3)] + [InlineData(2024, 1, 7, DayOfWeek.Sunday, 2)] + [InlineData(2022, 12, 25, DayOfWeek.Sunday, 5)] + public void CalendarWeekOfMonthShouldReturnCorrectWeek(int year, int month, int day, DayOfWeek dayOfWeek, int expectedWeekOfMonth) { var date = new DateTime(year, month, day); - var result = date.CalendarWeekOfMonth(); + var result = date.CalendarWeekOfMonth(dayOfWeek); Assert.Equal(expectedWeekOfMonth, result); } From f909fb710eccefeedb8d3f92c54842faedaf21da Mon Sep 17 00:00:00 2001 From: Marvin E Date: Fri, 8 Sep 2023 18:09:26 +0100 Subject: [PATCH 15/16] Remove method "Localize" from DateTimeExtensions --- XCalendar.Core/Extensions/DayOfWeekExtensions.cs | 5 ----- .../Converters/LocalizeDayOfWeekAndCharLimitConverter.cs | 3 ++- .../Converters/LocalizeDayOfWeekAndCharLimitConverter.cs | 3 ++- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/XCalendar.Core/Extensions/DayOfWeekExtensions.cs b/XCalendar.Core/Extensions/DayOfWeekExtensions.cs index b9e0184..b7e9e4b 100644 --- a/XCalendar.Core/Extensions/DayOfWeekExtensions.cs +++ b/XCalendar.Core/Extensions/DayOfWeekExtensions.cs @@ -56,11 +56,6 @@ public static List GetWeekAsLast(this DayOfWeek self) return week; } - - public static string Localize(this DayOfWeek self, CultureInfo culture) - { - return culture.DateTimeFormat.GetDayName(self); - } #endregion } } diff --git a/XCalendar.Forms/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs b/XCalendar.Forms/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs index 75ca53a..81e2783 100644 --- a/XCalendar.Forms/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs +++ b/XCalendar.Forms/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs @@ -14,7 +14,8 @@ public object Convert(object value, Type targetType, object parameter, CultureIn return string.Empty; } - return dayOfWeek.Localize(culture) + return culture.DateTimeFormat + .GetDayName(dayOfWeek) .TruncateStringToMaxLength(parameter) .ToTitleCase(culture); } diff --git a/XCalendar.Maui/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs b/XCalendar.Maui/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs index adad5c0..5944da4 100644 --- a/XCalendar.Maui/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs +++ b/XCalendar.Maui/Converters/LocalizeDayOfWeekAndCharLimitConverter.cs @@ -12,7 +12,8 @@ public object Convert(object value, Type targetType, object parameter, CultureIn return string.Empty; } - return dayOfWeek.Localize(culture) + return culture.DateTimeFormat + .GetDayName(dayOfWeek) .TruncateStringToMaxLength(parameter) .ToTitleCase(culture); } From 95f50a8fcaa000e30ee4af138899ce2c8d663da3 Mon Sep 17 00:00:00 2001 From: Marvin E Date: Fri, 8 Sep 2023 18:23:46 +0100 Subject: [PATCH 16/16] Update nuget package info for 4.5.2 --- XCalendar.Core/XCalendar.Core.csproj | 2 +- XCalendar.Forms/XCalendar.Forms.csproj | 2 +- XCalendar.Maui/XCalendar.Maui.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/XCalendar.Core/XCalendar.Core.csproj b/XCalendar.Core/XCalendar.Core.csproj index fbba6a3..45efdb8 100644 --- a/XCalendar.Core/XCalendar.Core.csproj +++ b/XCalendar.Core/XCalendar.Core.csproj @@ -2,7 +2,7 @@ netstandard2.0 - 4.5.0 + 4.5.2 MarvinE A plugin providing a calendar API and DateTime extensions for working with a calendar. XCalendar.Core Nuget Icon.png diff --git a/XCalendar.Forms/XCalendar.Forms.csproj b/XCalendar.Forms/XCalendar.Forms.csproj index f9db234..441dabe 100644 --- a/XCalendar.Forms/XCalendar.Forms.csproj +++ b/XCalendar.Forms/XCalendar.Forms.csproj @@ -6,7 +6,7 @@ A plugin for Xamarin Forms providing a calendar API and calendar controls. $(AssemblyName) False - 4.5.1 + 4.5.2 https://github.com/ME-MarvinE/XCalendar csharp; dotnet; cross-platform; calendar; calendar-component; plugin; xamarin; xamarinforms; xamarin-forms; True diff --git a/XCalendar.Maui/XCalendar.Maui.csproj b/XCalendar.Maui/XCalendar.Maui.csproj index 04acc7a..0fee2a1 100644 --- a/XCalendar.Maui/XCalendar.Maui.csproj +++ b/XCalendar.Maui/XCalendar.Maui.csproj @@ -16,7 +16,7 @@ 10.0.17763.0 6.5 MarvinE - 4.5.1 + 4.5.2 A plugin for .NET MAUI providing a calendar API and calendar controls. XCalendar.Maui Nuget Icon.png https://github.com/ME-MarvinE/XCalendar