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

When a date is selected in absolute mode, set to start/end of day #10433

Merged

Conversation

lukasolson
Copy link
Member

Prior to this PR, when you would open the timepicker and click on "Absolute", then select a from/to date, the hours/mins/secs/ms of the date would persist as you selected different dates.

This PR changes this behavior so that when you choose a "from" date, it automatically selects the beginning of the date (00:00:00.000), and when you choose a "to" date, it automatically selects the end of the date (23:59:59.999).

feb-17-2017 09-47-08

Closes #3803.

if (_.isDate(date)) $scope.absolute.from = moment(date);
// If it is a date, it was set from the timepicker, so we set it to the start of day and transform it into a moment
if (_.isDate(date)) {
date.setHours(0, 0, 0, 0); // Start of day
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of having to guess where the update came from, what if we used a getterSetter for the ng-model on the datepicker using ngModelOptions? Then this setHours logic could live inside the setter.

Copy link
Member Author

Choose a reason for hiding this comment

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

I had this thought too, but I don't think the version of the date picker we're using supports ngModelOptions. I guess I should look into upgrading the library.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does it need to do anything special to support it? I thought the getterSetter would be declared in timepicker.js and it would work without any modification to datepicker, since it would look like a regular model from datepicker's point of view.

expect($scope.absolute.to.valueOf()).to.be(moment('2012-02-11 23:59:59.999').valueOf());
done();
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a test ensuring that manually setting hour/minute/second still works?

@lukasolson
Copy link
Member Author

@cjcenizal What are your thoughts on this change?

@cjcenizal
Copy link
Contributor

cjcenizal commented Feb 24, 2017

This makes sense to me. If I'm selecting a date range, I want to see all data that falls within the entire range -- not have a few hours worth excluded from either end.

If users, for some reason, start asking for the ability to specify and "lock" the particular hour/minute/second values as they change the start and end days, I suggest we add timepicker controls above the date controls to give them that ability.

@alexfrancoeur Any thoughts on this UX?

@alexfrancoeur
Copy link

alexfrancoeur commented Feb 25, 2017

@cjcenizal this looks good to me. The current date selection is pretty awkward. It keeps the relative timerange and applies the the day/month/year to it. I certainly think this works. The only confusion I could foresee is that the defaults are not consistent (for example, both 00:00:000).

That being said, as someone who is investigating this data there is a good chance I'd default to the beginning of the first day and end of the last (or the beginning the last day +1). I think this is a good approach all around.

++ guys!

@lukasolson
Copy link
Member Author

lukasolson commented Feb 27, 2017

@Bargs Could you take another look at this? I've used the ngModelOptions as you suggested and I like it a lot better too.

I had thought that ngModelOptions wasn't available because, while it's listed as part of the config in the latest version of angular-ui-datepicker, it's not listed in our version. But alas, it still works!

@Bargs
Copy link
Contributor

Bargs commented Feb 28, 2017

@lukasolson this is first thing on my todo list tomorrow

Copy link
Contributor

@Bargs Bargs left a comment

Choose a reason for hiding this comment

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

LGTM! Had just one question about test description wording, inline

@@ -421,6 +421,33 @@ describe('timepicker directive', function () {
done();
});

});
it('should set from/to to start/end of day if set from timepicker', function (done) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should "timepicker" be "datepicker" in this test description and the one below?

@lukasolson lukasolson merged commit 3b0c41c into elastic:master Mar 1, 2017
lukasolson added a commit to lukasolson/kibana that referenced this pull request Mar 1, 2017
…astic#10433)

* In absolute timepicker, use whole days

* Use ngModelOptions instead of implicit bindings

* fix absolute timepicker test

* Fix wording in test
@lukasolson
Copy link
Member Author

Backported to 5.x (5.4) in 4f49a71.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants