Skip to content
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

Merged
merged 7 commits into from
Mar 19, 2019
Merged

Conversation

patricknolan
Copy link
Contributor

Hi @ryangribble please let me know what you think.

@patricknolan
Copy link
Contributor Author

Hi @ryangribble build failed but cause does'nt seem to be related to my changes.

@shiftkey
Copy link
Member

shiftkey commented Nov 5, 2018

@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)
Copy link
Contributor

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);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@khellang khellang Nov 5, 2018

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@patricknolan
Copy link
Contributor Author

Hi @ryangribble and @khellang when you get a chance let me know what you think!

Copy link
Contributor

@khellang khellang left a 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";
Copy link
Contributor

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")]
Copy link
Contributor

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 a DateTimeOffset, which also supports time.

Copy link
Contributor Author

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.

@patricknolan
Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this compile? 🤔

Copy link
Contributor

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...

Copy link
Contributor Author

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)}";

Copy link
Contributor

@khellang khellang Nov 7, 2018

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")]
Copy link
Contributor

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?

Copy link
Contributor

@ryangribble ryangribble left a 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);
Copy link
Contributor

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);
Copy link
Contributor

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}"));
Copy link
Contributor

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! 🤣

Copy link
Contributor Author

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.

@patricknolan
Copy link
Contributor Author

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.

@ryangribble
Copy link
Contributor

ryangribble commented Mar 14, 2019

👋 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 [Obsolete] messages, I can see previously I suggested that this wording might be more clear... what do you think?

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"

@patricknolan
Copy link
Contributor Author

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?

@ryangribble
Copy link
Contributor

ryangribble commented Mar 14, 2019

As a user you can't rerun them, I've kicked them off again

@patricknolan
Copy link
Contributor Author

Thanks @ryangribble. You ok for this to be merged now?

@ryangribble
Copy link
Contributor

Yep I think we're good now! Thanks @patricknolan 👍 🚢

LGTM

@ryangribble ryangribble merged commit d16ac98 into octokit:master Mar 19, 2019
@patricknolan
Copy link
Contributor Author

Thanks @ryangribble do you know when this update will be available via nuget?

@ryangribble
Copy link
Contributor

release_notes: Enhanced DateRange class used in SearchClient requests to support time and timezone components

@patricknolan
Copy link
Contributor Author

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.

@ryangribble
Copy link
Contributor

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 https://ci.appveyor.com/nuget/octokit-net, you can get the latest "beta" packages from our master branch, but yes I really do need to make a release and push to nuget proper 🙏

@patricknolan
Copy link
Contributor Author

Not a problem @ryangribble completely understand

@nickfloyd nickfloyd added Type: Feature New feature or request and removed category: feature labels Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants