-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Changes from 1 commit
d7072d0
5faa08a
f514c19
daf8e66
7581780
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 |
---|---|---|
|
@@ -421,6 +421,15 @@ describe('timepicker directive', function () { | |
done(); | ||
}); | ||
|
||
}); | ||
it('should set from/to to start/end of day if set from timepicker', function (done) { | ||
$scope.absolute.from = new Date('2012-02-01 12:00'); | ||
$scope.absolute.to = new Date('2012-02-11 12:00'); | ||
|
||
$scope.$digest(); | ||
|
||
expect($scope.absolute.from.valueOf()).to.be(moment('2012-02-01 00:00:00.000').valueOf()); | ||
expect($scope.absolute.to.valueOf()).to.be(moment('2012-02-11 23:59:59.999').valueOf()); | ||
done(); | ||
}); | ||
}); | ||
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. Could you add a test ensuring that manually setting hour/minute/second still works? |
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,11 +76,19 @@ module.directive('kbnTimepicker', function (quickRanges, timeUnits, refreshInter | |
}); | ||
|
||
$scope.$watch('absolute.from', function (date) { | ||
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 | ||
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. 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 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 had this thought too, but I don't think the version of the date picker we're using supports 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. 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. |
||
$scope.absolute.from = moment(date); | ||
} | ||
}); | ||
|
||
$scope.$watch('absolute.to', function (date) { | ||
if (_.isDate(date)) $scope.absolute.to = moment(date); | ||
// If it is a date, it was set from the timepicker, so we set it to the end of day and transform it into a moment | ||
if (_.isDate(date)) { | ||
date.setHours(23, 59, 59, 999); // End of day | ||
$scope.absolute.to = moment(date); | ||
} | ||
}); | ||
|
||
$scope.setMode = function (thisMode) { | ||
|
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.
Should "timepicker" be "datepicker" in this test description and the one below?