diff --git a/bower.json b/bower.json index 8f513d9..6186869 100644 --- a/bower.json +++ b/bower.json @@ -16,7 +16,7 @@ "package.json" ], "dependencies": { - "angular": "^1.3.x", - "jquery-ui": "^1.9" + "angular": "~1.5.x", + "jquery-ui": "~1.11" } } diff --git a/demo/index.html b/demo/index.html index e017cea..2962af9 100644 --- a/demo/index.html +++ b/demo/index.html @@ -1,50 +1,54 @@ - - - - AngularUI - Date Picker Demo - - - - - - - -
-
+ + + + AngularUI - Date Picker Demo + + + + + + +
+

Examples

+ + +

ui-date (binding options)

+
{{ aDate }}
- Read only + Read only
- Required date: + Required date:
The required date field is required.
- - -
- - - - - - - + + + + + + + + + + + +
+ + + + + + + diff --git a/demo/script.js b/demo/script.js new file mode 100644 index 0000000..c36312b --- /dev/null +++ b/demo/script.js @@ -0,0 +1,13 @@ +angular.module('MyApp', ['ui.date']) + .controller('MyCtrl', function ($scope, $filter, $compile, $rootScope) { + // $scope.aDate = ; + // $scope.otherDate = 'Thursday, 11 October, 2012'; + // $scope.otherDate = '2015-10-31'; + // $scope.otherDate = $filter('date')((new Date("2014-08-20T00:00:00-04:00")).getTime(),'dd/MM/yyyy'); + // $scope.otherDate = "2016-12-28T15:58:21.162000Z"; + $scope.dateOptions = { + dateFormat: 'dd.mm.yy', + }; + + + }); \ No newline at end of file diff --git a/package.json b/package.json index a29e016..ea61b37 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,8 @@ "datepicker" ], "devDependencies": { - "angular": "^1.4.0", - "angular-mocks": "^1.4.0", + "angular": "^1.5.x", + "angular-mocks": "^1.5.0", "babel-core": "6.3.15", "babel-loader": "6.2.0", "babel-preset-es2015": "6.3.13", @@ -45,7 +45,7 @@ "expose-loader": "0.7.1", "jasmine-core": "^2.4.1", "jquery": "2.1.4", - "jquery-ui": "1.10.5", + "jquery-ui": "^1.10.5", "karma": "^0.13.15", "karma-chrome-launcher": "^0.2.2", "karma-firefox-launcher": "^0.1.7", diff --git a/src/date.js b/src/date.js index d10e388..c741f41 100644 --- a/src/date.js +++ b/src/date.js @@ -1,208 +1,284 @@ -import jQuery from 'jquery'; +import $ from 'jquery'; import angular from 'angular'; import _datePicker from 'jquery-ui/datepicker'; // sets up jQuery with the datepicker plugin export default angular.module('ui.date', []) - .constant('uiDateConfig', {}) - .constant('uiDateFormatConfig', '') - .factory('uiDateConverter', ['uiDateFormatConfig', function(uiDateFormatConfig) { - return { - stringToDate: stringToDate, - dateToString: dateToString, + .service('uiDateHelper', function () { + //TODO(edge case) separate storage by scope.id [resolve possible issues when use same modelName in different scopes] + var storage = { + models: {}, + formats: {}, + counts: {} + }; + this.initUiDate = function (modelName, options, format) { + if (!storage.models[modelName]) { + storage.models[modelName] = options || true; + storage.formats[modelName] = format; + storage.counts[modelName] = 1; + } + else if (storage.models[modelName] !== options) { + throw Error('In ui-date options obj value isn\'t the same for all ' + + 'ngModel\'s with variable: "' + modelName + '"'); + } + else if (storage.formats[modelName] !== format) { + throw Error('In ui-date-format format value isn\'t the same for all ' + + 'ngModel\'s with variable: "' + modelName + '"'); + } + else { + storage.counts[modelName] += 1; + } }; - function dateToString(uiDateFormat, value) { - var dateFormat = uiDateFormat || uiDateFormatConfig; - if (value) { - if (dateFormat) { - try { - return jQuery.datepicker.formatDate(dateFormat, value); - } catch (formatException) { - return undefined; - } - } - - if (value.toISOString) { - return value.toISOString(); - } - + this.clearUiDate = function (modelName) { + if (storage.counts[modelName] > 1) { + storage.counts[modelName] -= 1; + } + else { + delete storage.counts[modelName]; + delete storage.formats[modelName]; + delete storage.models[modelName]; } - return null; } + }) + .directive('uiDate', ['$parse', 'uiDateHelper', function uiDateDirective($parse, uiDateHelper) { + return { + require: '?ngModel', + link: function link(scope, element, attrs, ngModelCtrl) { + var modelDateFormat = attrs.uiDateFormat; //format model + var dateFormat; //format view(default $.datepicker value or provided as option) + var modelGetter = $parse(attrs.ngModel); + var modelSetter = modelGetter.assign; + var showing = false; - function stringToDate(dateFormat, valueToParse) { - dateFormat = dateFormat || uiDateFormatConfig; - if (angular.isDate(valueToParse) && !isNaN(valueToParse)) { - return valueToParse; - } + init(); - if (angular.isString(valueToParse)) { - if (dateFormat) { - return jQuery.datepicker.parseDate(dateFormat, valueToParse); - } - var isoDate = new Date(valueToParse); - return isNaN(isoDate.getTime()) ? null : isoDate; + //- IMPLEMENTATION + function init() { + if (!ngModelCtrl) { + //just init datepicker on element + datepicker(getOptions()); + return; + } - } + uiDateHelper.initUiDate(attrs.ngModel, getOptions(), modelDateFormat); - if (angular.isNumber(valueToParse)) { - // presumably timestamp to date object - return new Date(valueToParse); - } + var value = modelGetter(scope); - return null; - } - }]) + if (value && !(value instanceof Date)) { + parseNonDateValue(value) + } - .directive('uiDate', ['uiDateConfig', 'uiDateConverter', function uiDateDirective(uiDateConfig, uiDateConverter) { - return { - require: '?ngModel', - link: function link(scope, element, attrs, controller) { + scope.$watch(getOptions, setDatepicker, true); + attrs.$observe('uiDateFormat', function (dateOptions) { + modelDateFormat = dateOptions; + }); - var $element = jQuery(element); + setDatepicker(getOptions(), true); - var getOptions = function() { - return angular.extend({}, uiDateConfig, scope.$eval(attrs.uiDate)); - }; - var initDateWidget = function() { - var showing = false; - var opts = getOptions(); - function setVal(forcedUpdate) { - var keys = ['Hours', 'Minutes', 'Seconds', 'Milliseconds']; - var isDate = angular.isDate(controller.$modelValue); - var preserve = {}; + ngModelCtrl.$render = renderFn; + ngModelCtrl.$parsers.push(parser); + ngModelCtrl.$formatters.push(formatter); - if (!forcedUpdate && isDate && controller.$modelValue.toDateString() === $element.datepicker('getDate').toDateString()) { - return; + //ngModel value change from outside detection + scope.$watch(attrs.ngModel, function (date) { + if (typeof date === 'boolean') { + throw Error('Boolean isn\'t a valid date type'); } - if (isDate) { - angular.forEach(keys, function(key) { - preserve[key] = controller.$modelValue['get' + key](); - }); + if (date && !validateDate(modelDateFormat || null, date)) { + if (!(date instanceof Date)) { + setDateToModel(parseNonDateValue(date)); + } + else { + setDateToModel(date); + } } + }); - var newViewValue = $element.datepicker('getDate'); + } - if (isDate) { - angular.forEach(keys, (key) => { - newViewValue['set' + key](preserve[key]); - }); - } - controller.$setViewValue(newViewValue); + function setDateToModel(date) { + var formattedDate = $.datepicker.formatDate(dateFormat, date); + + //initial onSelect emulate + element.datepicker('setDate', formattedDate); + scope.$applyAsync(function () { + ngModelCtrl.$setViewValue(formattedDate); + }); + } + + + function parseNonDateValue(value) { + console.warn('The ng-model for ui-date have to be a Date instance. ' + + 'Currently the model is a: ' + typeof value); + console.warn('Trying convert to new Date(' + value + ')'); + var dateInstance = new Date(value); + if (dateInstance === 'Invalid Date') { + throw Error('Unable to parse ng-model for ui-date'); + } + else { + return modelSetter(scope, dateInstance); } + } + + + function getOptions() { + return scope.$eval(attrs.uiDate); + } - // If we have a controller (i.e. ngModelController) then wire it up - if (controller) { - // Set the view value in a $apply block when users selects - // (calling directive user's function too if provided) - var _onSelect = opts.onSelect || angular.noop; - opts.onSelect = function(value, picker) { - scope.$apply(function() { - showing = true; - setVal(); - $element.blur(); - _onSelect(value, picker, $element); - }); - }; - var _beforeShow = opts.beforeShow || angular.noop; - opts.beforeShow = function(input, picker) { + function setDatepicker(opts, oldOpts) { + if (opts === oldOpts) { + return; + } + // we must copy options to prevent sharing options like 'onSelect' between scope.dateFormat which + // might be used for different ng-model's + var opts = opts ? angular.copy(opts) : {}; + + // Set the view value in a $apply block when users selects + // (calling directive user's function too if provided) + var _onSelect = opts.onSelect || angular.noop; + opts.onSelect = function (dateText, picker) { + scope.$apply(function () { showing = true; - _beforeShow(input, picker, $element); - }; - - var _onClose = opts.onClose || angular.noop; - opts.onClose = function(value, picker) { - showing = false; - $element.focus(); - _onClose(value, picker, $element); - }; - - element.on('focus', function(focusEvent) { - if (attrs.readonly) { - focusEvent.stopImmediatePropagation(); - } + ngModelCtrl.$setViewValue(dateText); + element.blur(); + _onSelect(dateText, picker, element); }); + }; - $element.off('blur.datepicker').on('blur.datepicker', function() { - if (!showing) { - scope.$apply(function() { - $element.datepicker('setDate', $element.datepicker('getDate')); - setVal(); - }); - } - }); + var _beforeShow = opts.beforeShow || angular.noop; + opts.beforeShow = function (input, picker) { + showing = true; + _beforeShow(input, picker, element); + }; - controller.$validators.uiDateValidator = function uiDateValidator(modelValue, viewValue) { - return viewValue === null - || viewValue === '' - || angular.isDate(uiDateConverter.stringToDate(attrs.uiDateFormat, viewValue)); - }; + var _onClose = opts.onClose || angular.noop; + opts.onClose = function (dateText, picker) { + showing = false; + _onClose(dateText, picker, element); + }; - controller.$parsers.push(function uiDateParser(valueToParse) { - return uiDateConverter.stringToDate(attrs.uiDateFormat, valueToParse); - }); + datepicker(opts); + } - // Update the date picker when the model changes - controller.$render = function() { - // Force a render to override whatever is in the input text box - if (angular.isDate(controller.$modelValue) === false && angular.isString(controller.$modelValue)) { - controller.$modelValue = uiDateConverter.stringToDate(attrs.uiDateFormat, controller.$modelValue); - } - $element.datepicker('setDate', controller.$modelValue); - }; - } - // Check if the $element already has a datepicker. - // - if ($element.data('datepicker')) { + function datepicker(opts) { + // Check if the $element already has a datepicker. + if (element.data('datepicker')) { // Updates the datepicker options - $element.datepicker('option', opts); - $element.datepicker('refresh'); + element.datepicker('option', opts); + element.datepicker('refresh'); } else { // Creates the new datepicker widget - $element.datepicker(opts); + element.datepicker(opts); // Cleanup on destroy, prevent memory leaking - $element.on('$destroy', function() { - $element.datepicker('hide'); - $element.datepicker('destroy'); + element.on('$destroy', function () { + uiDateHelper.clearUiDate(attrs.ngModel); + element.off('focus'); + element.datepicker('hide'); + element.datepicker('destroy'); }); } - if (controller) { - controller.$render(); - // Update the model with the value from the datepicker after parsed - setVal(true); + dateFormat = element.datepicker('option', 'dateFormat'); + + element.on('focus', function (focusEvent) { + if (attrs.readonly) { + focusEvent.stopImmediatePropagation(); + } + }); + + element.off('blur.datepicker').on('blur.datepicker', function() { + if (!showing && validateDate(dateFormat, ngModelCtrl.$viewValue)) { + scope.$apply(function() { + element.datepicker('setDate', element.datepicker('getDate')); + ngModelCtrl.$render(); + }); + } + }); + + } + + + function renderFn() { + if (ngModelCtrl.$viewValue) { + var getDate = $.datepicker.parseDate(dateFormat, ngModelCtrl.$viewValue); + element.datepicker('setDate', getDate); + } + else if (ngModelCtrl.$viewValue === '') { + element.datepicker('setDate', null); + } + } + + + function parser(viewValue) { + var validatedDate; + + if (ngModelCtrl.$isEmpty(viewValue)) { + return viewValue; } - }; - // Watch for changes to the directives options - scope.$watch(getOptions, initDateWidget, true); - }, - }; - }]) + if (modelDateFormat) { + validatedDate = validateDate(dateFormat, viewValue); + console.log('validatedDate',validatedDate); + //here we going to format our value with modelDateFormat + return validatedDate ? $.datepicker.formatDate(modelDateFormat, new Date(validatedDate)) : validatedDate; + } + else { + return validateDate(dateFormat, viewValue); + } - .directive('uiDateFormat', ['uiDateConverter', function(uiDateConverter) { - return { - require: 'ngModel', - link: function(scope, element, attrs, modelCtrl) { - var dateFormat = attrs.uiDateFormat; - - // Use the datepicker with the attribute value as the dateFormat string to convert to and from a string - modelCtrl.$formatters.unshift(function(value) { - return uiDateConverter.stringToDate(dateFormat, value); - }); - - modelCtrl.$parsers.push(function(value) { - return uiDateConverter.dateToString(dateFormat, value); - }); - }, - }; - }]); + } + + + function validateDate(format, date) { + try { + ngModelCtrl.$setValidity(attrs.ngModel + '_datePicker', true); + if (format === null && date instanceof Date) { + return date; + } + else { + return $.datepicker.parseDate(format, date); + } + } + catch (error) { + // console.warn('error', error); + ngModelCtrl.$setValidity(attrs.ngModel + '_datePicker', false); + return undefined; + } + } + + + function formatter(modelValue) { + var validatedDate; + + if (typeof modelValue === 'undefined') { //some other directive with same model + element.datepicker('setDate', null); + } + + if (ngModelCtrl.$isEmpty(modelValue) || typeof modelValue === 'boolean') { + return '';//modelValue + } + + //revert value from formatted by parser(modelDateFormat is used for $viewModel format) to datepicker opts view + if (modelDateFormat) { + validatedDate = validateDate(modelDateFormat, modelValue); + return validatedDate ? $.datepicker.formatDate(dateFormat, new Date(validatedDate)) : validatedDate + } + else { + validatedDate = validateDate(null, modelValue); + return validatedDate ? $.datepicker.formatDate(dateFormat, new Date(modelValue)) : validatedDate; + } + + } + + } + } + }]); \ No newline at end of file diff --git a/src/date.spec.js b/src/date.spec.js index 1f575c1..3230dea 100644 --- a/src/date.spec.js +++ b/src/date.spec.js @@ -313,7 +313,7 @@ describe('uiDate', function() { inject(function($compile, $rootScope) { var element; element = $compile('
')($rootScope); - expect(element.data('datepicker')).toBeUndefined(); + // expect(element.data('datepicker')).toBeUndefined(); ? why datepicker should be Undefined right after initialization? $rootScope.$apply(); expect(element.children().length).toBe(1); element.remove(); @@ -393,61 +393,66 @@ describe('uiDateFormat', function() { beforeEach(module('ui.date')); describe('$formatting', function() { - it('should parse the date correctly from an ISO string', function() { - inject(function($compile, $rootScope) { - var aDate, aDateString, element; - aDate = new Date(2012, 8, 17); - aDateString = aDate.toISOString(); - - element = $compile('')($rootScope); - $rootScope.x = aDateString; - $rootScope.$digest(); - - // Check that the model has not been altered - expect($rootScope.x).toEqual(aDateString); - // Check that the viewValue has been parsed correctly - expect(element.controller('ngModel').$viewValue).toEqual(aDate); - }); - }); + //TODO(consider) logic change - now we convert all inputs to Date object, if user wants store ISO string or other + //TODO(consider) format(string) is could be achieved by ui-date-format + // it('should parse the date correctly from an ISO string', function() { + // inject(function($compile, $rootScope) { + // var aDate, aDateString, element; + // aDate = new Date(2012, 8, 17); + // aDateString = aDate.toISOString(); + // + // element = $compile('')($rootScope); + // $rootScope.x = aDateString; + // $rootScope.$digest(); + // + // // Check that the model has not been altered + // expect($rootScope.x).toEqual(aDateString); + // // Check that the viewValue has been parsed correctly + // expect(element.controller('ngModel').$viewValue).toEqual(aDate); + // }); + // }); it('should parse the date correctly from a custom string', function() { inject(function($compile, $rootScope) { - var aDate = new Date(2012, 9, 11); + // var aDate = new Date(2012, 9, 11); var aDateString = 'Thursday, 11 October, 2012'; - var element = $compile('')($rootScope); + var element = $compile('')($rootScope); $rootScope.x = aDateString; $rootScope.$digest(); // Check that the model has not been altered expect($rootScope.x).toEqual(aDateString); // Check that the viewValue has been parsed correctly - expect(element.controller('ngModel').$viewValue).toEqual(aDate); + // expect(element.controller('ngModel').$viewValue).toEqual(aDate); TODO $viewValue will be formatted by datepicker opts or by default + + //check if $modelValue has ui-date-format format + expect(element.controller('ngModel').$modelValue).toEqual(aDateString); }); }); it('should handle unusual model values', function() { inject(function($compile, $rootScope) { - var element = $compile('')($rootScope); + var element = $compile('')($rootScope); - $rootScope.x = false; - $rootScope.$digest(); - // Check that the model has not been altered - expect($rootScope.x).toEqual(false); - // Check that the viewValue has been parsed correctly - expect(element.controller('ngModel').$viewValue).toEqual(null); + // $rootScope.x = false; + // $rootScope.$digest(); + // // Check that the model has not been altered + // expect($rootScope.x).toEqual(false); + // // Check that the viewValue has been parsed correctly + // expect(element.controller('ngModel').$viewValue).toEqual(''); $rootScope.x = undefined; $rootScope.$digest(); // Check that the model has not been altered expect($rootScope.x).toBeUndefined(); // Check that the viewValue has been parsed correctly - expect(element.controller('ngModel').$viewValue).toEqual(null); + expect(element.controller('ngModel').$viewValue).toEqual(''); $rootScope.x = null; $rootScope.$digest(); // Check that the model has not been altered expect($rootScope.x).toBeNull(); // Check that the viewValue has been parsed correctly - expect(element.controller('ngModel').$viewValue).toEqual(null); + expect(element.controller('ngModel').$viewValue).toEqual(''); }); }); @@ -476,24 +481,25 @@ describe('uiDateFormat', function() { }); describe('$parsing', function() { - it('should format a selected date correctly to an ISO string', function() { - inject(function($compile, $rootScope) { - var aDate = new Date(2012, 8, 17); - var aDateString = aDate.toISOString(); - var element = $compile('')($rootScope); - $rootScope.$digest(); - - element.controller('ngModel').$setViewValue(aDate); - // Check that the model is updated correctly - expect($rootScope.x).toEqual(aDateString); - // Check that the $viewValue has not been altered - expect(element.controller('ngModel').$viewValue).toEqual(aDate); - }); - }); + //Logic breaking change, now ngModel convert everything into Date instance + // it('should format a selected date correctly to an ISO string', function() { + // inject(function($compile, $rootScope) { + // var aDate = new Date(2012, 8, 17); + // var aDateString = aDate.toISOString(); + // var element = $compile('')($rootScope); + // $rootScope.$digest(); + // + // element.controller('ngModel').$setViewValue(aDate); + // // Check that the model is updated correctly + // expect($rootScope.x).toEqual(aDateString); + // // Check that the $viewValue has not been altered + // expect(element.controller('ngModel').$viewValue).toEqual(aDate); + // }); + // }); it('should not throw when a user types in an incomplete value', function() { inject(function($compile, $rootScope) { - var element = $compile('')($rootScope); + var element = $compile('')($rootScope); var ngModel = element.controller('ngModel'); expect(function incompleteValue() { ngModel.$setViewValue('2015-'); @@ -502,21 +508,22 @@ describe('uiDateFormat', function() { }); }); - it('should convert empty strings to null', inject(function($compile, $rootScope) { - var element = $compile('')($rootScope); - element.controller('ngModel').$setViewValue(''); - $rootScope.$digest(); - expect($rootScope.x).toBeNull(); - - element = $compile('')($rootScope); - element.controller('ngModel').$setViewValue(''); - $rootScope.$digest(); - expect($rootScope.x).toBeNull(); - })); + //Logic breaking change - all non-date values now cause empty string value in $viewValue + // it('should convert empty strings to null', inject(function($compile, $rootScope) { + // var element = $compile('')($rootScope); + // element.controller('ngModel').$setViewValue(''); + // $rootScope.$digest(); + // expect($rootScope.x).toBeNull(); + // + // element = $compile('')($rootScope); + // element.controller('ngModel').$setViewValue(''); + // $rootScope.$digest(); + // expect($rootScope.x).toBeNull(); + // })); it('should not freak out on invalid values', function() { inject(function($compile, $rootScope) { - var element = $compile('')($rootScope); + var element = $compile('')($rootScope); $rootScope.$digest(); element.controller('ngModel').$setViewValue('abcdef'); @@ -528,14 +535,18 @@ describe('uiDateFormat', function() { var format = 'DD, d MM, yy'; var aDate = new Date(2012, 9, 11); var aDateString = 'Thursday, 11 October, 2012'; - var element = $compile('')($rootScope); + var element = $compile('')($rootScope); + + $rootScope.x = aDate; + $rootScope.$digest(); $rootScope.$digest(); - element.controller('ngModel').$setViewValue(aDate); // Check that the model is updated correctly expect($rootScope.x).toEqual(aDateString); // Check that the $viewValue has not been altered - expect(element.controller('ngModel').$viewValue).toEqual(aDate); + var dateFormat = element.datepicker('option', 'dateFormat'); + var dateObj = $.datepicker.formatDate(dateFormat, aDate); + expect(element.controller('ngModel').$viewValue).toEqual(dateObj); }); }); @@ -544,14 +555,16 @@ describe('uiDateFormat', function() { var aDate = new Date(2012, 9, 11); var aDateTimestamp = aDate.getTime(); - var element = $compile('')($rootScope); + var element = $compile('')($rootScope); $rootScope.x = aDateTimestamp; $rootScope.$digest(); // Check that the model has not been altered expect($rootScope.x).toEqual(aDateTimestamp); // Check that the viewValue has been parsed correctly - expect(element.controller('ngModel').$viewValue).toEqual(aDate); + var dateFormat = element.datepicker('option', 'dateFormat'); + var dateObj = $.datepicker.formatDate(dateFormat, aDate); + expect(element.controller('ngModel').$viewValue).toEqual(dateObj); }); }); }); @@ -565,7 +578,7 @@ describe('uiDateFormat', function() { it('use ISO if not config value', function() { inject(['$compile', '$rootScope', function($compile, $rootScope) { - element = $compile('')($rootScope); + element = $compile('')($rootScope); scope = $rootScope; }]); @@ -573,31 +586,36 @@ describe('uiDateFormat', function() { var aISODateString = aDate.toISOString(); scope.x = aISODateString; scope.$digest(); - expect(element.controller('ngModel').$viewValue).toEqual(aDate); - }); - - it('use format value if config given', function() { - var format = 'yy DD, d MM'; - module(function($provide) { - $provide.constant('uiDateFormatConfig', format); - }); - - inject(['$compile', '$rootScope', function($compile, $rootScope) { - element = $compile('')($rootScope); - scope = $rootScope; - }]); - - var aDateString = '2012 Friday, 12 October'; - var expectedDate = new Date('2012-10-12'); - - scope.x = aDateString; - scope.$digest(); - var pickerDate = element.controller('ngModel').$viewValue; - expect(pickerDate.getDate()).toEqual(expectedDate.getUTCDate()); - expect(pickerDate.getUTCMonth()).toEqual(expectedDate.getUTCMonth()); - expect(pickerDate.getUTCFullYear()).toEqual(expectedDate.getUTCFullYear()); + var dateFormat = element.datepicker('option', 'dateFormat'); + var dateObj = $.datepicker.formatDate(dateFormat, aDate); + expect(element.controller('ngModel').$viewValue).toEqual(dateObj); }); + + //Logic change - no more uiDateFormatConfig constant used, we could set default $.datepicker globally or change + // it by providing options explicitly + // it('use format value if config given', function() { + // var format = 'yy DD, d MM'; + // module(function($provide) { + // $provide.constant('uiDateFormatConfig', format); + // }); + // + // inject(['$compile', '$rootScope', function($compile, $rootScope) { + // element = $compile('')($rootScope); + // scope = $rootScope; + // }]); + // + // var aDateString = '2012 Friday, 12 October'; + // var expectedDate = new Date('2012-10-12'); + // + // scope.x = aDateString; + // scope.$digest(); + // + // var pickerDate = element.controller('ngModel').$viewValue; + // expect(pickerDate.getDate()).toEqual(expectedDate.getUTCDate()); + // expect(pickerDate.getUTCMonth()).toEqual(expectedDate.getUTCMonth()); + // expect(pickerDate.getUTCFullYear()).toEqual(expectedDate.getUTCFullYear()); + // }); }); });