Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timestamps in Reports 1 hour behind #35

Open
lockheed opened this issue Nov 29, 2020 · 8 comments
Open

Timestamps in Reports 1 hour behind #35

lockheed opened this issue Nov 29, 2020 · 8 comments
Labels
feature This PR or Issue requests or introduces a new feature

Comments

@lockheed
Copy link

Jellyfin has the correct time and timezone (linked to /etc/localtime). Also, timestamps in Dashboard/Activity section are correct.
However, in Reports plugin, the times are:
a - 1 hour behind
b - in AM/PM format, even though system as well as Jellyfin are set for 24h format

Jellyfin 10.6.4 run as docker container.
Reports version 10.0.0.0

@oddstr13
Copy link
Member

oddstr13 commented Dec 5, 2020

I'm assuming you're in UTC+1 (CET), and that the plugin is displaying UTC

@lockheed
Copy link
Author

lockheed commented Dec 6, 2020

That's correct. But all other plugins display CET.

@oddstr13
Copy link
Member

oddstr13 commented Dec 6, 2020

All other plugins is false jellyfin/jellyfin-plugin-playbackreporting#24, but could you point to a plugin that actually does show the expected time?

@oddstr13 oddstr13 added the feature This PR or Issue requests or introduces a new feature label Dec 6, 2020
@lockheed
Copy link
Author

lockheed commented Dec 6, 2020

Playback Reporting (I think that's built-in).
"Activity" and anything else displaying timestamps in the dashboard.
(I realised these are not plugins)
Those display timestamps correctly, plus they display it in European style, not AM/PM.

Both web client and server are in the same timezone UTC+1 (CET).

@AlfredJKwack
Copy link

Looking through the codebase, which I'll freely admit I'm not too familiar with, it looks like ReportHelper.cs#L16-L33 are where this might be going wrong.

        public static string? ConvertToString<T>(T value, ReportFieldType fieldType)
        {
            if (value == null)
            {
                return string.Empty;
            }


            return fieldType switch
            {
                ReportFieldType.Boolean | ReportFieldType.Int | ReportFieldType.String => value.ToString(),
                ReportFieldType.Date => string.Format(CultureInfo.InvariantCulture, "{0:d}", value),
                ReportFieldType.Time => string.Format(CultureInfo.InvariantCulture, "{0:t}", value),
                ReportFieldType.DateTime => string.Format(CultureInfo.InvariantCulture, "{0:g}", value),
                ReportFieldType.Minutes => string.Format(CultureInfo.InvariantCulture, "{0}mn", value),
                _ when value is Guid guid => guid.ToString("N", CultureInfo.InvariantCulture),
                _ => value.ToString()
            };
        }

Using the CultureInfo.InvariantCulture calls brings whatever you have into UTC I believe.

There's several ways resolving this could be approached. Perhaps someone could pitch in here to see what would best suit this codebase. Unfortunately I don't have an environment where I could build and test out solutions hence my input will limit itself to suggesting approaches as opposed to providing a suitable patch.

Instead of using the InvariantCulture why not rely on the CultureInfo provided by the environment? Is it not suitable here? Another thing to consider is the serialization and desirialization of the dates where timezones get involved. Is TimeZoneInfo.Local set correctly in the environment?

There's a decent article in the Ms Docs that covers this providing handy examples.

Roughly here's a rundown that could get us on the right path:

      // Parse the date.
      DateTime parsedDate = DateTime.ParseExact(dateValue, "o",
                            DateTimeFormatInfo.InvariantInfo);
      // Convert it to local time.
      DateTime restoredDate = parsedDate.ToLocalTime();
      // Display information on the date and time.
      Console.WriteLine("Deserialized date: {0:F}", restoredDate);
      Console.WriteLine("Current Culture:   {0}",
                        CultureInfo.CurrentCulture.Name);
      Console.WriteLine("Time Zone:         {0}",
                        TimeZoneInfo.Local.DisplayName);

      // The above could display the following output:
      //    Deserialized date: lundi 18 août 2014 17:16:35
      //   Current Culture:   fr-FR
      //    Time Zone:         (UTC+01:00) Brussels, Copenhagen, Madrid, Paris

Hope this helps.

@brunoherrera
Copy link

mine displays in 24 hour format but is 3 hours ahead

@TheHYPO35
Copy link

My reports are also in UTC. Just to confirm - has there been no update to the plugin to either have a timezone setting or to import the Jellyfin time zone setting?

@piotrek2555
Copy link

piotrek2555 commented Sep 13, 2023

2 hours back

time zone me: UTC +2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This PR or Issue requests or introduces a new feature
Projects
None yet
Development

No branches or pull requests

6 participants