mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-03-29 22:41:54 +01:00
More robust date handling in Library DB migration (#16474)
* More robust date handling in Library DB migration * Apply review comment
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user