bagetter/BaGetter

Date(Time) of versions is not globalized

Opened this issue · 5 comments

Describe the bug

The detail page for a package does not use a globalized representation as requested by the browser.

To Reproduce

  1. open a detail page
  2. look at the Versions section in the Last Updated column

Expected behavior

A globalized representation as requested by the browser.

Screenshots

hosted as docker container
package_detail_docker

running local
package_detail_local

Additional context

It seems as the docker hosted version does not check the request header.
I added the following code to the Package.cshtml file.

@using System.Globalization;
    
<p>
    <b>CurrentCulture</b>: @System.Globalization.CultureInfo.CurrentCulture   
</p>
<p>
    <b>AcceptLanguage Header</b>: @HttpContext.Request.Headers.AcceptLanguage.ToString();
</p>
<p>
    <b>Last updated (ToShortDateString)</b>: @Model.Versions[0].LastUpdated.ToShortDateString();
</p>

Did you set the wished timezone to the Docker container as environment variable like so

docker run -p 5000:8080 -e TZ=Europe/Berlin bagetter/bagetter

or does this never work in Docker?

I did not know about this feature....
But that also does not fix the issue.
In my tests it never worked, when hosted inside of Docker.

Unfortunately, even with the new Dockerfile it looks like this for me:

CurrentCulture:

AcceptLanguage Header: de,en-GB;q=0.7,en;q=0.3;

Last updated (ToShortDateString): 02/12/2024; 

Putting something like this in the request pipeline works correctly in my small test, but I'm not entirely sure what else is affected by that and also it feels like the framework should already do something like this for us:

    app.Use(async (context, next) =>
    {
        var preferredLanguage = context.Request.Headers["Accept-Language"].ToString().Split(',').FirstOrDefault();
        if (!string.IsNullOrEmpty(preferredLanguage))
        {
            var culture = new System.Globalization.CultureInfo(preferredLanguage);
            System.Globalization.CultureInfo.CurrentCulture = culture;
        }

        await next.Invoke();
    });

This issue is stale because it has been open for 90 days with no activity. Remove the stale label, comment, or this will be closed in 5 days.

This issue was closed because it has been stale for 5 days with no activity.