-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DateRange does not include time #1904 #1905
Changes from 1 commit
2b06cc9
86a2d5f
2bc9ba6
65435b9
17e94a8
a02f466
0051e9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -304,33 +304,43 @@ public class DateRange | |
/// Matches repositories with regards to the <param name="date"/>. | ||
/// We will use the <param name="op"/> to see what operator will be applied to the date qualifier | ||
/// </summary> | ||
public DateRange(DateTime date, SearchQualifierOperator op) | ||
[Obsolete("This ctor has been deprecated as GitHub API now supports date and time")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth pointing out the preferred API and why you'd use it? Something like
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @khellang good pickup. Just made both changes and checked-in. |
||
public DateRange(DateTime date, SearchQualifierOperator op) : this(new DateTimeOffset(date), op) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By forwarding these ctors to the new I think the safest thing to do is to keep the existing logic (as @ryangribble noted in #1904) for these ctors and use the new (and improved) format for the new |
||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Matches repositories with regards to both the <param name="from"/> and <param name="to"/> dates. | ||
/// </summary> | ||
[Obsolete("This ctor has been deprecated as GitHub API now supports date and time")] | ||
public DateRange(DateTime from, DateTime to) : this(new DateTimeOffset(from), new DateTimeOffset(to)) | ||
{ | ||
} | ||
|
||
public DateRange(DateTimeOffset from, DateTimeOffset to) | ||
{ | ||
query = string.Format(CultureInfo.InvariantCulture, "{0:yyyy-MM-dd'T'HH:mm:ss zzz}..{1:yyyy-MM-dd'T'HH:mm:ss zzz}", from.DateTime, to.DateTime); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What will the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @khellang the However, you're right these changes affect the behaviour. I'll update and re-submit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But what is that offset? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi sorry you are right @khellang. I was trying to do to code this while also doing my job which was a mistake. I'll fix in my next PR. |
||
} | ||
|
||
public DateRange(DateTimeOffset date, SearchQualifierOperator op) | ||
{ | ||
switch (op) | ||
{ | ||
case SearchQualifierOperator.GreaterThan: | ||
query = string.Format(CultureInfo.InvariantCulture, ">{0:yyyy-MM-dd}", date); | ||
query = string.Format(CultureInfo.InvariantCulture, ">{0:yyyy-MM-dd'T'HH:mm:ss zzz}", date); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd probably store this pattern in a constant and reuse it throughout. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @khellang I've included this suggestion aswell. I've also updated the relevant unit tests to use a Theory which tests both the |
||
break; | ||
case SearchQualifierOperator.LessThan: | ||
query = string.Format(CultureInfo.InvariantCulture, "<{0:yyyy-MM-dd}", date); | ||
query = string.Format(CultureInfo.InvariantCulture, "<{0:yyyy-MM-dd'T'HH:mm:ss zzz}", date); | ||
break; | ||
case SearchQualifierOperator.LessThanOrEqualTo: | ||
query = string.Format(CultureInfo.InvariantCulture, "<={0:yyyy-MM-dd}", date); | ||
query = string.Format(CultureInfo.InvariantCulture, "<={0:yyyy-MM-dd'T'HH:mm:ss zzz}", date); | ||
break; | ||
case SearchQualifierOperator.GreaterThanOrEqualTo: | ||
query = string.Format(CultureInfo.InvariantCulture, ">={0:yyyy-MM-dd}", date); | ||
query = string.Format(CultureInfo.InvariantCulture, ">={0:yyyy-MM-dd'T'HH:mm:ss zzz}", date); | ||
break; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Matches repositories with regards to both the <param name="from"/> and <param name="to"/> dates. | ||
/// </summary> | ||
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); } | ||
|
@@ -344,7 +354,7 @@ internal string DebuggerDisplay | |
/// <returns><see cref="DateRange"/></returns> | ||
public static DateRange LessThan(DateTime date) | ||
{ | ||
return new DateRange(date, SearchQualifierOperator.LessThan); | ||
return new DateRange(new DateTimeOffset(date), SearchQualifierOperator.LessThan); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -355,7 +365,7 @@ public static DateRange LessThan(DateTime date) | |
/// <returns><see cref="DateRange"/></returns> | ||
public static DateRange LessThanOrEquals(DateTime date) | ||
{ | ||
return new DateRange(date, SearchQualifierOperator.LessThanOrEqualTo); | ||
return new DateRange(new DateTimeOffset(date), SearchQualifierOperator.LessThanOrEqualTo); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -366,7 +376,7 @@ public static DateRange LessThanOrEquals(DateTime date) | |
/// <returns><see cref="DateRange"/></returns> | ||
public static DateRange GreaterThan(DateTime date) | ||
{ | ||
return new DateRange(date, SearchQualifierOperator.GreaterThan); | ||
return new DateRange(new DateTimeOffset(date), SearchQualifierOperator.GreaterThan); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -377,7 +387,7 @@ public static DateRange GreaterThan(DateTime date) | |
/// <returns><see cref="DateRange"/></returns> | ||
public static DateRange GreaterThanOrEquals(DateTime date) | ||
{ | ||
return new DateRange(date, SearchQualifierOperator.GreaterThanOrEqualTo); | ||
return new DateRange(new DateTimeOffset(date), SearchQualifierOperator.GreaterThanOrEqualTo); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -389,7 +399,7 @@ public static DateRange GreaterThanOrEquals(DateTime date) | |
/// <returns><see cref="DateRange"/></returns> | ||
public static DateRange Between(DateTime from, DateTime to) | ||
{ | ||
return new DateRange(from, to); | ||
return new DateRange(new DateTimeOffset(from), new DateTimeOffset(to)); | ||
} | ||
|
||
public override string ToString() | ||
|
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 prefer the unit test actually tests the formatted string eg '2014-1-1'T'020406 1000' (or whatever it should be)
Otherwise these tests are susceptible to whatever formatting bug may exist inside
DateRange
class.EG Im pretty sure the way you've implemented it at the moment isn't correctly formatting the string, yet all these tests pass (because you are using the
DateRange
class to test theDateRange
class! 🤣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.
Hi @ryangribble
Has taken me a while to make these changes due to other commitments, however, they're now there.
Let me know what you think.