Browse Source

Specify DateTimeKind when pulling a DateTime out of the database

Cody Robibero 1 year ago
parent
commit
f2b01f66e8
1 changed files with 7 additions and 0 deletions
  1. 7 0
      Emby.Server.Implementations/Data/SqliteExtensions.cs

+ 7 - 0
Emby.Server.Implementations/Data/SqliteExtensions.cs

@@ -104,6 +104,13 @@ namespace Emby.Server.Implementations.Data
 
             if (DateTime.TryParseExact(dateText, _datetimeFormats, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AdjustToUniversal, out var dateTimeResult))
             {
+                // If the resulting DateTimeKind is Unspecified it is actually Utc.
+                // This is required downstream for the Json serializer.
+                if (dateTimeResult.Kind == DateTimeKind.Unspecified)
+                {
+                    dateTimeResult = DateTime.SpecifyKind(dateTimeResult, DateTimeKind.Utc);
+                }
+
                 result = dateTimeResult;
                 return true;
             }