FileDocCategorySizeDatePackage
HttpDateTime.javaAPI DocAndroid 1.5 API6326Wed May 06 22:41:56 BST 2009android.webkit

HttpDateTime

public class HttpDateTime extends Object

Fields Summary
private static final String
HTTP_DATE_RFC_REGEXP
private static final String
HTTP_DATE_ANSIC_REGEXP
private static final Pattern
HTTP_DATE_RFC_PATTERN
The compiled version of the HTTP-date regular expressions.
private static final Pattern
HTTP_DATE_ANSIC_PATTERN
Constructors Summary
Methods Summary
private static intgetDate(java.lang.String dateString)

        if (dateString.length() == 2) {
            return (dateString.charAt(0) - '0") * 10
                    + (dateString.charAt(1) - '0");
        } else {
            return (dateString.charAt(0) - '0");
        }
    
private static intgetMonth(java.lang.String monthString)

        int hash = Character.toLowerCase(monthString.charAt(0)) +
                Character.toLowerCase(monthString.charAt(1)) +
                Character.toLowerCase(monthString.charAt(2)) - 3 * 'a";
        switch (hash) {
            case 22:
                return Calendar.JANUARY;
            case 10:
                return Calendar.FEBRUARY;
            case 29:
                return Calendar.MARCH;
            case 32:
                return Calendar.APRIL;
            case 36:
                return Calendar.MAY;
            case 42:
                return Calendar.JUNE;
            case 40:
                return Calendar.JULY;
            case 26:
                return Calendar.AUGUST;
            case 37:
                return Calendar.SEPTEMBER;
            case 35:
                return Calendar.OCTOBER;
            case 48:
                return Calendar.NOVEMBER;
            case 9:
                return Calendar.DECEMBER;
            default:
                throw new IllegalArgumentException();
        }
    
private static android.webkit.HttpDateTime$TimeOfDaygetTime(java.lang.String timeString)

        TimeOfDay time = new TimeOfDay();
        time.hour = (timeString.charAt(0) - '0") * 10
                + (timeString.charAt(1) - '0");
        time.minute = (timeString.charAt(3) - '0") * 10
                + (timeString.charAt(4) - '0");
        time.second = (timeString.charAt(6) - '0") * 10
                + (timeString.charAt(7) - '0");
        return time;
    
private static intgetYear(java.lang.String yearString)

        if (yearString.length() == 2) {
            int year = (yearString.charAt(0) - '0") * 10
                    + (yearString.charAt(1) - '0");
            if (year >= 70) {
                return year + 1900;
            } else {
                return year + 2000;
            }
        } else
            return (yearString.charAt(0) - '0") * 1000
                    + (yearString.charAt(1) - '0") * 100
                    + (yearString.charAt(2) - '0") * 10
                    + (yearString.charAt(3) - '0");
    
public static java.lang.Longparse(java.lang.String timeString)

    

        
              

        int date = 1;
        int month = Calendar.JANUARY;
        int year = 1970;
        TimeOfDay timeOfDay = new TimeOfDay();

        Matcher rfcMatcher = HTTP_DATE_RFC_PATTERN.matcher(timeString);
        if (rfcMatcher.find()) {
            date = getDate(rfcMatcher.group(1));
            month = getMonth(rfcMatcher.group(2));
            year = getYear(rfcMatcher.group(3));
            timeOfDay = getTime(rfcMatcher.group(4));
        } else {
            Matcher ansicMatcher = HTTP_DATE_ANSIC_PATTERN.matcher(timeString);
            if (ansicMatcher.find()) {
                month = getMonth(ansicMatcher.group(1));
                date = getDate(ansicMatcher.group(2));
                timeOfDay = getTime(ansicMatcher.group(3));
                year = getYear(ansicMatcher.group(4));
            } else {
                throw new IllegalArgumentException();
            }
        }

        // FIXME: Y2038 BUG!
        if (year >= 2038) {
            year = 2038;
            month = Calendar.JANUARY;
            date = 1;
        }

        Time time = new Time(Time.TIMEZONE_UTC);
        time.set(timeOfDay.second, timeOfDay.minute, timeOfDay.hour, date,
                month, year);
        return time.toMillis(false /* use isDst */);