Skip to content

Commit 152f762

Browse files
committed
Update StringExtensions.cs
Using correct max timestamp
1 parent 7ff66e0 commit 152f762

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

RestSharp/Extensions/StringExtensions.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ public static string RemoveUnderscoresAndDashes(this string input)
122122
/// <returns>DateTime</returns>
123123
public static DateTime ParseJsonDate(this string input, CultureInfo culture)
124124
{
125+
const long maxAllowedTimestamp = 253402300799;
126+
125127
input = input.Replace("\n", "");
126128
input = input.Replace("\r", "");
127129
input = input.RemoveSurroundingQuotes();
@@ -132,10 +134,10 @@ public static DateTime ParseJsonDate(this string input, CultureInfo culture)
132134
{
133135
DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
134136

135-
if (unix > DateTime.MaxValue.Second)
136-
return epoch.AddMilliseconds(unix);
137-
else
138-
return epoch.AddSeconds(unix);
137+
if (unix > maxAllowedTimestamp)
138+
return epoch.AddMilliseconds(unix);
139+
else
140+
return epoch.AddSeconds(unix);
139141
}
140142

141143
if (input.Contains("/Date("))

0 commit comments

Comments
 (0)