(type, regexp, parseDate, format)
| 19713 | } |
| 19714 | |
| 19715 | function createDateInputType(type, regexp, parseDate, format) { |
| 19716 | return function dynamicDateInputType(scope, element, attr, ctrl, $sniffer, $browser, $filter) { |
| 19717 | badInputChecker(scope, element, attr, ctrl); |
| 19718 | baseInputType(scope, element, attr, ctrl, $sniffer, $browser); |
| 19719 | var timezone = ctrl && ctrl.$options && ctrl.$options.timezone; |
| 19720 | var previousDate; |
| 19721 | |
| 19722 | ctrl.$$parserName = type; |
| 19723 | ctrl.$parsers.push(function(value) { |
| 19724 | if (ctrl.$isEmpty(value)) return null; |
| 19725 | if (regexp.test(value)) { |
| 19726 | // Note: We cannot read ctrl.$modelValue, as there might be a different |
| 19727 | // parser/formatter in the processing chain so that the model |
| 19728 | // contains some different data format! |
| 19729 | var parsedDate = parseDate(value, previousDate); |
| 19730 | if (timezone === 'UTC') { |
| 19731 | parsedDate.setMinutes(parsedDate.getMinutes() - parsedDate.getTimezoneOffset()); |
| 19732 | } |
| 19733 | return parsedDate; |
| 19734 | } |
| 19735 | return undefined; |
| 19736 | }); |
| 19737 | |
| 19738 | ctrl.$formatters.push(function(value) { |
| 19739 | if (value && !isDate(value)) { |
| 19740 | throw $ngModelMinErr('datefmt', 'Expected `{0}` to be a date', value); |
| 19741 | } |
| 19742 | if (isValidDate(value)) { |
| 19743 | previousDate = value; |
| 19744 | if (previousDate && timezone === 'UTC') { |
| 19745 | var timezoneOffset = 60000 * previousDate.getTimezoneOffset(); |
| 19746 | previousDate = new Date(previousDate.getTime() + timezoneOffset); |
| 19747 | } |
| 19748 | return $filter('date')(value, format, timezone); |
| 19749 | } else { |
| 19750 | previousDate = null; |
| 19751 | return ''; |
| 19752 | } |
| 19753 | }); |
| 19754 | |
| 19755 | if (isDefined(attr.min) || attr.ngMin) { |
| 19756 | var minVal; |
| 19757 | ctrl.$validators.min = function(value) { |
| 19758 | return !isValidDate(value) || isUndefined(minVal) || parseDate(value) >= minVal; |
| 19759 | }; |
| 19760 | attr.$observe('min', function(val) { |
| 19761 | minVal = parseObservedDateValue(val); |
| 19762 | ctrl.$validate(); |
| 19763 | }); |
| 19764 | } |
| 19765 | |
| 19766 | if (isDefined(attr.max) || attr.ngMax) { |
| 19767 | var maxVal; |
| 19768 | ctrl.$validators.max = function(value) { |
| 19769 | return !isValidDate(value) || isUndefined(maxVal) || parseDate(value) <= maxVal; |
| 19770 | }; |
| 19771 | attr.$observe('max', function(val) { |
| 19772 | maxVal = parseObservedDateValue(val); |
no test coverage detected