Unix Timestamp helper

This commit is contained in:
Amy Palamountain
2014-02-16 15:14:13 +13:00
parent 71029212b9
commit 8469a50c11
13 changed files with 39 additions and 18 deletions
@@ -90,7 +90,7 @@ namespace Octokit.Tests.Clients
statisticsClient.GetCodeFrequency("username", "repositoryName");
client.Received().GetQueuedOperation<IEnumerable<int[]>>(expectedEndPoint, Args.CancellationToken);
client.Received().GetQueuedOperation<IEnumerable<long[]>>(expectedEndPoint, Args.CancellationToken);
}
[Fact]
+1 -1
View File
@@ -94,7 +94,7 @@ namespace Octokit
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
var endpoint = "/repos/{0}/{1}/stats/code_frequency".FormatUri(owner, repositoryName);
var rawFrequencies = await ApiConnection.GetQueuedOperation<IEnumerable<int[]>>(endpoint,cancellationToken);
var rawFrequencies = await ApiConnection.GetQueuedOperation<IEnumerable<long[]>>(endpoint,cancellationToken);
return new CodeFrequency(rawFrequencies);
}
@@ -0,0 +1,14 @@
using System;
namespace Octokit.Helpers
{
public static class UnixTimestampExtensions
{
const long _unixEpochTicks = 621355968000000000; // Unix Epoch is January 1, 1970 00:00 -0:00
public static DateTimeOffset FromUnixTime(this long unixTime)
{
return new DateTimeOffset(unixTime * TimeSpan.TicksPerSecond + _unixEpochTicks, TimeSpan.Zero);
}
}
}
+2 -7
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Octokit.Helpers;
namespace Octokit
{
@@ -12,7 +13,6 @@ namespace Octokit
: ISerializable
#endif
{
const long _unixEpochTicks = 621355968000000000; // Unix Epoch is January 1, 1970 00:00 -0:00
public RateLimit(IDictionary<string, string> responseHeaders)
{
@@ -20,7 +20,7 @@ namespace Octokit
Limit = (int) GetHeaderValueAsInt32Safe(responseHeaders, "X-RateLimit-Limit");
Remaining = (int) GetHeaderValueAsInt32Safe(responseHeaders, "X-RateLimit-Remaining");
Reset = FromUnixTime(GetHeaderValueAsInt32Safe(responseHeaders, "X-RateLimit-Reset"));
Reset = GetHeaderValueAsInt32Safe(responseHeaders, "X-RateLimit-Reset").FromUnixTime();
}
/// <summary>
@@ -47,11 +47,6 @@ namespace Octokit
: result;
}
static DateTimeOffset FromUnixTime(long unixTime)
{
return new DateTimeOffset(unixTime*TimeSpan.TicksPerSecond + _unixEpochTicks, TimeSpan.Zero);
}
#if !NETFX_CORE
protected RateLimit(SerializationInfo info, StreamingContext context)
{
@@ -1,23 +1,24 @@
using System;
using System.Collections.Generic;
using Octokit.Helpers;
namespace Octokit
{
public class AdditionsAndDeletions
{
public AdditionsAndDeletions(IList<int> additionsAndDeletions)
public AdditionsAndDeletions(IList<long> additionsAndDeletions)
{
Ensure.ArgumentNotNull(additionsAndDeletions, "additionsAndDeletions");
if (additionsAndDeletions.Count != 3)
{
throw new ArgumentException("Addition and deletion aggregate must only contain three data points.");
}
Timestamp = additionsAndDeletions[0];
Additions = additionsAndDeletions[1];
Deletions = additionsAndDeletions[2];
Timestamp = additionsAndDeletions[0].FromUnixTime();
Additions = Convert.ToInt32(additionsAndDeletions[1]);
Deletions = Convert.ToInt32(additionsAndDeletions[2]);
}
public int Timestamp { get; private set; }
public DateTimeOffset Timestamp { get; private set; }
public int Additions { get; private set; }
+1 -1
View File
@@ -5,7 +5,7 @@ namespace Octokit
{
public class CodeFrequency
{
public CodeFrequency(IEnumerable<IList<int>> rawFrequencies)
public CodeFrequency(IEnumerable<IList<long>> rawFrequencies)
{
Ensure.ArgumentNotNull(rawFrequencies, "rawFrequencies");
AdditionsAndDeletionsByWeek = rawFrequencies.Select(point => new AdditionsAndDeletions(point)).ToList();
@@ -19,7 +19,7 @@ namespace Octokit
/// <summary>
/// The week of commits
/// </summary>
public int Week { get; set; }
public long Week { get; set; }
/// <summary>
/// Get the number of commits made on any <see cref="DayOfWeek"/>
+8 -2
View File
@@ -1,11 +1,12 @@
using System;
using Octokit.Helpers;
namespace Octokit
{
public class WeeklyHash
public class WeeklyHash
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "W")]
public string W { get; set; }
public long W { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "A")]
public int A { get; set; }
@@ -15,5 +16,10 @@ namespace Octokit
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "C")]
public int C { get; set; }
public DateTimeOffset Week
{
get { return W.FromUnixTime(); }
}
}
}
+1
View File
@@ -278,6 +278,7 @@
<Compile Include="Models\Response\AdditionsAndDeletions.cs" />
<Compile Include="Models\Response\CodeFrequency.cs" />
<Compile Include="Models\Response\CommitActivity.cs" />
<Compile Include="Helpers\UnixTimeStampExtensions.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
+1
View File
@@ -288,6 +288,7 @@
<Compile Include="Models\Response\AdditionsAndDeletions.cs" />
<Compile Include="Models\Response\CodeFrequency.cs" />
<Compile Include="Models\Response\CommitActivity.cs" />
<Compile Include="Helpers\UnixTimeStampExtensions.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>
+1
View File
@@ -283,6 +283,7 @@
<Compile Include="Models\Response\AdditionsAndDeletions.cs" />
<Compile Include="Models\Response\CodeFrequency.cs" />
<Compile Include="Models\Response\CommitActivity.cs" />
<Compile Include="Helpers\UnixTimeStampExtensions.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
+1
View File
@@ -276,6 +276,7 @@
<Compile Include="Models\Response\AdditionsAndDeletions.cs" />
<Compile Include="Models\Response\CodeFrequency.cs" />
<Compile Include="Models\Response\CommitActivity.cs" />
<Compile Include="Helpers\UnixTimeStampExtensions.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
+1
View File
@@ -84,6 +84,7 @@
<Compile Include="Clients\WatchedClient.cs" />
<Compile Include="Clients\IFollowersClient.cs" />
<Compile Include="Clients\FollowersClient.cs" />
<Compile Include="Helpers\UnixTimeStampExtensions.cs" />
<Compile Include="Models\Request\BaseSearchRequest.cs" />
<Compile Include="Helpers\EnumExtensions.cs">
<SubType>Code</SubType>