/* Extract all possible characters from the date format.
969914
function (format) {
		var chars = '';
		var literal = false;
		// Check whether a format character is doubled
		var lookAhead = function(match) {
			var matches = (iFormat + 1 < format.length && format.charAt(iFormat + 1) == match);
			if (matches)
				iFormat++;
			return matches;
		};
		for (var iFormat = 0; iFormat < format.length; iFormat++)
			if (literal)
				if (format.charAt(iFormat) == "'" && !lookAhead("'"))
					literal = false;
				else
					chars += format.charAt(iFormat);
			else
				switch (format.charAt(iFormat)) {
					case 'd': case 'm': case 'y': case '@':
						chars += '0123456789';
						break;
					case 'D': case 'M':
						return null; // Accept anything
					case "'":
						if (lookAhead("'"))
							chars += "'";
						else
							literal = true;
						break;
					default:
						chars += format.charAt(iFormat);
				}
		return chars;
	}
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);
    }
871719
public static String getFormattedObect(String date)
    {
        return date != null ? getDateByPattern(date).toString() : null;
    }
98424
public static String toDateString(final Date date) {
        SimpleDateFormat df = RFC1123_PATTERN_FORMAT.get();
        //we always need to set the time zone
        //because date format is stupid, and calling parse() can mutate the timezone
        //see UNDERTOW-458
        df.setTimeZone(GMT_ZONE);
        return df.format(date);
    }
1009533
public static String format(Date date, String format) {
		if (null == date || StrUtil.isBlank(format)) {
			return null;
		}
		return format(date, FastDateFormat.getInstance(format));
	}
867536
public boolean select(String date, String format, Locale locale) {
        SimpleDateFormat inDateFormat = new SimpleDateFormat(format, locale);
        SimpleDateFormat outDateForm = new SimpleDateFormat("dd/MMM/yyyy", locale);
        try {
            Date fromDate = inDateFormat.parse(date);
            date = outDateForm.format(fromDate);
        } catch (ParseException e) {
            LOGGER.error("ParseException: {}", e);
        }
        String[] dates = date.split("/");
        return setDate(Integer.parseInt(dates[0]) + "", dates[1], dates[2]);
    }
1075328
protected String parseDateToString(Date date, Context context, Arguments args)
    {
        final DateFormat dateFormat = parseFormatter(context, args);
        dateFormat.setTimeZone(context.get(Contexts.TIMEZONE));
        return dateFormat.format(date);
    }
808878
public static Date getDateByPattern(String date)
    {
        if (StringUtils.isNumeric(date))
        {
            return new Date(Long.parseLong(date));
        }

        for (String p : patterns)
        {
            try
            {
                DateFormat formatter = new SimpleDateFormat(p);
                Date dt = formatter.parse(date);
                return dt;
            }
            catch (IllegalArgumentException iae)
            {
                // Do nothing.
                // move to next pattern.
            }
            catch (ParseException e)
            {
                // Do nothing.
                // move to next pattern.
            }

        }
        log.error("Required Date format is not supported!" + date);
        throw new PropertyAccessException("Required Date format is not supported!" + date);
    }
13839
public static String dateToString(Date date, String pattern) {

        if (date == null) {

            return null;
        }

        try {

            SimpleDateFormat sfDate = new SimpleDateFormat(pattern);
            sfDate.setLenient(false);

            return sfDate.format(date);
        } catch (Exception e) {

            return null;
        }
    }
1293014
public static String toDateString(final Date date) {

        String result;
        if (date == null) {
            result = "";
        } else {
            result = Z_DATE_FORMAT.format(date);
        }
        return result;
    }
958205
private static String formatDate(Date date) {

        String dateStr = dateFormat.format(date);
        // insert colon into timezone
        return dateStr.substring(0, 22) + ":" + dateStr.substring(22);
    }
425431
def parse_date(self, value):
        """"""
        res = dateparser.parse(
            value, date_formats=self.options['date_formats'], languages=self.options['languages']
        )
        logger.debug("result of date parsing=%s", res)
        return res
1046623
def split_date(value):
    
    if not is_valid_date(value):
        return ('', '', '')

    splited = value.split('-')

    try:
        year = splited[0]
    except IndexError:
        year = ''

    try:
        month = splited[1]
    except IndexError:
        month = ''

    try:
        day = splited[2]
    except IndexError:
        day = ''

    return (year, month, day)
862725
function _is_format_valid($date)
    {

        // the format we expect the date to be
        // escape characters that would make sense as regular expression
        $format = preg_quote($this->attributes['format']);

        // parse the format and extract the characters that define the format
        // (note that we're also capturing the offsets)
        preg_match_all('/[dDjlNSwFmMnYyGHghaAisU]{1}/', $format, $matches, PREG_OFFSET_CAPTURE);

        $regexp = array();

        // iterate through the found characters
        // and create the regular expression that we will use to see if the entered date is ok
        foreach ($matches[0] as $match) {

            switch ($match[0]) {

                // day of the month, 2 digits with leading zeros, 01 to 31
                case 'd': $regexp[] = '0[1-9]|[12][0-9]|3[01]'; break;

                // a textual representation of a day, three letters, mon through sun
                case 'D': $regexp[] = '[a-z]{3}'; break;

                // day of the month without leading zeros, 1 to 31
                case 'j': $regexp[] = '[1-9]|[12][0-9]|3[01]'; break;

                // a full textual representation of the day of the week, sunday through saturday
                case 'l': $regexp[] = '[a-z]+'; break;

                // ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0), 1 (for Monday) through 7 (for Sunday)
                case 'N': $regexp[] = '[1-7]'; break;

                // english ordinal suffix for the day of the month, 2 characters: st, nd, rd or th. works well with j
                case 'S': $regexp[] = 'st|nd|rd|th'; break;

                // numeric representation of the day of the week, 0 (for sunday) through 6 (for saturday)
                case 'w': $regexp[] = '[0-6]'; break;

                // a full textual representation of a month, such as january or march
                case 'F': $regexp[] = '[a-z]+'; break;

                // numeric representation of a month, with leading zeros, 01 through 12
                case 'm': $regexp[] = '0[1-9]|1[012]+'; break;

                // a short textual representation of a month, three letters, jan through dec
                case 'M': $regexp[] = '[a-z]{3}'; break;

                // numeric representation of a month, without leading zeros, 1 through 12
                case 'n': $regexp[] = '[1-9]|1[012]'; break;

                // a full numeric representation of a year, 4 digits examples: 1999 or 2003
                case 'Y': $regexp[] = '[0-9]{4}'; break;

                // a two digit representation of a year examples: 99 or 03
                case 'y': $regexp[] = '[0-9]{2}'; break;

                // 24-hour format of an hour without leading zeros, 0 through 23
				case 'G': $regexp[] = '[0-9]|1[0-9]|2[0-3]'; break;

                // 24-hour format of an hour with leading zeros, 00 through 23
				case 'H': $regexp[] = '0[0-9]|1[0-9]|2[0-3]'; break;

                // 12-hour format of an hour without leading zeros, 1 through 12
				case 'g': $regexp[] = '[0-9]|1[0-2]'; break;

                // 12-hour format of an hour with leading zeros, 01 through 12
				case 'h': $regexp[] = '0[0-9]|1[0-2]'; break;

                // lowercase ante meridiem and post meridiem am or pm
				case 'a':
				case 'A': $regexp[] = '(am|pm)'; break;

                // minutes with leading zeros, 00 to 59
				case 'i': $regexp[] = '[0-5][0-9]'; break;

                // seconds, with leading zeros 00 through 59
				case 's': $regexp[] = '[0-5][0-9]'; break;

            }

        }

        // if format is defined
        if (!empty($regexp)) {

            // we will replace every format-related character in the format expression with
            // the appropriate regular expression in order to see that valid data was entered
            // as required by the character
            // we are replacing from finish to start so that we don't mess up the offsets
            // therefore, we need to reverse the array first
            $matches[0] = array_reverse($matches[0]);

            // how many characters to replace
            $chars = count($matches[0]);

            // iterate through the characters
            foreach ($matches[0] as $index => $char)

                // and replace them with the appropriate regular expression
                $format = substr_replace($format, '(' . $regexp[$chars - $index - 1] . ')', $matches[0][$index][1], 1);

            // the final regular expression to math the date against
            $format = '/^' . str_replace('/', '\/', $format) . '$/i';

            // if entered value seems to be ok
            if (preg_match($format, $date, $segments)) {

                $original_day = $original_month = $original_year = 0;
                $original_hour = $original_minute = $original_second = $original_format = -1;

                // english names for days and months
                $english_days   = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
                $english_months = array('January','February','March','April','May','June','July','August','September','October','November','December');

                // reverse the characters in the format (remember that we reversed them above)
                $matches[0] = array_reverse($matches[0]);

                $valid = true;

                // iterate through the characters in the format
                // to see if years, months, days, hours, minutes and seconds are correct
                // i.e. if for month we entered "abc" it would pass our regular expression but
                // now we will check if the three letter text is an actual month
                foreach ($matches[0] as $index => $match) {

                    switch ($match[0]) {

                        // numeric representation of a month, with leading zeros, 01 through 12
                        case 'm':
                        // numeric representation of a month, without leading zeros, 1 through 12
                        case 'n':

                            $original_month = (int)($segments[$index + 1] - 1);

                            break;

                        // day of the month, 2 digits with leading zeros, 01 to 31
                        case 'd':
                        // day of the month without leading zeros, 1 to 31
                        case 'j':

                            $original_day = (int)($segments[$index + 1]);

                            break;

                        // a textual representation of a day, three letters, mon through sun
                        case 'D':
                        // a full textual representation of the day of the week, sunday through saturday
                        case 'l':
                        // a full textual representation of a month, such as january or march
                        case 'F':
                        // a short textual representation of a month, three letters, jan through dec
                        case 'M':

                            // by default, we assume that the text is invalid
                            $valid = false;

                            // iterate through the values in the language file
                            foreach ($this->form_properties['language'][($match[0] == 'F' || $match[0] == 'M' ? 'months' : 'days')] as $key => $value) {

                                // if value matches the value from the language file
                                if (strtolower($segments[$index + 1]) == strtolower(substr($value, 0, ($match[0] == 'D' || $match[0] == 'M' ? 3 : strlen($value))))) {

                                    // replace with the english value
                                    // this is because later on we'll run strtotime of the entered value and strtotime parses english dates
                                    switch ($match[0]) {
                                        case 'D': $segments[$index + 1] = substr($english_days[$key], 0, 3); break;
                                        case 'l': $segments[$index + 1] = $english_days[$key]; break;
                                        case 'F': $segments[$index + 1] = $english_months[$key]; $original_month = $key; break;
                                        case 'M': $segments[$index + 1] = substr($english_months[$key], 0, 3); $original_month = $key; break;
                                    }

                                    // flag the value as valid
                                    $valid = true;

                                    // don't look further
                                    break;

                                }

                            }

                            // if an invalid was found don't look any further
                            if (!$valid) break 2;

                            break;

                        // a full numeric representation of a year, 4 digits examples: 1999 or 2003
                        case 'Y':

                            $original_year = (int)($segments[$index + 1]);

                            break;

                        // a two digit representation of a year examples: 99 or 03
                        case 'y':

                            $original_year = (int)('19' . $segments[$index + 1]);

                            break;

                        // 24-hour format of an hour without leading zeros, 0 through 23
        				case 'G':
                        // 24-hour format of an hour with leading zeros, 00 through 23
        				case 'H':
                        // 12-hour format of an hour without leading zeros, 1 through 12
        				case 'g':
                        // 12-hour format of an hour with leading zeros, 01 through 12
        				case 'h':

                            $original_hour = (int)($segments[$index + 1]);

                            break;

                        // lowercase ante meridiem and post meridiem am or pm
        				case 'a':
        				case 'A':

                            $original_format = $segments[$index + 1];

                            break;

                        // minutes with leading zeros, 00 to 59
        				case 'i':

                            $original_minute = (int)($segments[$index + 1]);

                            break;

                        // seconds, with leading zeros 00 through 59
        				case 's':

                            $original_second = (int)($segments[$index + 1]);

                            break;

                    }

                }

                // if entered value seems valid
                if ($valid) {

                    // if date format does not include day, make day = 1
                    if ($original_day == 0) $original_day = 1;

                    // if date format does not include month, make month = 0 (January)
                    if ($original_month == 0) $original_month = 0;

                    // if date format does not include year, use the current year
                    if ($original_year == 0) $original_year = date('Y');

                    // if date is still valid after we process it with strtotime
                    // (we do this because, so far, a date like "Feb 31 2010" would be valid
                    // but strtotime would turn that to "Mar 03 2010")
                    if (

                        $english_months[$original_month] . ' ' . str_pad($original_day, 2, '0', STR_PAD_LEFT) . ', ' . $original_year ==
                        date('F d, Y', strtotime($english_months[$original_month] . ' ' . $original_day . ', ' . $original_year))

                    ) {

                        // make sure we also return the date as YYYY-MM-DD so that it can be
                        // easily used with a database or with PHP's strtotime function
                        $this->attributes['date'] = $original_year . '-' . str_pad($original_month + 1, 2, '0', STR_PAD_LEFT) . '-' . str_pad($original_day, 2, '0', STR_PAD_LEFT);

                        return strtotime($original_year . '-' . ($original_month + 1) . '-' . $original_day);

                    }

                }

            }

        }

        // if script gets this far, return FALSE as something must've been wrong
        return false;

    }
384644
function(format, value) {
      var date = helpers.date.parse(value);

      if(date === false || date === undefined) return false;

      var day = date.getDate().toString().replace(/(?=(^\d{1}$))/g, "0");
      var month = (date.getMonth() + 1).toString().replace(/(?=(^\d{1}$))/g, "0");

      var formatDate = format
         .replace(/dd/gi, day)
         .replace(/mm/gi, month)
         .replace(/yyyy/gi, date.getFullYear());

      return formatDate;
   }
1234170
function encodeDate(date) {
	if (!(date instanceof Date)) throw new Error('Value not Date: ' + date)
	return (date.getUTCFullYear() * monthsPerYear + date.getUTCMonth()) - yearMonthZero
}
177062
@Override
    public String format(Date date, String mask) {
	return format(date, mask, null);
    }