-
Notifications
You must be signed in to change notification settings - Fork 445
Fixing date parsing for VSTS repos #838
Conversation
src/GitHub.Api/Helpers/SimpleJson.cs
Outdated
@@ -1369,9 +1369,9 @@ public virtual object DeserializeObject(object value, Type type) | |||
if (type == typeof(NPath) || (ReflectionUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type) == typeof(NPath))) | |||
return new NPath(str); | |||
if (type == typeof(DateTime) || (ReflectionUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type) == typeof(DateTime))) | |||
return DateTime.ParseExact(str, Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); | |||
return DateTime.ParseExact(str, Constants.Iso8601Formats, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather have Iso8601Format
point to Constants instead of hardcoding that here, it's easier to maintain that way I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/GitHub.Api/Helpers/Constants.cs
Outdated
public static readonly string[] Iso8601Formats = { | ||
Iso8601FormatZ, | ||
@"yyyy-MM-dd\THH\:mm\:ss.fffffffzzz", | ||
Iso8601Format, | ||
Iso8601FormatPointZ, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Iso8601Format
and Iso8601FormatZ
are the preferred ones, which is why I made them into consts, but we'll need way more. This list probably needs to read more like
public static readonly string[] Iso8601Formats = {
Iso8601Format,
Iso8601FormatZ,
@"yyyy-MM-dd\THH\:mm\:ss.fffffffzzz",
@"yyyy-MM-dd\THH\:mm\:ss.ffffffzzz",
@"yyyy-MM-dd\THH\:mm\:ss.fffffzzz",
@"yyyy-MM-dd\THH\:mm\:ss.ffffzzz",
@"yyyy-MM-dd\THH\:mm\:ss.ffzzz",
@"yyyy-MM-dd\THH\:mm\:ss.fzzz",
@"yyyy-MM-dd\THH\:mm\:sszzz",
@"yyyy-MM-dd\THH\:mm\:ss.fffffff\Z",
@"yyyy-MM-dd\THH\:mm\:ss.ffffff\Z",
@"yyyy-MM-dd\THH\:mm\:ss.fffff\Z",
@"yyyy-MM-dd\THH\:mm\:ss.ffff\Z",
@"yyyy-MM-dd\THH\:mm\:ss.fff\Z",
@"yyyy-MM-dd\THH\:mm\:ss.ff\Z",
@"yyyy-MM-dd\THH\:mm\:ss.f\Z",
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Fixes #835
Update by @shana:
This adds more milisecond precision variants to the ISO8601 formats, given that different servers return different variations of the standard. Because standards.