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

CRM-21148 - Refactor two near-identical date functions into one #11887

Merged
merged 3 commits into from
Apr 16, 2018

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Mar 28, 2018

Overview

At some point, a method was copy-pasted, then modified. This is a partial / reviewer's cut of #10941 which reconciles the differences and reduces code duplication.

Before

No functional change, code tidy up

After

No functional change, code tidy up

Technical Details

This is a partial of #10941 but it skips the conversion from string to integer which had been queried & also the changes in calling functions, which I think is not required for a 'no-change' outcome.

In fact relativeToAbsolute only returns a date-only string or one of the default time strings ('000000' for 'from' or '235959' for 'to'). However, it is unreliable - e.g this.week does not append 235959 when it should so we should continue to ignore the time returned from this function

The original commit changed the way this was called by a bunch of reports. I have not carried that over as it should not be necessary now to call these functions differently to achieve the same result

Comments

@MegaphoneJon Please check this - if you are happy with it I will merge & you can evaluate whether there are additional changes in your PR that you wish to follow up with


@MegaphoneJon
Copy link
Contributor

@eileenmcnaughton I've reviewed this, and unfortunately this approach won't work.
When the function signature has an optional default value:

public function getFromTo($relative, $from, $to, $fromTime = NULL, $toTime = '235959') {

There's a difference between these two invocations:

getFromTo(1, 2, 3, 4);
getFromTo(1, 2, 3, 4, NULL);

In the first case, $toTime will be '235959'; in the other, it will be NULL.

We discussed this some on the other PR, but the old CRM_Core_Form::getFromTo had these lines which gave the same result for the two commands above:

if (empty($toTime)) {
  $toTime = '235959';
}

We either need to a) add that into CRM_Utils_Date::getFromTo or modify the reports so that they don't pass NULL.

Note that this is a separate issue from converting $fromTime and $toTime to int. We could split the difference between our PRs by leaving them as strings, but still modify the existing reports not to pass NULL.

Anyway, you can replicate the bug I found by running the Activity Summary report with an Activity Date filter set to "today", then consulting the Developer tab.

With master or my PR, you should see this line in the WHERE clauses:

activity_date_time >= 20180411000000 ) AND ( activity_date_time <= 20180411235959 )

With this PR, it's:

activity_date_time >= 20180411000000 ) AND ( activity_date_time <= 20180411000000 )

@eileenmcnaughton
Copy link
Contributor Author

@MegaphoneJon how about now - I re-instated the oddity in that function & soft deprecated the function (I figure it makes more sense to update the calls to bypass that function when we touch them).

@MegaphoneJon
Copy link
Contributor

@eileenmcnaughton I've just retested this and feel good about this new cut. The test failure seems unrelated, so I'll give this a merge-on-pass. Thanks for all of your help getting this to the finish line.

@seamuslee001
Copy link
Contributor

Jenkins re test this please

@eileenmcnaughton
Copy link
Contributor Author

I'm going to merge this now rather than wait for unrelated test failure - we should get Paypal onto guzzle so we can prevent those fails

@eileenmcnaughton eileenmcnaughton merged commit 0ce1f53 into civicrm:master Apr 16, 2018
@eileenmcnaughton eileenmcnaughton deleted the date branch April 16, 2018 22:27
@civicrm civicrm deleted a comment from alexander0205 Apr 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants