Skip to content

Commit

Permalink
fix(DateTime): Fixed an ArgumentOutOfRangeException - Returning 1 Jan…
Browse files Browse the repository at this point in the history
…uary 1970
  • Loading branch information
macmade committed Jan 30, 2024
1 parent 24b6c95 commit fc1f122
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ValueTransformers/Converters/DateTimeToString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,16 @@ public static string ToString( DateTime dt, DateFormatStyle dateStyle, TimeForma

public static DateTime DateTimeFromUnixTimestamp( long ts, DateTimeKind kind = DateTimeKind.Utc )
{
DateTime dt = new DateTime( 1970, 1, 1, 0, 0, 0, 0, kind );
try
{
DateTime dt = new DateTime( 1970, 1, 1, 0, 0, 0, 0, kind );

return dt.AddSeconds( ts ).ToLocalTime();
return dt.AddSeconds( ts ).ToLocalTime();
}
catch( ArgumentOutOfRangeException )
{
return new DateTime( 1970, 1, 1, 0, 0, 0, 0, kind ).ToLocalTime();
}
}

public static string ToString( long ts, DateFormatStyle dateStyle, TimeFormatStyle timeStyle )
Expand Down

0 comments on commit fc1f122

Please sign in to comment.