jellyfin / jellyfin-plugin-reports

Reports Plugin for Jellyfin
https://jellyfin.org
MIT License
30 stars 19 forks source link

Timestamps in Reports 1 hour behind #35

Open lockheed opened 3 years ago

lockheed commented 3 years ago

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 commented 3 years ago

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

lockheed commented 3 years ago

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

oddstr13 commented 3 years ago

All other plugins is false https://github.com/jellyfin/jellyfin-plugin-playbackreporting/issues/24, but could you point to a plugin that actually does show the expected time?

lockheed commented 3 years ago

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 commented 2 years ago

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 commented 1 year ago

mine displays in 24 hour format but is 3 hours ahead

TheHYPO35 commented 1 year ago

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 commented 12 months ago

2 hours back

time zone me: UTC +2