Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

feat(datepicker):add today date in controller with a class on the element #5814

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
dateParser.fromTimezone(new Date(ngModelCtrl.$modelValue), ngModelOptions.timezone) :
dateParser.fromTimezone(new Date(), ngModelOptions.timezone);

this.todayDate = dateParser.fromTimezone(new Date(), ngModelOptions.timezone);

ngModelCtrl.$render = function() {
self.render();
};
Expand Down Expand Up @@ -232,6 +234,10 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
$scope.activeDt = dt;
}

if (this.compare(dt.date, self.todayDate) === 0) {
$scope.todayDt = dt;
}

return dt;
};

Expand Down
10 changes: 10 additions & 0 deletions src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,16 @@ describe('datepicker', function() {
});
});

it('should have a today date equal to the current date', function() {
var baseTime = new Date();
jasmine.clock().mockDate(baseTime);

element = $compile('<uib-datepicker ng-model="fooDate"></uib-datepicker')($rootScope);
$rootScope.$digest();

expect(element.controller('uibDatepicker').todayDate.getTime()).toEqual(baseTime.getTime());
});

it('should support custom templates', function() {
$templateCache.put('foo/bar.html', '<div>baz</div>');

Expand Down
3 changes: 2 additions & 1 deletion template/datepicker/day.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
<button type="button" class="btn btn-default btn-sm"
uib-is-class="
'btn-info' for selectedDt,
'active' for activeDt
'active' for activeDt,
'today' for todayDt
on dt"
ng-click="select(dt.date)"
ng-disabled="::dt.disabled"
Expand Down