From 9056851eedd7dc09108682f8600e6b17ca59cebb Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Thu, 14 Nov 2024 11:29:34 +0100 Subject: [PATCH] Revert "Making Culture Invariant When Validating Date to negate deferent formats (#17257)" This reverts commit dabaeac262dd1953f006cebb68d133382942b848. # Conflicts: # src/Umbraco.Core/PropertyEditors/Validators/DateTimeValidator.cs # tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/Validators/DateTimeValidatorTests.cs --- .../Validators/DateTimeValidator.cs | 3 +- .../Validators/DateTimeValidatorTests.cs | 47 ------------------- 2 files changed, 1 insertion(+), 49 deletions(-) delete mode 100644 tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/Validators/DateTimeValidatorTests.cs diff --git a/src/Umbraco.Core/PropertyEditors/Validators/DateTimeValidator.cs b/src/Umbraco.Core/PropertyEditors/Validators/DateTimeValidator.cs index b306efbb10bb..78f6a95d9c25 100644 --- a/src/Umbraco.Core/PropertyEditors/Validators/DateTimeValidator.cs +++ b/src/Umbraco.Core/PropertyEditors/Validators/DateTimeValidator.cs @@ -1,5 +1,4 @@ using System.ComponentModel.DataAnnotations; -using System.Globalization; using Umbraco.Cms.Core.Models.Validation; using Umbraco.Extensions; @@ -26,7 +25,7 @@ public IEnumerable Validate(object? value, string? valueType, yield break; } - if (DateTime.TryParse(value.ToString(), CultureInfo.InvariantCulture, out DateTime dt) == false) + if (DateTime.TryParse(value.ToString(), out DateTime dt) == false) { yield return new ValidationResult( $"The string value {value} cannot be parsed into a DateTime", diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/Validators/DateTimeValidatorTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/Validators/DateTimeValidatorTests.cs deleted file mode 100644 index 49241acda44a..000000000000 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/Validators/DateTimeValidatorTests.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.Globalization; -using NUnit.Framework; -using Umbraco.Cms.Core.Models.Validation; -using Umbraco.Cms.Core.PropertyEditors.Validators; - -namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.PropertyEditors.Validators -{ - /// - /// Unit test fixture for the DateTimeValidator class. - /// - [TestFixture] - public class DateTimeValidatorTests - { - /// - /// Tests that the DateTimeValidator is culture invariant. - /// - /// The culture to set for the current thread. - /// The date format to use for the test. - [TestCase("en-US", "yyyy-MM-dd HH:mm:ss", TestName = "US Thread, DateTimeValidator")] - [TestCase("en-US", "dd-MM-yyyy HH:mm:ss", TestName = "US Thread, DateTimeValidator ar-SA format")] - [TestCase("ar-SA", "dd-MM-yyyy HH:mm:ss", TestName = "Arabian Saudi Thread, DateTimeValidator")] - [TestCase("ar-SA", "yyyy-MM-dd HH:mm:ss", TestName = "Arabian Saudi Thread, DateTimeValidator US format")] - public void DateTimeValidatorIsCultureInvariant(string culture, string format) - { - // Generate a date string using the specified format - var dateString = DateTime.Now.ToString(format); - - // Set the current thread's culture and UI culture - var cultureInfo = new CultureInfo(culture); - Thread.CurrentThread.CurrentCulture = cultureInfo; - Thread.CurrentThread.CurrentUICulture = cultureInfo; - - // Create a new DateTimeValidator instance - var validator = new DateTimeValidator(); - - // Validate the date string - var validationResults = validator.Validate( - dateString, - "DATETIME", - new Dictionary(), - PropertyValidationContext.Empty()); - - // Assert that there are no validation errors - CollectionAssert.IsEmpty(validationResults); - } - } -}