MCPcopy Create free account
hub / github.com/choosehappy/QuickAnnotator / createDateInputType

Function createDateInputType

static/js/angular.js:26677–26796  ·  view source on GitHub ↗
(type, regexp, parseDate, format)

Source from the content-addressed store, hash-verified

26675}
26676
26677function createDateInputType(type, regexp, parseDate, format) {
26678 return function dynamicDateInputType(scope, element, attr, ctrl, $sniffer, $browser, $filter, $parse) {
26679 badInputChecker(scope, element, attr, ctrl, type);
26680 baseInputType(scope, element, attr, ctrl, $sniffer, $browser);
26681
26682 var isTimeType = type === 'time' || type === 'datetimelocal';
26683 var previousDate;
26684 var previousTimezone;
26685
26686 ctrl.$parsers.push(function(value) {
26687 if (ctrl.$isEmpty(value)) return null;
26688
26689 if (regexp.test(value)) {
26690 // Note: We cannot read ctrl.$modelValue, as there might be a different
26691 // parser/formatter in the processing chain so that the model
26692 // contains some different data format!
26693 return parseDateAndConvertTimeZoneToLocal(value, previousDate);
26694 }
26695 ctrl.$$parserName = type;
26696 return undefined;
26697 });
26698
26699 ctrl.$formatters.push(function(value) {
26700 if (value && !isDate(value)) {
26701 throw ngModelMinErr('datefmt', 'Expected `{0}` to be a date', value);
26702 }
26703 if (isValidDate(value)) {
26704 previousDate = value;
26705 var timezone = ctrl.$options.getOption('timezone');
26706
26707 if (timezone) {
26708 previousTimezone = timezone;
26709 previousDate = convertTimezoneToLocal(previousDate, timezone, true);
26710 }
26711
26712 return formatter(value, timezone);
26713 } else {
26714 previousDate = null;
26715 previousTimezone = null;
26716 return '';
26717 }
26718 });
26719
26720 if (isDefined(attr.min) || attr.ngMin) {
26721 var minVal = attr.min || $parse(attr.ngMin)(scope);
26722 var parsedMinVal = parseObservedDateValue(minVal);
26723
26724 ctrl.$validators.min = function(value) {
26725 return !isValidDate(value) || isUndefined(parsedMinVal) || parseDate(value) >= parsedMinVal;
26726 };
26727 attr.$observe('min', function(val) {
26728 if (val !== minVal) {
26729 parsedMinVal = parseObservedDateValue(val);
26730 minVal = val;
26731 ctrl.$validate();
26732 }
26733 });
26734 }

Callers 1

angular.jsFile · 0.85

Calls 11

badInputCheckerFunction · 0.85
baseInputTypeFunction · 0.85
isDateFunction · 0.85
isValidDateFunction · 0.85
convertTimezoneToLocalFunction · 0.85
formatterFunction · 0.85
isDefinedFunction · 0.85
$parseFunction · 0.85
parseObservedDateValueFunction · 0.85
isUndefinedFunction · 0.85

Tested by

no test coverage detected