Parse dates in certain known json fields, if possible.
7414
def __json_date_parse(json_object):
        
        known_date_fields = ["created_at", "week", "day", "expires_at", "scheduled_at"]
        for k, v in json_object.items():
            if k in known_date_fields:
                if v != None:
                    try:
                        if isinstance(v, int):
                            json_object[k] = datetime.datetime.fromtimestamp(v, pytz.utc)
                        else:
                            json_object[k] = dateutil.parser.parse(v)
                    except:
                        raise MastodonAPIError('Encountered invalid date.')
        return json_object
840570
private static Date getShortDateOrNull(JSONObject obj, String field)
			throws JSONException {
        final String dateStr = JsonInput.getStringOrNull(obj, field);
        if (dateStr == null) {
            return null;
        }
        final SimpleDateFormat dateFormat; 
        if (dateStr.length() >= 5 && dateStr.charAt(4) == '/')
            dateFormat = RedmineDateUtils.SHORT_DATE_FORMAT.get();
        else
            dateFormat = RedmineDateUtils.SHORT_DATE_FORMAT_V2.get();

        try {
            return dateFormat.parse(dateStr);
        } catch (ParseException e) {
            throw new JSONException("Bad date " + dateStr);
        }
	}
1134724
def _parse_canonical_datetime(doc, json_options):
    """"""
    dtm = doc["$date"]
    if len(doc) != 1:
        raise TypeError('Bad $date, extra field(s): %s' % (doc,))
    # mongoexport 2.6 and newer
    if isinstance(dtm, string_type):
        # Parse offset
        if dtm[-1] == 'Z':
            dt = dtm[:-1]
            offset = 'Z'
        elif dtm[-3] == ':':
            # (+|-)HH:MM
            dt = dtm[:-6]
            offset = dtm[-6:]
        elif dtm[-5] in ('+', '-'):
            # (+|-)HHMM
            dt = dtm[:-5]
            offset = dtm[-5:]
        elif dtm[-3] in ('+', '-'):
            # (+|-)HH
            dt = dtm[:-3]
            offset = dtm[-3:]
        else:
            dt = dtm
            offset = ''

        # Parse the optional factional seconds portion.
        dot_index = dt.rfind('.')
        microsecond = 0
        if dot_index != -1:
            microsecond = int(float(dt[dot_index:]) * 1000000)
            dt = dt[:dot_index]

        aware = datetime.datetime.strptime(
            dt, "%Y-%m-%dT%H:%M:%S").replace(microsecond=microsecond,
                                             tzinfo=utc)

        if offset and offset != 'Z':
            if len(offset) == 6:
                hours, minutes = offset[1:].split(':')
                secs = (int(hours) * 3600 + int(minutes) * 60)
            elif len(offset) == 5:
                secs = (int(offset[1:3]) * 3600 + int(offset[3:]) * 60)
            elif len(offset) == 3:
                secs = int(offset[1:3]) * 3600
            if offset[0] == "-":
                secs *= -1
            aware = aware - datetime.timedelta(seconds=secs)

        if json_options.tz_aware:
            if json_options.tzinfo:
                aware = aware.astimezone(json_options.tzinfo)
            return aware
        else:
            return aware.replace(tzinfo=None)
    return bson._millis_to_datetime(int(dtm), json_options)
314214
private static Date parse(String date) {
        for (int i = 0; i < fmt.length; i++) {
            try {
                SimpleDateFormat df = new SimpleDateFormat(fmt[i]);
                return df.parse(date);
            } catch (ParseException E) {
                // keep trying
            }
        }
        throw new IllegalArgumentException(date);
    }
289993
def parse_date(s):
    
    if isinstance(s, (datetime.datetime, datetime.date)):
        return s
    try:
        from dateutil.parser import parse
    except ImportError:
        parse = lambda d: datetime.datetime.strptime(d, "%Y-%m-%d")
    return parse(s)
524734
function parseDate(date) {
  if (isDateObject(date)) { // 1
    return date;
  } else if (isValidTimeStamp(date)) { // 2
    return new Date(date);
  } else if (typeof date === 'string' && /^[0-9]{4}([-\.\/][0-9]{2}){2}$/.test(date)) { // 3
    date = date.split(/[-\.\/]/);

    return new Date(date[0], date[1] - 1, date[2]);
  }
  
  return; // ??
}
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
799330
def parse_datetime(s: str) -> datetime.date:
    """"""
    for fmt in (CREATION_DATE_FMT, PUBLISHED_DATE_FMT, PUBLISHED_DATE_FMT_2):
        try:
            dt = datetime.strptime(s, fmt)
        except ValueError:
            pass
        else:
            return dt

    raise ValueError('Incorrect datetime format for {}'.format(s))
953082
def deserialize_date(string):
    
    try:
        from dateutil.parser import parse
        return parse(string).date()
    except ImportError:
        return string
131659
def parse_date(date, default=None):
    
    if date == "":
        if default is not None:
            return default
        else:
            raise Exception("Unknown format for " + date)

    for format_type in ["%Y-%m-%d %H:%M:%S", "%Y-%m-%d %H:%M", "%Y-%m-%d %H", "%Y-%m-%d", "%d/%m/%Y %H:%M:%S", "%d/%m/%Y %H:%M", "%d/%m/%Y %H",
                        "%d/%m/%Y"]:
        try:
            return datetime.strptime(date, format_type)
        except ValueError:
            pass
    raise Exception("Unknown format for " + date)
94390
def _parse_date(self, dt, fmt=None):
        
        try:
            # test if it's not a datelike instance ...
            _dt = utils.Date(dt, fmt=fmt)
        except ValueError:
            # nope, not a datelike instance
            _dt = None
        return _dt
61549
def parse_json_date(value):
    
    if not value:
        return None

    return datetime.datetime.strptime(value, JSON_DATETIME_FORMAT).replace(tzinfo=pytz.UTC)
668178
private SortedSet<Date> readDates(JSONArray array) {

        if (null != array) {
            SortedSet<Date> result = new TreeSet<>();
            for (int i = 0; i < array.length(); i++) {
                try {
                    long l = Long.valueOf(array.getString(i)).longValue();
                    result.add(new Date(l));
                } catch (NumberFormatException | JSONException e) {
                    LOG.error("Could not read date from JSON array.", e);
                }
            }
            return result;
        }
        return new TreeSet<>();
    }
1149172
def read_dates_by_service_ids(
    path: str
) -> Dict[FrozenSet[str], FrozenSet[datetime.date]]:
    """"""
    feed = load_raw_feed(path)
    return _dates_by_service_ids(feed)
996175
function deserializeAllDates(model, json) {
	_.each(json, function (value, name) {
		if ( !_.isDate( value ) && !isBackboneInstance( value ) ) {
			if ( _.isString( value ) && model.isSerializedDate( name, value ) ) {
				json[ name ] = model.deserializeDate( name, value );
			} else if ( !isScalar( value ) && isRecursive( value ) ) {
				deserializeAllDates( model, value );
			}
		}
	});

	return json;
}
897077
def _from_json_object_hook(obj):
    

    for key, value in obj.items():
        # Check for datetime objects
        if isinstance(value, str):
            dt_result = datetime_regex.match(value)
            if dt_result:
                year, month, day, hour, minute, second = map(
                    lambda x: int(x), dt_result.groups())
                obj[key] = datetime.datetime(
                    year, month, day, hour, minute, second)
            else:
                dt_result = uuid_regex.match(value)
                if dt_result:
                    obj[key] = uuid.UUID(value)
    return obj
1114553
def parse_value(cls, itype, value):
        """"""

        parsed = None
        if itype == "date":
            m = RE_DATE.match(value)
            if m:
                year = int(m.group('year'), 10)
                month = int(m.group('month'), 10)
                day = int(m.group('day'), 10)
                if cls.validate_year(year) and cls.validate_month(month) and cls.validate_day(year, month, day):
                    parsed = (year, month, day)
        elif itype == "month":
            m = RE_MONTH.match(value)
            if m:
                year = int(m.group('year'), 10)
                month = int(m.group('month'), 10)
                if cls.validate_year(year) and cls.validate_month(month):
                    parsed = (year, month)
        elif itype == "week":
            m = RE_WEEK.match(value)
            if m:
                year = int(m.group('year'), 10)
                week = int(m.group('week'), 10)
                if cls.validate_year(year) and cls.validate_week(year, week):
                    parsed = (year, week)
        elif itype == "time":
            m = RE_TIME.match(value)
            if m:
                hour = int(m.group('hour'), 10)
                minutes = int(m.group('minutes'), 10)
                if cls.validate_hour(hour) and cls.validate_minutes(minutes):
                    parsed = (hour, minutes)
        elif itype == "datetime-local":
            m = RE_DATETIME.match(value)
            if m:
                year = int(m.group('year'), 10)
                month = int(m.group('month'), 10)
                day = int(m.group('day'), 10)
                hour = int(m.group('hour'), 10)
                minutes = int(m.group('minutes'), 10)
                if (
                    cls.validate_year(year) and cls.validate_month(month) and cls.validate_day(year, month, day) and
                    cls.validate_hour(hour) and cls.validate_minutes(minutes)
                ):
                    parsed = (year, month, day, hour, minutes)
        elif itype in ("number", "range"):
            m = RE_NUM.match(value)
            if m:
                parsed = float(m.group('value'))
        return parsed