Skip to content

Commit fab41ec

Browse files
committed
Resolve #543 by sending back junk data to disco era
1 parent bc8d220 commit fab41ec

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/IronyModManager.IO/Mods/Models/Paradox/PropertyHandlers/LongToDateTimeHandler.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Created : 11-16-2021
55
//
66
// Last Modified By : Mario
7-
// Last Modified On : 11-04-2022
7+
// Last Modified On : 03-28-2025
88
// ***********************************************************************
99
// <copyright file="LongToDateTimeHandler.cs" company="Mario">
1010
// Mario
@@ -15,6 +15,8 @@
1515
using System;
1616
using System.Collections.Generic;
1717
using System.Linq;
18+
using IronyModManager.DI;
19+
using IronyModManager.Shared;
1820
using RepoDb.Interfaces;
1921
using RepoDb.Options;
2022

@@ -37,7 +39,18 @@ internal class LongToDateTimeHandler : IPropertyHandler<long, DateTime>
3739
/// <returns>DateTime.</returns>
3840
public DateTime Get(long input, PropertyHandlerGetOptions options)
3941
{
40-
return DateTimeOffset.FromUnixTimeMilliseconds(input).DateTime;
42+
try
43+
{
44+
return DateTimeOffset.FromUnixTimeMilliseconds(input).DateTime;
45+
}
46+
catch (Exception e)
47+
{
48+
var logger = DIResolver.Get<ILogger>();
49+
logger.Error(new ArgumentOutOfRangeException($"Invalid timestamp {input} detected, logging for posterity. Defaulting to disco era value.", e));
50+
51+
// If junk data, send it back to the disco era (1970)
52+
return new DateTime(1970, 1, 1); // Unix epoch date
53+
}
4154
}
4255

4356
/// <summary>

0 commit comments

Comments
 (0)