question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Changing the date / time format reflect to the CurrentCulture all the time

See original GitHub issue

Background and Motivation

Changing the culture date/time format reflect to the default culture, there’s no way in the current APIs to allow the user doesn’t rely on the system settings

Proposed API

+ private readonly bool _useUserOverride;
+
    private RequestCulture _defaultRequestCulture =
        new RequestCulture(CultureInfo.CurrentCulture, CultureInfo.CurrentUICulture);

- public RequestLocalizationOptions()
+ public RequestLocalizationOptions() : this(useUserOverride: true)
{
-    RequestCultureProviders = new List<IRequestCultureProvider>
-    {
-        new QueryStringRequestCultureProvider { Options = this },
-        new CookieRequestCultureProvider { Options = this },
-        new AcceptLanguageHeaderRequestCultureProvider { Options = this }
-    };
}

+ public RequestLocalizationOptions(bool useUserOverride)
+{
+    _useUserOverride = useUserOverride;
+    RequestCultureProviders = new List<IRequestCultureProvider>
+    {
+        new QueryStringRequestCultureProvider { Options = this },
+        new CookieRequestCultureProvider { Options = this },
+        new AcceptLanguageHeaderRequestCultureProvider { Options = this }
+    };

Usage Examples

var options = new RequestLocalizationOptions(useUserOverride: true);

app.UseRequestLocalization(options);

Alternative Designs

Risks

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
halter73commented, Oct 20, 2022

You need to update PublicAPI.Unshipped.txt instead of PublicAPI.Shipped.txt. We generally only update the PublicAPI.Shipped.txt files once a year after we’ve shipped new APIs as part of a major release. You can read more about these files in our API Baselines doc.

As suggested in that doc, you can apply the RS0016 code fix in VS to update PublicAPI.Unshipped.txt automatically. If it doesn’t work out for you, just try making the actual code change and we can update PublicAPI.Unshipped.txt for you.

1reaction
halter73commented, Oct 19, 2022

@hishamco It wasn’t just me that decided on CultureInfoUseUserOverride. Members of @dotnet/aspnet-api-review had a vote and approved it. We discussed your UseSystemCultureSettings and UseUserOverrideCulture naming suggestions, but we still prefer CultureInfoUseUserOverride. If you want us to merge your PR, it must match the approved API.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - How to change "CurrentThread.CurrentCulture. ...
1. Or you can use DateTime. · 1. You'd probably have to change your current culture, not just your date time format settings,...
Read more >
CultureInfo.CurrentCulture Property (System.Globalization)
The CultureInfo object that this property returns is read-only. That means you can't mutate the existing object, for example, by changing the DateTimeFormat...
Read more >
Standard date and time format strings
Learn how to use a standard date and time format string to define the text representation of a date and time value in...
Read more >
c# Datetime Examples - Franco Morales
Current culture is ES – the default format for it, it's : “dd/MM/yyyy”. When we try to convert “24/12/2020 23:50” to this culture,...
Read more >
CurrentCulture - 2000 Things You Should Know About WPF
Current culture impacts the display of the following: Numeric data; Date/time values; Currency values. All of these values are typically ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found