Default validation for Date Types data structure
168764
def validate_dates(prop, value, xpath_map=None):
    

    if value is not None:
        validate_type(prop, value, dict)

        date_keys = set(value)

        if date_keys:
            if DATE_TYPE not in date_keys or DATE_VALUES not in date_keys:
                if prop in _complex_definitions:
                    complex_keys = _complex_definitions[prop]
                else:
                    complex_keys = _complex_definitions[DATES] if xpath_map is None else xpath_map

                _validation_error(prop, None, value, ('keys: {0}'.format(','.join(complex_keys))))

            date_type = value[DATE_TYPE]

            if date_type not in DATE_TYPES:
                _validation_error('dates.type', None, date_type, DATE_TYPES)

            date_vals = value[DATE_VALUES]

            validate_type('dates.values', date_vals, list)

            dates_len = len(date_vals)

            if date_type == DATE_TYPE_MISSING and dates_len != 0:
                _validation_error('len(dates.values)', None, dates_len, 0)

            if date_type == DATE_TYPE_SINGLE and dates_len != 1:
                _validation_error('len(dates.values)', None, dates_len, 1)

            if date_type == DATE_TYPE_RANGE and dates_len != 2:
                _validation_error('len(dates.values)', None, dates_len, 2)

            if date_type == DATE_TYPE_MULTIPLE and dates_len < 2:
                _validation_error('len(dates.values)', None, dates_len, 'at least two')

            for idx, date in enumerate(date_vals):
                date_key = 'dates.value[' + str(idx) + ']'
                validate_type(date_key, date, string_types)
1015545
function convertDateType (data) {
  if (!(data.type === 'string' && data.pattern)) {
    return data
  }
  const pattern = data.pattern
  delete data.pattern
  switch (pattern) {
    case constants.dateOnlyPattern:
      data['type'] = 'date-only'
      break
    case constants.timeOnlyPattern:
      data['type'] = 'time-only'
      break
    case constants.dateTimeOnlyPattern:
      data['type'] = 'datetime-only'
      break
    case constants.RFC3339DatetimePattern:
      data['type'] = 'datetime'
      data['format'] = constants.RFC3339
      break
    case constants.RFC2616DatetimePattern:
      data['type'] = 'datetime'
      data['format'] = constants.RFC2616
      break
    default:
      data['pattern'] = pattern
  }
  return data
}
1238058
function date(value) {
  var parsedDate = Date.parse(value);

  // couldn't parse it
  if (typeOf(parsedDate) != 'number') {
    return throwModifierError('date', value, {message: 'Invalid Date'});
  }

  return new Date(parsedDate);
}
1234146
static function convertDateRangeDefaultsToDates($in_type, $in_string, &$range_start, &$range_end)
    {
        $retval = true;
        if ($in_type == "DATE") {
            $elar = preg_split("/-/", $in_string);
            if (count($elar) == 1) {
                $range_start = $in_string;
            } else if (count($elar) == 3) // Specified in xx-xx-xx format
            {
                $range_start = $elar[0] . "-" . $elar[1] . "-" . $elar[2];
            } else {
                $retval = false;
                $range_start = "TODAY";
            }
        }

        if ($in_type == "DATERANGE") {
            $range_start = "TODAY";
            $range_end = "TODAY";
            $elar = preg_split("/-/", $in_string);

            if (count($elar) == 2) {
                $range_start = $elar[0];
                $range_end = $elar[1];
            } else if (count($elar) == 6) // Specified in xx-xx-xx format
            {
                $range_start = $elar[0] . "-" . $elar[1] . "-" . $elar[2];
                $range_end = $elar[3] . "-" . $elar[4] . "-" . $elar[5];
            } else if (count($elar) == 4 && is_numeric($elar[0]) && is_numeric($elar[1]) && is_numeric($elar[2]) && !is_numeric($elar[3])) // Specified in xx-xx-xx format
            {
                $range_start = $elar[0] . "-" . $elar[1] . "-" . $elar[2];
                $range_end = $elar[3];
            } else if (count($elar) == 4 && is_numeric($elar[1]) && is_numeric($elar[2]) && is_numeric($elar[3]) && !is_numeric($elar[0])) // Specified in xx-xx-xx format
            {
                $range_start = $elar[0];
                $range_end = $elar[1] . "-" . $elar[2] . "-" . $elar[3];
            } else {
                $retval = false;
                $range_start = "TODAY";
                $range_end = "TODAY";
            }
        }

        return $retval;
    }
52684
def _validate_date_str(str_):
    """"""

    if not str_:
        return None

    # Convert to datetime so we can validate it's a real date that exists then
    # convert it back to the string.
    try:
        date = datetime.strptime(str_, DATE_FMT)
    except ValueError:
        msg = 'Invalid date format, should be YYYY-MM-DD'
        raise argparse.ArgumentTypeError(msg)

    return date.strftime(DATE_FMT)
210891
def _validate_type_scalar(self, value):
        
        if isinstance(
            value, _int_types + (_str_type, float, date, datetime, bool)
        ):
            return True
899987
def convert_date(value, parameter):
    '''
    
    '''
    value = _check_default(value, parameter, ( '', '-', None ))
    if value is None or isinstance(value, datetime.date):
        return value
    for fmt in settings.DATE_INPUT_FORMATS:
        try:
            return datetime.datetime.strptime(value, fmt).date()
        except (ValueError, TypeError):
            continue
    raise ValueError("`{}` does not match a format in settings.DATE_INPUT_FORMATS".format(value))
514816
function isValid(date) {
  return Object.prototype.toString.call(date) == '[object Date]' && !isNaN(date.getTime());
}
1254079
function default_1(value) {
    if (pretty_easy_data_types_1.isString(value))
        return makeDate_1.stringDate(value);
    else if (pretty_easy_data_types_1.isDate(value))
        return true;
    else
        return false;
}
1161437
function(schemaType, schemaDefault) {
    if (!_.isUndefined(schemaDefault)) {
      return schemaDefault;
    }
    switch (schemaType) {
      case 'integer':
      case 'uinteger':
      case 'float':
      case 'ufloat':
        return 0;
      case 'boolean':
        return false;
      case 'timestamp':
        return new Date().getTime(); // ms
      case 'date':
        return new Date(); // iso
      default:
        return null;
    }
  }
421052
function fixInvalidDate(dateString) {
  if (!dateString) {
    return;
  }

  //Convert invalid dates' timezones to GMT using timezoneMap
  dateString = dateString.replace(/BST?/i, function (match) {
    return timezoneMap[match];
  });

  //Some dates come in as ET, CT etc.. and some don't have the correct offset.
  //Matches /ET/EDT/EST/CT/CDT/CST/MT/MDT/MST/PT/PDT/PST if found at the end of a date string
  var newDateString = dateString.replace(/(E|C|M|P)[DS+]?T$/i, function (match) {
    var firstChar = match.charAt(0);
    return isDaylightSavingsTime() ? (firstChar + 'DT') : (firstChar + 'ST');
  });

  return new Date(newDateString);
}
1277489
function parse_date_strings(root) {
    for (key in root) {
        if (!root.hasOwnProperty(key)) continue;
        var value = root[key];
        if (typeof(value) === 'object') { 
            parse_date_strings(value);
        } else if (typeof(value) === 'string' && /\d{4}-?\d{2}-?\d{2}(T?\d{2}:?\d{2}:?\d{2}(Z)?)?/.test(value)) {
            var timestamp = Date.parse(value);
            if (!isNaN(timestamp)) {
                root[key] = new Date(timestamp);
            }
        }
    }
}
53989
function (date) {
            this._setDefaultMinMaxTime();
            if (date) {
                if (dp.isSame(date, this.d.opts.minDate)) {
                    this._setMinTimeFromDate(this.d.opts.minDate);
                } else if (dp.isSame(date, this.d.opts.maxDate)) {
                    this._setMaxTimeFromDate(this.d.opts.maxDate);
                }
            }

            this._validateHoursMinutes(date);
        }
436962
def match_date(self, value, strict=False):
        """"""
        value = stringify(value)
        try:
            parse(value)
        except Exception:
            self.shout('Value %r is not a valid date', strict, value)
1313687
function validateProperty(object, value, property, schema, options, errors, indexInArray, array) {
    var valid,
        type;

    function constrain(name, value, assert) {
      if (schema[name] !== undefined && !assert(value, schema[name])) {
        error(name, property, value, schema, errors);
      }
    }

    //validate default value
    if (options.validateDefaultValue && schema['default'] !== undefined &&
        property != 'default') {
      validateProperty(schema, schema['default'], 'default', schema, options, errors);
    }

    if (value === undefined) {
      //apply default value if have an option and default value
      if (options.applyDefaultValue && schema['default'] !== undefined) {
        value = schema['default'];
        object[property] = value;
        return;
      } else if (schema.required) {
        var required = schema.required;
        if (typeof required === 'function') {
          required = required(object, property);
        }
        if (required && schema.type !== 'any') {
          return error('required', property, undefined, schema, errors);
        } else {
          return;
        }
      } else {
        return;
      }
    }

    if (options.cast) {
      if (('integer' === schema.type || 'number' === schema.type) && value == +value) {
        value = +value;
      }

      if ('boolean' === schema.type) {
        if ('true' === value || '1' === value || 1 === value) {
          value = true;
        }

        if ('false' === value || '0' === value || 0 === value) {
          value = false;
        }
      }

      if ('date' === schema.type) {
        value = new Date(value);
      }
      //modify source object if we have an option and values are differ
      //for simple value
      if (options.castSource && indexInArray == null && object[property] !== value) {
        object[property] = value;
      } else
        if (options.castSource && indexInArray != null && array[indexInArray] !== value) {
          //and for an array
          array[indexInArray] = value;
        }
    }

    if (schema['enum'] && schema['enum'].indexOf(value) === -1) {
      error('enum', property, value, schema, errors);
    }

    // Dependencies (see 5.8)
    if (typeof schema.dependencies === 'string' &&
        object[schema.dependencies] === undefined) {
      error('dependencies', property, null, schema, errors);
    }

    if (isArray(schema.dependencies)) {
      for (var i = 0, l = schema.dependencies.length; i < l; i++) {
        if (object[schema.dependencies[i]] === undefined) {
          error('dependencies', property, null, schema, errors);
        }
      }
    }

    if (typeof schema.dependencies === 'object') {
      var oldAdditionalProperties = options.additionalProperties;
      options.additionalProperties = true;
      validateObject(object, schema.dependencies, options, errors);
      options.additionalProperties = oldAdditionalProperties;
    }

    checkType(value, schema.type, function(err, type) {
      var errorsCountBeforeCheckType = errors.length;
      if (err) return error('type', property, typeof value, schema, errors);

      constrain('conform', value, function (a, e) { return e(a, object, property) });

      switch (type || (isArray(value) ? 'array' : typeof value)) {
        case 'string':
          constrain('minLength', value.length, function (a, e) { return a >= e });
          constrain('maxLength', value.length, function (a, e) { return a <= e });
          constrain('pattern',   value,        function (a, e) {
            e = typeof e === 'string'
              ? e = new RegExp(e)
              : e;
            return e.test(a)
          });
          if (options.validateFormats) {
            constrain('format', value, function(value, format) {
              var spec;
              if (options.validateFormatExtensions) {
                spec = validate.formatExtensions[format];
              }
              if (!spec) {
                spec = validate.formats[format];
              }
              if (spec) {
                return spec.test(value);
              } else {
                return !options.validateFormatsStrict;
              }
            });
          }
          break;
        case 'integer':
        case 'number':
          constrain('minimum',     value, function (a, e) { return a >= e });
          constrain('maximum',     value, function (a, e) { return a <= e });
          constrain('exclusiveMinimum', value, function (a, e) { return a > e });
          constrain('exclusiveMaximum', value, function (a, e) { return a < e });
          constrain('divisibleBy', value, function (a, e) {
            var multiplier = Math.max((a - Math.floor(a)).toString().length - 2, (e - Math.floor(e)).toString().length - 2);
            multiplier = multiplier > 0 ? Math.pow(10, multiplier) : 1;
            return (a * multiplier) % (e * multiplier) === 0
          });
          break;
        case 'array':
          constrain('items', value, function (a, e) {
            for (var i = 0, l = a.length; i < l; i++) {
              validateProperty(object, a[i], property, e, options, errors, i, a);
            }
            return true;
          });
          constrain('minItems', value, function (a, e) { return a.length >= e });
          constrain('maxItems', value, function (a, e) { return a.length <= e });
          constrain('uniqueItems', value, function (a) {
            var h = {};

            for (var i = 0, l = a.length; i < l; i++) {
              var key = JSON.stringify(a[i]);
              if (h[key]) return false;
              h[key] = true;
            }

            return true;
          });
          break;
        case 'object':
          // Recursive validation
          if (schema.properties || schema.patternProperties || schema.additionalProperties) {
            validateObject(value, schema, options, errors);
          }
          break;
      }

      //schema filtering
      if (schema.filter && errorsCountBeforeCheckType == errors.length) {
        if (type != 'array' && type != 'object') {
          var filters = isArray(schema.filter) ? schema.filter : [schema.filter];
          for (var i = 0, l = filters.length; i < l; i++) {
            var filter = null;
            if (isString(filters[i])) {
              if (filters[i] in validate.filters) {
                filter = validate.filters[filters[i]];
              } else {
                return error('filter', property, filters[i], schema, errors, 'unknown filter: %{actual}');
              }
            } else if (isFunction(filters[i])) {
              filter = filters[i];
            } else {
              return error('filter', property, typeof filters[i], schema, errors, 'bad filter type: %{actual}');
            }
            try {
              // filter value for simple value or for an array item
              if (indexInArray == null) {
                object[property] = filter(object[property]);  
              } else {
                object[property][indexInArray] = filter(object[property][indexInArray]);
              }
            } catch(err) {
              return error('filter', property, err, schema, errors, 'error during filtering: %{actual}');
            }
          }
        } else {
          return error('filter', property, type, schema, errors, 'bad property type for filtering: %{actual}');
        }
      }
    });
  }
854
def _safe_match_date_and_datetime(graphql_type, expected_python_types, value):
    """"""
    # Python datetime.datetime is a subclass of datetime.date,
    # but in this case, the two are not interchangeable.
    # Rather than using isinstance, we will therefore check for exact type equality.
    value_type = type(value)
    if not any(value_type == x for x in expected_python_types):
        raise GraphQLInvalidArgumentError(u'Expected value to be exactly one of '
                                          u'python types {}, but was {}: '
                                          u'{}'.format(expected_python_types, value_type, value))

    # The serialize() method of GraphQLDate and GraphQLDateTime produces the correct
    # ISO-8601 format that MATCH expects. We then simply represent it as a regular string.
    try:
        serialized_value = graphql_type.serialize(value)
    except ValueError as e:
        raise GraphQLInvalidArgumentError(e)

    return _safe_match_string(serialized_value)
539801
def valid_date(key, config_date):
    
    key_date = "/".join(key.split("/")[4:7])
    return parse_date(key_date) > parse_date(config_date)