Java 类android.util.TimeFormatException 实例源码

项目:CheckSmarter    文件:EventRecurrence.java   
@Override
public int parsePart(String value, EventRecurrence er) {
    if (VALIDATE_UNTIL) {
        try {
            // Parse the time to validate it.  The result isn't retained.
            Time until = new Time();
            until.parse(value);
        } catch (TimeFormatException tfe) {
            throw new InvalidFormatException("Invalid UNTIL value: " + value);
        }
    }
    er.until = value;
    return PARSED_UNTIL;
}
项目:SublimePicker    文件:EventRecurrence.java   
@Override
public int parsePart(String value, EventRecurrence er) {
    if (VALIDATE_UNTIL) {
        try {
            // Parse the time to validate it.  The result isn't retained.
            Time until = new Time();
            until.parse(value);
        } catch (TimeFormatException tfe) {
            throw new InvalidFormatException("Invalid UNTIL value: " + value);
        }
    }
    er.until = value;
    return PARSED_UNTIL;
}
项目:sms-ticket    文件:FormatUtil.java   
public static Time timeFrom3339(String s3339) {
    final Time time = new Time();
    if (TextUtils.isEmpty(s3339)) {
        return time;
    }
    try {
        time.parse3339(s3339);
    } catch (TimeFormatException e) {
        return time;
    }
    time.switchTimezone(Time.getCurrentTimezone());
    return time;
}
项目:sms-ticket    文件:FormatUtil.java   
public static Time timeFrom3339(String s3339) {
    final android.text.format.Time time = new Time();
    if (TextUtils.isEmpty(s3339)) {
        return time;
    }
    try {
        time.parse3339(s3339);
    } catch (TimeFormatException e) {
        return time;
    }
    time.switchTimezone(android.text.format.Time.getCurrentTimezone());
    return time;
}
项目:Android-RecurrencePicker    文件:EventRecurrence.java   
@Override
public int parsePart(String value, EventRecurrence er) {
    if (VALIDATE_UNTIL) {
        try {
            // Parse the time to validate it.  The result isn't retained.
            Time until = new Time();
            until.parse(value);
        } catch (TimeFormatException tfe) {
            throw new InvalidFormatException("Invalid UNTIL value: " + value);
        }
    }
    er.until = value;
    return PARSED_UNTIL;
}
项目:Cthulhator    文件:EventRecurrence.java   
@Override
public int parsePart(String value, EventRecurrence er) {
    if (VALIDATE_UNTIL) {
        try {
            // Parse the time to validate it.  The result isn't retained.
            Time until = new Time();
            until.parse(value);
        } catch (TimeFormatException tfe) {
            throw new InvalidFormatException("Invalid UNTIL value: " + value);
        }
    }
    er.until = value;
    return PARSED_UNTIL;
}
项目:Calendar_lunar    文件:RecurrenceSet.java   
/**
 * Parses the provided RDATE or EXDATE string into an array of longs
 * representing each date/time in the recurrence.
 * @param recurrence The recurrence to be parsed.
 * @return The list of date/times.
 */
public static long[] parseRecurrenceDates(String recurrence)
        throws EventRecurrence.InvalidFormatException{
    // TODO: use "local" time as the default.  will need to handle times
    // that end in "z" (UTC time) explicitly at that point.
    String tz = Time.TIMEZONE_UTC;
    int tzidx = recurrence.indexOf(";");
    if (tzidx != -1) {
        tz = recurrence.substring(0, tzidx);
        recurrence = recurrence.substring(tzidx + 1);
    }
    Time time = new Time(tz);
    String[] rawDates = recurrence.split(",");
    int n = rawDates.length;
    long[] dates = new long[n];
    for (int i = 0; i<n; ++i) {
        // The timezone is updated to UTC if the time string specified 'Z'.
        try {
            time.parse(rawDates[i]);
        } catch (TimeFormatException e) {
            throw new EventRecurrence.InvalidFormatException(
                    "TimeFormatException thrown when parsing time " + rawDates[i]
                            + " in recurrence " + recurrence);

        }
        dates[i] = time.toMillis(false /* use isDst */);
        time.timezone = tz;
    }
    return dates;
}
项目:Calendar_lunar    文件:EventRecurrence.java   
@Override public int parsePart(String value, EventRecurrence er) {
    if (VALIDATE_UNTIL) {
        try {
            // Parse the time to validate it.  The result isn't retained.
            Time until = new Time();
            until.parse(value);
        } catch (TimeFormatException tfe) {
            throw new InvalidFormatException("Invalid UNTIL value: " + value);
        }
    }
    er.until = value;
    return PARSED_UNTIL;
}
项目:Yarrn    文件:Report.java   
protected Time parseCrashReportTimestamp(String crashTime) {
    Time parsedTime = new Time();

    try {
        parsedTime.parse3339(crashTime);
    } catch (TimeFormatException e) {
        ACRA.log.w(getTag(), String.format("Failed to decode timestamp %s", crashTime), e);
    }

    return parsedTime;
}
项目:acra-sentry-sender    文件:Report.java   
protected Time parseCrashReportTimestamp(String crashTime) {
    Time parsedTime = new Time();

    try {
        parsedTime.parse3339(crashTime);
    } catch (TimeFormatException e) {
        ACRA.log.w(getTag(), String.format("Failed to decode timestamp %s", crashTime), e);
    }

    return parsedTime;
}
项目:FullRobolectricTestSample    文件:ShadowTime.java   
private void throwTimeFormatException() {
  throw constructor().withParameterTypes(String.class).in(TimeFormatException.class)
      .newInstance("fail");
}
项目:FullRobolectricTestSample    文件:TimeTest.java   
@Test(expected = TimeFormatException.class)
public void shouldThrowTimeFormatException() throws Exception {
  Time t = new Time();
  t.parse("BLARGH");
}
项目:tomdroid    文件:NoteHandler.java   
@Override
public void endElement(String uri, String localName, String name)
        throws SAXException, TimeFormatException {

    if (localName.equals(TITLE)) {
        inTitleTag = false;
        note.setTitle(title.toString());
    } 
    else if (localName.equals(LAST_CHANGE_DATE)) {
        inLastChangeDateTag = false;
        note.setLastChangeDate(lastChangeDate.toString());
    }
    else if (localName.equals(NOTE_CONTENT)) {
        inNoteContentTag = false;
        note.setXmlContent(noteContent.toString());
    }
    else if (localName.equals(CREATE_DATE)) {
        inCreateDateTag = false;
        if(createDate.length() > 0)
            note.setCreateDate(createDate.toString());
    }
    else if (localName.equals(NOTE_C)) {
        inCursorTag = false;
        if(cursorPos.length() > 0)
            note.cursorPos = Integer.parseInt(cursorPos.toString());
    }
    else if (localName.equals(NOTE_W)) {
        inWidthTag = false;
        if(width.length() > 0)
            note.width = Integer.parseInt(width.toString());
    }
    else if (localName.equals(NOTE_H)) {
        inHeightTag = false;
        if(height.length() > 0)
            note.height = Integer.parseInt(height.toString());
    }
    else if (localName.equals(NOTE_X)) {
        inXTag = false;
        if(X.length() > 0)
            note.X = Integer.parseInt(X.toString());
    }
    else if (localName.equals(NOTE_Y)) {
        inYTag = false;
        if(Y.length() > 0)
            note.Y = Integer.parseInt(Y.toString());
    }
    else if (localName.equals(NOTE_TAG)) {
        inTagTag = false;
        if(tag.length() > 0)
            note.addTag(tag.toString());
    }
}
项目:Calendar_lunar    文件:RecurrenceSet.java   
/**
 * Populates the database map of values with the appropriate RRULE, RDATE,
 * EXRULE, and EXDATE values extracted from the parsed iCalendar component.
 * @param component The iCalendar component containing the desired
 * recurrence specification.
 * @param values The db values that should be updated.
 * @return true if the component contained the necessary information
 * to specify a recurrence.  The required fields are DTSTART,
 * one of DTEND/DURATION, and one of RRULE/RDATE.  Returns false if
 * there was an error, including if the date is out of range.
 */
public static boolean populateContentValues(ICalendar.Component component,
        ContentValues values) {
    try {
        ICalendar.Property dtstartProperty =
                component.getFirstProperty("DTSTART");
        String dtstart = dtstartProperty.getValue();
        ICalendar.Parameter tzidParam =
                dtstartProperty.getFirstParameter("TZID");
        // NOTE: the timezone may be null, if this is a floating time.
        String tzid = tzidParam == null ? null : tzidParam.value;
        Time start = new Time(tzidParam == null ? Time.TIMEZONE_UTC : tzid);
        boolean inUtc = start.parse(dtstart);
        boolean allDay = start.allDay;

        // We force TimeZone to UTC for "all day recurring events" as the server is sending no
        // TimeZone in DTSTART for them
        if (inUtc || allDay) {
            tzid = Time.TIMEZONE_UTC;
        }

        String duration = computeDuration(start, component);
        String rrule = flattenProperties(component, "RRULE");
        String rdate = extractDates(component.getFirstProperty("RDATE"));
        String exrule = flattenProperties(component, "EXRULE");
        String exdate = extractDates(component.getFirstProperty("EXDATE"));

        if ((TextUtils.isEmpty(dtstart))||
                (TextUtils.isEmpty(duration))||
                ((TextUtils.isEmpty(rrule))&&
                        (TextUtils.isEmpty(rdate)))) {
                if (false) {
                    Log.d(TAG, "Recurrence missing DTSTART, DTEND/DURATION, "
                                + "or RRULE/RDATE: "
                                + component.toString());
                }
                return false;
        }

        if (allDay) {
            start.timezone = Time.TIMEZONE_UTC;
        }
        long millis = start.toMillis(false /* use isDst */);
        values.put(CalendarContract.Events.DTSTART, millis);
        if (millis == -1) {
            if (false) {
                Log.d(TAG, "DTSTART is out of range: " + component.toString());
            }
            return false;
        }

        values.put(CalendarContract.Events.RRULE, rrule);
        values.put(CalendarContract.Events.RDATE, rdate);
        values.put(CalendarContract.Events.EXRULE, exrule);
        values.put(CalendarContract.Events.EXDATE, exdate);
        values.put(CalendarContract.Events.EVENT_TIMEZONE, tzid);
        values.put(CalendarContract.Events.DURATION, duration);
        values.put(CalendarContract.Events.ALL_DAY, allDay ? 1 : 0);
        return true;
    } catch (TimeFormatException e) {
        // Something is wrong with the format of this event
        Log.i(TAG,"Failed to parse event: " + component.toString());
        return false;
    }
}