-
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
Conversation
Hi @ryangribble build failed but cause does'nt seem to be related to my changes. |
@patricknolan I restarted the problem build - let's see if it goes green |
@@ -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")] | |||
public DateRange(DateTime date, SearchQualifierOperator op) : this(new DateTimeOffset(date), op) |
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.
By forwarding these ctors to the new DateTimeOffset
overloads, the behavior has changed by taking the time into account. That could be a breaking change.
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 DateTimeOffset
ctors.
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
What will the zzz
component be here, given you're using the DateTime
property and not the DateTimeOffset
itself?
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 @khellang the zzz
includes the timezone offset which I believe is correct.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
But what is that offset? DateTime
doesn't store a separate offset.
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.
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 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.
{ | ||
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 comment
The 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 comment
The 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 DateTime
and DateTimeOffset
strategies.
Hi @ryangribble and @khellang when you get a chance let me know what you think! |
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.
Just a few nits from me 👍
@@ -298,37 +298,66 @@ public override string ToString() | |||
[DebuggerDisplay("{DebuggerDisplay,nq}")] | |||
public class DateRange | |||
{ | |||
public const string DateTimePatten = "yyyy-MM-dd'T'HH:mm:ss zzz"; | |||
public const string DatePatten = "yyyy-MM-dd"; |
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.
Nit: Patten
-> Pattern
private readonly string query = string.Empty; | ||
|
||
/// <summary> | ||
/// 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> | ||
[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 comment
The 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
This constructor doesn't use the time component of the specified
DateTime
. Please use the overload accepting aDateTimeOffset
, which also supports time.
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.
Thanks @khellang good pickup. Just made both changes and checked-in.
Hi @khellang all done. |
public DateRange(DateTime date, SearchQualifierOperator op) | ||
{ | ||
switch (op) | ||
{ | ||
case SearchQualifierOperator.GreaterThan: | ||
query = string.Format(CultureInfo.InvariantCulture, ">{0:yyyy-MM-dd}", date); | ||
query = string.Format(CultureInfo.InvariantCulture, ">{0:DatePatten}", date); |
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.
Does this compile? 🤔
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'm thinking it might be better to just use ToString(DatePattern, CultureInfo.InvariantCulture)
and string concatenation or interpolation than the current format strings...
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 @khellang you're thinking something like this?
query = $"{from.ToString(DateTimePattern, CultureInfo.InvariantCulture)}..{to.ToString(DateTimePattern, CultureInfo.InvariantCulture)}";
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'm thinking something like query = FormattableString.Invariant($"{from.ToString(DateTimePattern)}..{to.ToString(DateTimePattern)}");
😄
@@ -342,6 +371,7 @@ internal string DebuggerDisplay | |||
/// </summary> | |||
/// <param name="date">date to be used for comparison (times are ignored)</param> | |||
/// <returns><see cref="DateRange"/></returns> | |||
[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 comment
The reason will be displayed to describe this comment to others. Learn more.
These are not ctors. Maybe also change these to reflect the recommended APIs?
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 @patricknolan
Thanks for sending the PR over, and thanks @khellang for starting the review.
Just to confirm, yes we dont want any behaviuor change on the exiusting DateTime
based ctors and methods. As you've done we can add DateTimeOffset
versions of everything and flag the old ones as [Obsolete]
. They will be deleted from the code base in 2 releases time.
In terms of the tests, im not sure I like the complexity of adding the enum and switching out the request code, as once you take my other comment into account (and actually test the formatted date/time string) there will be a 2nd point that needs to switch. IMO it would be better to just leave all the old tests completely untouched and just copy them for DateTimeOffset versions. As I say, the deprecated stuff will be removed in a couple of releases time so I dont think the test complexity needs to be introduced, would rather just copy/paste them for now, and remove the old ones later.
In terms of the [Obsolete] messages, can we use these please?
"This ctor does not support the time component or timezone and will be removed in a future release. Please use the DateTimeOffset overload instead"
"This method does not support the time component or timezone and will be removed in a future release. Please use the DateTimeOffset overload instead"
[Obsolete("This constructor doesn't use the time component of the specified DateTime. Please use the overload accepting a DateTimeOffset, which also supports time.")] | ||
public DateRange(DateTime from, DateTime to) | ||
{ | ||
query = string.Format(CultureInfo.InvariantCulture, "{0:DateTimePattern}..{1:DateTimePattern}", from, to); |
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.
Same here, it needs to use Date only, not Date+Time
{ | ||
query = string.Format(CultureInfo.InvariantCulture, "{0:yyyy-MM-dd}..{1:yyyy-MM-dd}", from, to); | ||
query = string.Format(CultureInfo.InvariantCulture, "{0:DateTimePatten}..{1:DateTimePatten}", from, to); |
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.
This still has the old spelling. Im not sure you even can parameterize the format string like this anyway?!
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")); | ||
Arg.Is<Dictionary<string, string>>(d => d["q"] == $"github+created:{request.Created}")); |
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 the DateRange
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.
Hi @ryangribble and @khellang,, Has taken me a while to make changes due to other commitments, however, I have now made the changes advised. Let me know what you think. |
👋 Hi @patricknolan Thanks for picking this back up! I'm just trying to get back up to speed... The changes look pretty good now. Just on the
|
Hi @ryangribble changes for [Obsolete] messages have been done. The CI failed, however, it may be an intermittent error as I don't believe the changes could have caused this to fail. I'm not sure how to invoke the CI again without an additional check-in? |
As a user you can't rerun them, I've kicked them off again |
Thanks @ryangribble. You ok for this to be merged now? |
Yep I think we're good now! Thanks @patricknolan 👍 🚢 |
Thanks @ryangribble do you know when this update will be available via nuget? |
release_notes: Enhanced |
Hi @ryangribble just confirming if you do the release notes or do I? Sorry this is my first contribution no am not sure. Am keen to get a new release available via Nuget. |
Hi @patricknolan sorry for the confusion, this is something I do... I'm really sorry I've just been tied up in lots of real life stuff and not cut a new release as yet. If you add a custom nuget source of our appveyor feed |
Not a problem @ryangribble completely understand |
Hi @ryangribble please let me know what you think.