Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Serializing DateTimeOffset objects with ISO8601
Browse files Browse the repository at this point in the history
Failure to do so will lead to inconsistent results, especially with
users that have a custom system-wide date time string.
  • Loading branch information
StanleyGoldman committed Nov 20, 2017
1 parent 85e8d7c commit 60a90b2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/GitHub.Api/Helpers/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ static class Constants
public const string UsageFile = "usage.json";
public const string GitInstallPathKey = "GitInstallPath";
public const string TraceLoggingKey = "EnableTraceLogging";
public const string Iso8601Format = "o";

public static readonly Version MinimumGitVersion = new Version(2, 11, 0);
public static readonly Version MinimumGitLfsVersion = new Version(2, 3, 4);
Expand Down
4 changes: 2 additions & 2 deletions src/GitHub.Api/OutputProcessors/LogEntryOutputProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ private void ReturnGitLogEntry()
Summary = summary,
Description = description,
CommitID = commitId,
TimeString = time.Value.ToString(DateTimeFormatInfo.CurrentInfo),
CommitTimeString = committerTime.Value.ToString(DateTimeFormatInfo.CurrentInfo)
TimeString = time.Value.ToString(Constants.Iso8601Format),
CommitTimeString = committerTime.Value.ToString(Constants.Iso8601Format)
});
}

Expand Down
27 changes: 21 additions & 6 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationCache.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Octokit;
using UnityEditor;
using UnityEngine;
using Application = UnityEngine.Application;
Expand Down Expand Up @@ -92,7 +92,6 @@ abstract class ManagedCacheBase<T> : ScriptObjectSingleton<T> where T : Scriptab
private static readonly TimeSpan DataTimeout = TimeSpan.MaxValue;

[NonSerialized] private DateTimeOffset? lastUpdatedAtValue;

[NonSerialized] private DateTimeOffset? lastVerifiedAtValue;

public event Action CacheInvalidated;
Expand Down Expand Up @@ -148,14 +147,22 @@ public DateTimeOffset LastUpdatedAt
{
if (!lastUpdatedAtValue.HasValue)
{
lastUpdatedAtValue = DateTimeOffset.Parse(LastUpdatedAtString);
DateTimeOffset result;
if (DateTimeOffset.TryParseExact(LastUpdatedAtString, Constants.Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.None, out result))
{
lastUpdatedAtValue = result;
}
else
{
lastUpdatedAtValue = DateTimeOffset.MinValue;
}
}

return lastUpdatedAtValue.Value;
}
set
{
LastUpdatedAtString = value.ToString();
LastUpdatedAtString = value.ToString(Constants.Iso8601Format);
lastUpdatedAtValue = null;
}
}
Expand All @@ -166,14 +173,22 @@ public DateTimeOffset LastVerifiedAt
{
if (!lastVerifiedAtValue.HasValue)
{
lastVerifiedAtValue = DateTimeOffset.Parse(LastVerifiedAtString);
DateTimeOffset result;
if (DateTimeOffset.TryParseExact(LastVerifiedAtString, Constants.Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.None, out result))
{
lastVerifiedAtValue = result;
}
else
{
lastVerifiedAtValue = DateTimeOffset.MinValue;
}
}

return lastVerifiedAtValue.Value;
}
set
{
LastVerifiedAtString = value.ToString();
LastVerifiedAtString = value.ToString(Constants.Iso8601Format);
lastVerifiedAtValue = null;
}
}
Expand Down

0 comments on commit 60a90b2

Please sign in to comment.