aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Eisele <Ghost_of_Stone@web.de>2026-03-29 12:38:32 +0200
committerGitHub <noreply@github.com>2026-03-29 12:38:32 +0200
commitad9ebe5baa166d26e15cb2472de7914c89fe7108 (patch)
treeafafb9244a24e53daf3e7d943428273188b3d38a
parent6ea77f484d6c1b3faf160aee41d1ea099e64b85e (diff)
More robust date handling in Library DB migration (#16474)
* More robust date handling in Library DB migration * Apply review comment
-rw-r--r--Jellyfin.Server/Migrations/Routines/MigrateLibraryDb.cs24
1 files changed, 23 insertions, 1 deletions
diff --git a/Jellyfin.Server/Migrations/Routines/MigrateLibraryDb.cs b/Jellyfin.Server/Migrations/Routines/MigrateLibraryDb.cs
index c6ac55b6e..de55c00ec 100644
--- a/Jellyfin.Server/Migrations/Routines/MigrateLibraryDb.cs
+++ b/Jellyfin.Server/Migrations/Routines/MigrateLibraryDb.cs
@@ -515,7 +515,7 @@ internal class MigrateLibraryDb : IDatabaseMigrationRoutine
PlayCount = dto.GetInt32(4),
IsFavorite = dto.GetBoolean(5),
PlaybackPositionTicks = dto.GetInt64(6),
- LastPlayedDate = dto.IsDBNull(7) ? null : dto.GetDateTime(7),
+ LastPlayedDate = dto.IsDBNull(7) ? null : ReadDateTimeFromColumn(dto, 7),
AudioStreamIndex = dto.IsDBNull(8) ? null : dto.GetInt32(8),
SubtitleStreamIndex = dto.IsDBNull(9) ? null : dto.GetInt32(9),
Likes = null,
@@ -524,6 +524,28 @@ internal class MigrateLibraryDb : IDatabaseMigrationRoutine
};
}
+ private static DateTime? ReadDateTimeFromColumn(SqliteDataReader reader, int index)
+ {
+ // Try reading as a formatted date string first (handles ISO-8601 dates).
+ if (reader.TryReadDateTime(index, out var dateTimeResult))
+ {
+ return dateTimeResult;
+ }
+
+ // Some databases have Unix epoch timestamps stored as integers.
+ // SqliteDataReader.GetDateTime interprets integers as Julian dates, which crashes
+ // for Unix epoch values. Handle them explicitly.
+ var rawValue = reader.GetValue(index);
+ if (rawValue is long unixTimestamp
+ && unixTimestamp > 0
+ && unixTimestamp <= DateTimeOffset.MaxValue.ToUnixTimeSeconds())
+ {
+ return DateTimeOffset.FromUnixTimeSeconds(unixTimestamp).UtcDateTime;
+ }
+
+ return null;
+ }
+
private AncestorId GetAncestorId(SqliteDataReader reader)
{
return new AncestorId()