diff --git a/src/datepicker/datepicker.js b/src/datepicker/datepicker.js index ef3a5c4b52..4204d95dd3 100644 --- a/src/datepicker/datepicker.js +++ b/src/datepicker/datepicker.js @@ -145,7 +145,7 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst model = dateParser.fromTimezone(model, ngModelOptions.timezone); var dt = { date: date, - label: dateFilter(date, format), + label: dateFilter(date, format.replace(/d!/, 'dd')).replace(/M!/, 'MM'), selected: model && this.compare(date, model) === 0, disabled: this.isDisabled(date), current: this.compare(date, new Date()) === 0, @@ -729,6 +729,9 @@ function(scope, element, attrs, $compile, $parse, $document, $rootScope, $positi return value; } scope.date = dateParser.fromTimezone(value, ngModelOptions.timezone); + dateFormat = dateFormat.replace(/M!/, 'MM') + .replace(/d!/, 'dd'); + return dateFilter(scope.date, dateFormat); }); } else { diff --git a/src/datepicker/test/datepicker.spec.js b/src/datepicker/test/datepicker.spec.js index 44376dae1f..11eb8c521b 100644 --- a/src/datepicker/test/datepicker.spec.js +++ b/src/datepicker/test/datepicker.spec.js @@ -1948,6 +1948,30 @@ describe('datepicker', function() { }); }); + describe('custom format with optional leading zeroes', function() { + beforeEach(inject(function() { + var wrapElement = $compile('