Field Converters
 Handles parsing datetimes from a string
340428
def parse_date(sdate)
    # Assume this is UTC if no timezone is specified
    sdate = sdate + "Z" unless sdate.match(/Z|([+|-]\d{2}:\d{2})$/)

    # This is to handle older versions of Ruby (e.g. ruby 1.8.7 (2010-12-23 patchlevel 330) [i386-mingw32])
    # See http://makandra.com/notes/1017-maximum-representable-value-for-a-ruby-time-object
    # In recent versions of Ruby, Time has a much larger range
    begin
      result = Time.parse(sdate)
    rescue ArgumentError
      result = DateTime.parse(sdate)
    end

    return result
  end
988125
def _parse_date(self, date_string):
        """"""
        date = datetime.strptime(date_string, self._DATE_FORMAT)
        self.date = self._TZ.localize(date).astimezone(pytz.UTC)
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))
1252966
def _parse_date(string: str) -> datetime.date:
    
    return datetime.datetime.strptime(string, '%Y-%m-%d').date()
858835
function parse(value, field, options) {
  options = options || {};
  var parsed = utils.standardizeInput(value);

  // Integer
  if (field.type.key === "BOOLEAN") {
    parsed = utils.toBoolean(parsed);
  }
  else if (field.type.key === "INTEGER") {
    parsed = utils.toInteger(parsed);
  }
  else if (field.type.key === "FLOAT") {
    parsed = utils.toFloat(parsed);
  }
  else if (field.type.key === "DATEONLY") {
    parsed = utils.toDate(parsed, options.dateFormat);
  }
  else if (field.type.key === "DATE") {
    parsed = utils.toDateTime(parsed, options.datetimeFormat);
  }
  else if (field.type.key === "STRING") {
    parsed = utils.toString(parsed);
  }

  return parsed;
}
262857
def parse_datetime(datetimestring):
    '''
    
    '''
    try:
        datestring, timestring = re.split('T| ', datetimestring)
    except ValueError:
        raise isodate.ISO8601Error(
            "ISO 8601 time designator 'T' or ' '  missing. Unable to parse "
            "datetime string %r" % datetimestring
        )
    tmpdate = isodate.parse_date(datestring)
    tmptime = isodate.parse_time(timestring)
    return datetime.datetime.combine(tmpdate, tmptime)
1371240
def parse_date(string, formation=None):
        
        if formation:
            _stamp = datetime.datetime.strptime(string, formation).date()
            return _stamp

        _string = string.replace('.', '-').replace('/', '-')
        if '-' in _string:
            if len(_string.split('-')[0]) > 3 or len(_string.split('-')[2]) > 3:
                try:
                    _stamp = datetime.datetime.strptime(_string, '%Y-%m-%d').date()
                except ValueError:
                    try:
                        _stamp = datetime.datetime.strptime(_string, '%m-%d-%Y').date()
                    except ValueError:
                        _stamp = datetime.datetime.strptime(_string, '%d-%m-%Y').date()
            else:
                try:
                    _stamp = datetime.datetime.strptime(_string, '%y-%m-%d').date()
                except ValueError:
                    try:
                        _stamp = datetime.datetime.strptime(_string, '%m-%d-%y').date()
                    except ValueError:
                        _stamp = datetime.datetime.strptime(_string, '%d-%m-%y').date()
        else:
            if len(_string) > 6:
                try:
                    _stamp = datetime.datetime.strptime(_string, '%Y%m%d').date()
                except ValueError:
                    _stamp = datetime.datetime.strptime(_string, '%m%d%Y').date()
            elif len(_string) <= 6:
                try:
                    _stamp = datetime.datetime.strptime(_string, '%y%m%d').date()
                except ValueError:
                    _stamp = datetime.datetime.strptime(_string, '%m%d%y').date()
            else:
                raise CanNotFormatError
        return _stamp
1069599
def __deserialize_date(self, string):
        
        try:
            from dateutil.parser import parse
            return parse(string).date()
        except ImportError:
            return string
        except ValueError:
            raise ApiException(
                status=0,
                reason="Failed to parse `{0}` into a date object".format(string)
            )
870324
def field_datetime_from_json(self, json_val):
        """"""
        if type(json_val) == int:
            seconds = int(json_val)
            dt = datetime.fromtimestamp(seconds, utc)
        elif json_val is None:
            dt = None
        else:
            seconds, microseconds = [int(x) for x in json_val.split('.')]
            dt = datetime.fromtimestamp(seconds, utc)
            dt += timedelta(microseconds=microseconds)
        return dt
685170
def TAF_datetime_to_datetime_object(
    datetime_string             = None,
    datetime_for_year_and_month = None  # e.g. datetime.datetime.utcnow()
    ):

    

    if datetime_string.endswith("24"):

        datetime_string = datetime_string[:-2] + "00"

        tmp = datetime.datetime.strptime(datetime_string, "%d%H") +\
              datetime.timedelta(days = 1)

    else:

        tmp = datetime.datetime.strptime(datetime_string, "%d%H")

    return datetime.datetime(
        datetime_for_year_and_month.year,
        datetime_for_year_and_month.month,
        tmp.day,
        tmp.hour,
        tmp.minute
    )
424628
def to_time_field(formatter):
    
    class TimeConverter(object):

        def __init__(self, formatter):
            self.formatter = formatter

        def __call__(self, value):
            if isinstance(value, string_types):
                value = datetime.strptime(value, self.formatter).time()

            return value

    return TimeConverter(formatter)
80416
def get_date_field(datetimes, field):
    """"""
    return np.array([getattr(date, field) for date in datetimes])
415270
def field_date_to_json(self, day):
        """"""
        if isinstance(day, six.string_types):
            day = parse_date(day)
        return [day.year, day.month, day.day] if day else None
1254793
def cast_datetime_filter(value):
    
    if isinstance(value, str):
        dtime = parse_datetime(value)

    elif isinstance(value, datetime):
        dtime = value
    else:
        raise ValueError('Received value of type {0}'.format(type(value)))

    return dtime.isoformat()
1257095
def parse_dates(d, default='today'):
    

    if default == 'today':
        default = datetime.datetime.today()

    if d is None:
        return default

    elif isinstance(d, _parsed_date_types):
        return d

    elif is_number(d):
        # Treat as milliseconds since 1970
        d = d if isinstance(d, float) else float(d)
        return datetime.datetime.utcfromtimestamp(d)

    elif not isinstance(d, STRING_TYPES):
        if hasattr(d, '__iter__'):
            return [parse_dates(s, default) for s in d]
        else:
            return default

    elif len(d) == 0:
        # Behaves like dateutil.parser < version 2.5
        return default

    else:
        try:
            return parser.parse(d)
        except (AttributeError, ValueError):
            return default
907660
def deserialize(self, raw_data, **kwargs):
        """"""
        super(DateTimeField, self).deserialize(raw_data, **kwargs)
        return self.converted
442132
function parseDateString (dateString) {
  // Pass through when a native object is sent
  if (dateString instanceof Date) {
    return dateString
  }
  // Caste string to date object
  if (String(dateString).match(matchers)) {
    // If looks like a milisecond value cast to number before
    // final casting (Thanks to @msigley)
    if (String(dateString).match(/^[0-9]*$/)) {
      dateString = Number(dateString)
    }
    // Replace dashes to slashes
    if (String(dateString).match(/-/)) {
      dateString = String(dateString).replace(/-/g, '/')
    }
    return new Date(dateString)
  } else {
    throw new Error('Couldn\'t cast `' + dateString +
      '` to a date object.')
  }
}