From 8aa493a06dbc55d759b5b090796a7793a6e2c939 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Mon, 1 Jan 2018 17:17:42 +0200 Subject: [PATCH 1/7] added support for DateTime serialized as FileTime --- Octokit/SimpleJson.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Octokit/SimpleJson.cs b/Octokit/SimpleJson.cs index 40dca76cd2..9efbf7e912 100644 --- a/Octokit/SimpleJson.cs +++ b/Octokit/SimpleJson.cs @@ -1429,6 +1429,14 @@ public virtual object DeserializeObject(object value, Type type) return value; if ((valueIsDouble && type != typeof(double)) || (valueIsLong && type != typeof(long))) { + if (valueIsLong && (type == typeof(DateTimeOffset) || type == typeof(DateTimeOffset?))) + { + return DateTimeOffset.FromFileTime((long)value); + } + else if (valueIsLong && (type == typeof(DateTime) || type == typeof(DateTime?))) + { + return DateTime.FromFileTime((long)value); + } obj = type == typeof(int) || type == typeof(long) || type == typeof(double) || type == typeof(float) || type == typeof(bool) || type == typeof(decimal) || type == typeof(byte) || type == typeof(short) ? Convert.ChangeType(value, type, CultureInfo.InvariantCulture) : value; From 107c11f032133a68c65b7b49eb38805c1121b1b9 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Tue, 9 Jan 2018 11:05:40 +0200 Subject: [PATCH 2/7] changed non-iso timestamp deserialization from FromFileTime to FromUnixTime. --- Octokit/SimpleJson.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Octokit/SimpleJson.cs b/Octokit/SimpleJson.cs index 9efbf7e912..016e9aab4c 100644 --- a/Octokit/SimpleJson.cs +++ b/Octokit/SimpleJson.cs @@ -66,6 +66,7 @@ using Octokit.Reflection; #if !SIMPLE_JSON_NO_LINQ_EXPRESSION using System.Linq.Expressions; +using Octokit.Helpers; #endif #if SIMPLE_JSON_DYNAMIC using System.Dynamic; @@ -1431,11 +1432,11 @@ public virtual object DeserializeObject(object value, Type type) { if (valueIsLong && (type == typeof(DateTimeOffset) || type == typeof(DateTimeOffset?))) { - return DateTimeOffset.FromFileTime((long)value); + return ((long)value).FromUnixTime(); } else if (valueIsLong && (type == typeof(DateTime) || type == typeof(DateTime?))) { - return DateTime.FromFileTime((long)value); + return ((long)value).FromUnixTime().DateTime; } obj = type == typeof(int) || type == typeof(long) || type == typeof(double) || type == typeof(float) || type == typeof(bool) || type == typeof(decimal) || type == typeof(byte) || type == typeof(short) ? Convert.ChangeType(value, type, CultureInfo.InvariantCulture) From 511b521a5c7643eaa2c9893a1a4d9133e06c2477 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Tue, 9 Jan 2018 11:06:33 +0200 Subject: [PATCH 3/7] updated a test to also test the new time stamp deserializer. --- Octokit.Tests/SimpleJsonSerializerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Octokit.Tests/SimpleJsonSerializerTests.cs b/Octokit.Tests/SimpleJsonSerializerTests.cs index 228dc08225..0c183f3aec 100644 --- a/Octokit.Tests/SimpleJsonSerializerTests.cs +++ b/Octokit.Tests/SimpleJsonSerializerTests.cs @@ -253,7 +253,7 @@ public void CanDeserializeOrganization() "\"followers\": 0," + "\"following\": 0," + "\"created_at\": \"2009-02-10T17:53:17Z\"," + - "\"updated_at\": \"2014-07-07T00:12:56Z\"" + + "\"updated_at\": 1404691976" + "}"; var result = new SimpleJsonSerializer().Deserialize(json); From 9a0c9d0ddbb5eb1cc08d5c968620682665b4e0c5 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Tue, 9 Jan 2018 11:07:00 +0200 Subject: [PATCH 4/7] moved all tests projects to a solution folder of their own. --- Octokit.sln | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Octokit.sln b/Octokit.sln index 03f8c744d5..cd54847945 100644 --- a/Octokit.sln +++ b/Octokit.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26228.4 +VisualStudioVersion = 15.0.27130.2010 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Octokit", "Octokit\Octokit.csproj", "{104E8324-C2B9-43BE-8040-36B736A64D45}" EndProject @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Octokit.Tests.Conventions", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Octokit.Tests.Integration", "Octokit.Tests.Integration\Octokit.Tests.Integration.csproj", "{EF19E577-D810-4357-BF95-9029A359CB4E}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{64FD6CD6-3714-4A7B-AF5A-B8E7DFEEC807}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -43,4 +45,12 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {E58EC0EA-B6E5-43AA-A7D2-AD0A6D4BB0D2} = {64FD6CD6-3714-4A7B-AF5A-B8E7DFEEC807} + {A04124DC-D057-4DB0-8E5F-ECD114FA371A} = {64FD6CD6-3714-4A7B-AF5A-B8E7DFEEC807} + {EF19E577-D810-4357-BF95-9029A359CB4E} = {64FD6CD6-3714-4A7B-AF5A-B8E7DFEEC807} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3ABF5A09-BE91-46DF-93C1-BE3932581DF5} + EndGlobalSection EndGlobal From 12f01beff0c6ccfa52f9a5db29a5ef787c68b7e2 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Thu, 11 Jan 2018 14:12:37 +0200 Subject: [PATCH 5/7] Fixed test and added a missing field to Account. --- Octokit.Tests/SimpleJsonSerializerTests.cs | 5 ++++- Octokit/Models/Response/Account.cs | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Octokit.Tests/SimpleJsonSerializerTests.cs b/Octokit.Tests/SimpleJsonSerializerTests.cs index 0c183f3aec..c7da0923cb 100644 --- a/Octokit.Tests/SimpleJsonSerializerTests.cs +++ b/Octokit.Tests/SimpleJsonSerializerTests.cs @@ -1,5 +1,6 @@ using Octokit.Helpers; using Octokit.Internal; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -253,13 +254,15 @@ public void CanDeserializeOrganization() "\"followers\": 0," + "\"following\": 0," + "\"created_at\": \"2009-02-10T17:53:17Z\"," + - "\"updated_at\": 1404691976" + + "\"updated_at\": 1234288397" + "}"; var result = new SimpleJsonSerializer().Deserialize(json); Assert.Equal("Mono Project", result.Name); Assert.Null(result.Hireable); + Assert.Equal(new DateTimeOffset(2009, 02, 10, 17, 53, 17, TimeSpan.Zero), result.CreatedAt); + Assert.Equal(new DateTimeOffset(2009, 02, 10, 17, 53, 17, TimeSpan.Zero), result.UpdatedAt); } [Fact] diff --git a/Octokit/Models/Response/Account.cs b/Octokit/Models/Response/Account.cs index 9538411933..586ff03341 100644 --- a/Octokit/Models/Response/Account.cs +++ b/Octokit/Models/Response/Account.cs @@ -67,6 +67,11 @@ protected Account(string avatarUrl, string bio, string blog, int collaborators, /// public DateTimeOffset CreatedAt { get; protected set; } + /// + /// Date the account was updated. + /// + public DateTimeOffset UpdatedAt { get; protected set; } + /// /// Amount of disk space the account is using. /// From 7a5b9920789fb583cea9f1db6e79d1dfe7dcb68a Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Thu, 11 Jan 2018 14:18:21 +0200 Subject: [PATCH 6/7] Use original values in test. --- Octokit.Tests/SimpleJsonSerializerTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Octokit.Tests/SimpleJsonSerializerTests.cs b/Octokit.Tests/SimpleJsonSerializerTests.cs index c7da0923cb..7194cd352e 100644 --- a/Octokit.Tests/SimpleJsonSerializerTests.cs +++ b/Octokit.Tests/SimpleJsonSerializerTests.cs @@ -254,7 +254,7 @@ public void CanDeserializeOrganization() "\"followers\": 0," + "\"following\": 0," + "\"created_at\": \"2009-02-10T17:53:17Z\"," + - "\"updated_at\": 1234288397" + + "\"updated_at\": 1404691976" + "}"; var result = new SimpleJsonSerializer().Deserialize(json); @@ -262,7 +262,7 @@ public void CanDeserializeOrganization() Assert.Equal("Mono Project", result.Name); Assert.Null(result.Hireable); Assert.Equal(new DateTimeOffset(2009, 02, 10, 17, 53, 17, TimeSpan.Zero), result.CreatedAt); - Assert.Equal(new DateTimeOffset(2009, 02, 10, 17, 53, 17, TimeSpan.Zero), result.UpdatedAt); + Assert.Equal(new DateTimeOffset(2014, 07, 07, 00, 12, 56, TimeSpan.Zero), result.UpdatedAt); } [Fact] From ab73bc6423ab9fcf5c637b8e8aee5ea81dda8933 Mon Sep 17 00:00:00 2001 From: Itai Bar-Haim Date: Thu, 11 Jan 2018 16:01:37 +0200 Subject: [PATCH 7/7] Moved UpdatedAt from Account to User. --- Octokit/Models/Response/Account.cs | 5 ----- Octokit/Models/Response/User.cs | 8 +++++++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Octokit/Models/Response/Account.cs b/Octokit/Models/Response/Account.cs index 586ff03341..9538411933 100644 --- a/Octokit/Models/Response/Account.cs +++ b/Octokit/Models/Response/Account.cs @@ -67,11 +67,6 @@ protected Account(string avatarUrl, string bio, string blog, int collaborators, /// public DateTimeOffset CreatedAt { get; protected set; } - /// - /// Date the account was updated. - /// - public DateTimeOffset UpdatedAt { get; protected set; } - /// /// Amount of disk space the account is using. /// diff --git a/Octokit/Models/Response/User.cs b/Octokit/Models/Response/User.cs index 2cd22753ed..423fb27f66 100644 --- a/Octokit/Models/Response/User.cs +++ b/Octokit/Models/Response/User.cs @@ -13,13 +13,14 @@ public class User : Account { public User() { } - public User(string avatarUrl, string bio, string blog, int collaborators, string company, DateTimeOffset createdAt, int diskUsage, string email, int followers, int following, bool? hireable, string htmlUrl, int totalPrivateRepos, int id, string location, string login, string name, int ownedPrivateRepos, Plan plan, int privateGists, int publicGists, int publicRepos, string url, RepositoryPermissions permissions, bool siteAdmin, string ldapDistinguishedName, DateTimeOffset? suspendedAt) + public User(string avatarUrl, string bio, string blog, int collaborators, string company, DateTimeOffset createdAt, DateTimeOffset updatedAt, int diskUsage, string email, int followers, int following, bool? hireable, string htmlUrl, int totalPrivateRepos, int id, string location, string login, string name, int ownedPrivateRepos, Plan plan, int privateGists, int publicGists, int publicRepos, string url, RepositoryPermissions permissions, bool siteAdmin, string ldapDistinguishedName, DateTimeOffset? suspendedAt) : base(avatarUrl, bio, blog, collaborators, company, createdAt, diskUsage, email, followers, following, hireable, htmlUrl, totalPrivateRepos, id, location, login, name, ownedPrivateRepos, plan, privateGists, publicGists, publicRepos, AccountType.User, url) { Permissions = permissions; SiteAdmin = siteAdmin; LdapDistinguishedName = ldapDistinguishedName; SuspendedAt = suspendedAt; + UpdatedAt = updatedAt; } public RepositoryPermissions Permissions { get; protected set; } @@ -45,6 +46,11 @@ public User(string avatarUrl, string bio, string blog, int collaborators, string [Parameter(Key = "ldap_dn")] public string LdapDistinguishedName { get; protected set; } + /// + /// Date the user account was updated. + /// + public DateTimeOffset UpdatedAt { get; protected set; } + internal string DebuggerDisplay { get