Skip to content

Commit

Permalink
Merge pull request #857 from ChrisMissal/issue841
Browse files Browse the repository at this point in the history
Add multiple dates to DateRange filter
  • Loading branch information
shiftkey committed Aug 1, 2015
2 parents a7bc09e + 43b6f1b commit 1776ca1
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
51 changes: 51 additions & 0 deletions Octokit.Tests/Clients/SearchClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,19 @@ public void TestingTheCreatedQualifier_LessThan()
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+created:<2014-01-01"));
}

[Fact]
public void TestingTheCreatedQualifier_Between()
{
var connection = Substitute.For<IApiConnection>();
var client = new SearchClient(connection);
var request = new SearchUsersRequest("github");
request.Created = DateRange.Between(new DateTime(2014, 1, 1), new DateTime(2014, 2, 1));
client.SearchUsers(request);
connection.Received().Get<SearchUsersResult>(
Arg.Is<Uri>(u => u.ToString() == "search/users"),
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+created:2014-01-01..2014-02-01"));
}

[Fact]
public void TestingTheFollowersQualifier_GreaterThan()
{
Expand Down Expand Up @@ -546,6 +559,17 @@ public void TestingTheCreatedQualifier_LessThanOrEquals()
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+created:<=2011-01-01"));
}

[Fact]
public void TestingTheCreatedQualifier_Between()
{
var connection = Substitute.For<IApiConnection>();
var client = new SearchClient(connection);
var request = new SearchRepositoriesRequest("github");
request.Created = DateRange.Between(new DateTime(2011, 1, 1), new DateTime(2012, 11, 11));
client.SearchRepo(request);
connection.Received().Get<SearchRepositoryResult>(Arg.Is<Uri>(u => u.ToString() == "search/repositories"),
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+created:2011-01-01..2012-11-11"));
}

[Fact]
public void TestingTheUpdatedQualifier()
Expand Down Expand Up @@ -599,6 +623,18 @@ public void TestingTheUpdatedQualifier_LessThanOrEquals()
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+pushed:<=2013-01-01"));
}

[Fact]
public void TestingTheUpdatedQualifier_Between()
{
var connection = Substitute.For<IApiConnection>();
var client = new SearchClient(connection);
var request = new SearchRepositoriesRequest("github");
request.Updated = DateRange.Between(new DateTime(2012, 4, 30), new DateTime(2012, 7, 4));
client.SearchRepo(request);
connection.Received().Get<SearchRepositoryResult>(Arg.Is<Uri>(u => u.ToString() == "search/repositories"),
Arg.Is<Dictionary<string, string>>(d => d["q"] == "github+pushed:2012-04-30..2012-07-04"));
}

[Fact]
public void TestingTheUserQualifier()
{
Expand Down Expand Up @@ -995,6 +1031,21 @@ public void TestingTheCreatedQualifier_LessThanOrEquals()
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+created:<=2014-01-01"));
}

[Fact]
public void TestingTheCreatedQualifier_Between()
{
var connection = Substitute.For<IApiConnection>();
var client = new SearchClient(connection);
var request = new SearchIssuesRequest("something");
request.Created = DateRange.Between(new DateTime(2014, 1, 1), new DateTime(2014, 2, 2));

client.SearchIssues(request);

connection.Received().Get<SearchIssuesResult>(
Arg.Is<Uri>(u => u.ToString() == "search/issues"),
Arg.Is<Dictionary<string, string>>(d => d["q"] == "something+created:2014-01-01..2014-02-02"));
}

[Fact]
public void TestingTheUpdatedQualifier_GreaterThan()
{
Expand Down
22 changes: 22 additions & 0 deletions Octokit/Models/Request/SearchRepositoriesRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,16 @@ public DateRange(DateTime date, SearchQualifierOperator op)
}
}

/// <summary>
/// Matches repositories with regards to both the <param name="from"/> and <param name="to"/> dates.
/// </summary>
/// <param name="from">earlier date of the two</param>
/// <param name="to">latter date of the two</param>
public DateRange(DateTime from, DateTime to)
{
query = string.Format(CultureInfo.InvariantCulture, "{0:yyyy-MM-dd}..{1:yyyy-MM-dd}", from, to);
}

internal string DebuggerDisplay
{
get { return String.Format(CultureInfo.InvariantCulture, "Query: {0}", query); }
Expand Down Expand Up @@ -350,6 +360,18 @@ public static DateRange GreaterThanOrEquals(DateTime date)
return new DateRange(date, SearchQualifierOperator.GreaterThanOrEqualTo);
}

/// <summary>
/// helper method to create a bounded Date Comparison
/// e.g. 2015-08-01..2015-10-31
/// </summary>
/// <param name="from">earlier date of the two</param>
/// <param name="to">latter date of the two</param>
/// <returns><see cref="DateRange"/></returns>
public static DateRange Between(DateTime from, DateTime to)
{
return new DateRange(from, to);
}

public override string ToString()
{
return query;
Expand Down

0 comments on commit 1776ca1

Please sign in to comment.