Skip to content

Conversation

@Krishanthaudayakumara
Copy link
Owner

@Krishanthaudayakumara Krishanthaudayakumara commented Aug 6, 2025

Description / Motivation

  • Updated DateTagHelper to use CultureInfo.InvariantCulture when DateFormat is specified and no explicit Culture is set, ensuring consistent date output regardless of system locale.
  • Explicitly set culture to en-US in RichTextFieldTagHelperFixture and other relevant integration test fixtures to make test expectations stable and independent of the developer's environment.
  • Updated test assertions to use the correct culture where appropriate.
  • Resolves test failures related to date formatting when running tests under non-US locales (e.g., da-DK).

Issue

encountered date formatting test failures when running the Sitecore ASP.NET Core SDK test suite with non-US locale settings (specifically Danish da-DK). The core issue was that date formatting was culture-dependent, causing tests to fail when the system culture used different date separators (dashes - vs slashes /).

Cause

DateTagHelper Implementation: Used CultureInfo.CurrentCulture for date formatting, making it dependent on system locale
Test Inconsistencies: Some tests expected invariant culture formatting while others expected current culture formatting
Integration Test Configuration: Missing explicit culture configuration in test fixtures, relying on system culture

Solution Implemented

  1. Enhanced DateTagHelper Logic

string formattedDate = !string.IsNullOrWhiteSpace(DateFormat) ? field.Value.ToString(DateFormat, !string.IsNullOrWhiteSpace(Culture) ? culture : CultureInfo.InvariantCulture) : field.Value.ToString(culture);

Behavior

  • When a specific DateFormat is provided (e.g., "MM/dd/yyyy"): Uses CultureInfo.InvariantCulture to ensure consistent formatting - regardless of system culture
  • When a specific Culture is provided: Uses that culture as intended
  • When no format is specified: Uses current culture for proper localization
  1. Integration Test Culture Configuration
app.UseRequestLocalization(options =>
{
    var culture = new CultureInfo("en-US");
    options.DefaultRequestCulture = new RequestCulture(culture);
    options.SupportedCultures = [culture];
    options.SupportedUICultures = [culture];
});

Testing

  • The Unit & Intergration tests are passing.
  • I have added the necessary tests to cover my changes.

Terms

Krishanthaudayakumara and others added 15 commits August 6, 2025 12:01
… test cultures

- Updated DateTagHelper to use CultureInfo.InvariantCulture when DateFormat is specified and no explicit Culture is set, ensuring consistent date output regardless of system locale.
- Explicitly set culture to en-US in RichTextFieldTagHelperFixture and other relevant integration test fixtures to make test expectations stable and independent of the developer's environment.
- Updated test assertions to use the correct culture where appropriate.
- Resolves test failures related to date formatting when running tests under non-US locales (e.g., da-DK).
…gHelperFixture.cs, extracting the culture selection logic into a separate variable for better readability in DateTagHelper.cs
…- Convert DateTagHelper unit tests to use InlineData pattern with multiple cultures
…eFieldTagHelperFixture.cs, extracting the culture selection logic into a separate variable for better readability in DateTagHelper.cs"

This reverts commit 979e588.
…ine Data Approach

To main PR - Update date formatting tests to handle culture-specific formats - Inline Data Approach
Added missing metadata for Pages Assembly

## Description / Motivation
The Pages package wasn't generating with any information, due to the
missing meta data in the csproj

## Testing

- [x] The Unit & Intergration tests are passing.
- [x] I have added the necessary tests to cover my changes.

## Terms
<!-- Place an X in the [] to check. -->

<!-- The Code of Conduct helps create a safe space for everyone. We
require that everyone agrees to it. -->
- [x] I agree to follow this project's [Code of
Conduct](CODE_OF_CONDUCT.md).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants