Search in sources :

Example 11 with TimeFormatException

use of android.util.TimeFormatException in project android_frameworks_base by ResurrectionRemix.

the class TimeTest method testParse33390.

@SmallTest
public void testParse33390() throws Exception {
    Time t = new Time(Time.TIMEZONE_UTC);
    t.parse3339("1980-05-23");
    if (!t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23) {
        fail("Did not parse all-day date correctly");
    }
    t.parse3339("1980-05-23T09:50:50");
    if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 || t.hour != 9 || t.minute != 50 || t.second != 50 || t.gmtoff != 0) {
        fail("Did not parse timezone-offset-less date correctly");
    }
    t.parse3339("1980-05-23T09:50:50Z");
    if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 || t.hour != 9 || t.minute != 50 || t.second != 50 || t.gmtoff != 0) {
        fail("Did not parse UTC date correctly");
    }
    t.parse3339("1980-05-23T09:50:50.0Z");
    if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 || t.hour != 9 || t.minute != 50 || t.second != 50 || t.gmtoff != 0) {
        fail("Did not parse UTC date correctly");
    }
    t.parse3339("1980-05-23T09:50:50.12Z");
    if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 || t.hour != 9 || t.minute != 50 || t.second != 50 || t.gmtoff != 0) {
        fail("Did not parse UTC date correctly");
    }
    t.parse3339("1980-05-23T09:50:50.123Z");
    if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 || t.hour != 9 || t.minute != 50 || t.second != 50 || t.gmtoff != 0) {
        fail("Did not parse UTC date correctly");
    }
    // The time should be normalized to UTC
    t.parse3339("1980-05-23T09:50:50-01:05");
    if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 || t.hour != 10 || t.minute != 55 || t.second != 50 || t.gmtoff != 0) {
        fail("Did not parse timezone-offset date correctly");
    }
    // The time should be normalized to UTC
    t.parse3339("1980-05-23T09:50:50.123-01:05");
    if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 || t.hour != 10 || t.minute != 55 || t.second != 50 || t.gmtoff != 0) {
        fail("Did not parse timezone-offset date correctly");
    }
    try {
        t.parse3339("1980");
        fail("Did not throw error on truncated input length");
    } catch (TimeFormatException e) {
    // Successful
    }
    try {
        t.parse3339("1980-05-23T09:50:50.123+");
        fail("Did not throw error on truncated timezone offset");
    } catch (TimeFormatException e1) {
    // Successful
    }
    try {
        t.parse3339("1980-05-23T09:50:50.123+05:0");
        fail("Did not throw error on truncated timezone offset");
    } catch (TimeFormatException e1) {
    // Successful
    }
}
Also used : Time(android.text.format.Time) TimeFormatException(android.util.TimeFormatException) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 12 with TimeFormatException

use of android.util.TimeFormatException in project android_frameworks_base by crdroidandroid.

the class TimeTest method testParse33390.

@SmallTest
public void testParse33390() throws Exception {
    Time t = new Time(Time.TIMEZONE_UTC);
    t.parse3339("1980-05-23");
    if (!t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23) {
        fail("Did not parse all-day date correctly");
    }
    t.parse3339("1980-05-23T09:50:50");
    if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 || t.hour != 9 || t.minute != 50 || t.second != 50 || t.gmtoff != 0) {
        fail("Did not parse timezone-offset-less date correctly");
    }
    t.parse3339("1980-05-23T09:50:50Z");
    if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 || t.hour != 9 || t.minute != 50 || t.second != 50 || t.gmtoff != 0) {
        fail("Did not parse UTC date correctly");
    }
    t.parse3339("1980-05-23T09:50:50.0Z");
    if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 || t.hour != 9 || t.minute != 50 || t.second != 50 || t.gmtoff != 0) {
        fail("Did not parse UTC date correctly");
    }
    t.parse3339("1980-05-23T09:50:50.12Z");
    if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 || t.hour != 9 || t.minute != 50 || t.second != 50 || t.gmtoff != 0) {
        fail("Did not parse UTC date correctly");
    }
    t.parse3339("1980-05-23T09:50:50.123Z");
    if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 || t.hour != 9 || t.minute != 50 || t.second != 50 || t.gmtoff != 0) {
        fail("Did not parse UTC date correctly");
    }
    // The time should be normalized to UTC
    t.parse3339("1980-05-23T09:50:50-01:05");
    if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 || t.hour != 10 || t.minute != 55 || t.second != 50 || t.gmtoff != 0) {
        fail("Did not parse timezone-offset date correctly");
    }
    // The time should be normalized to UTC
    t.parse3339("1980-05-23T09:50:50.123-01:05");
    if (t.allDay || t.year != 1980 || t.month != 04 || t.monthDay != 23 || t.hour != 10 || t.minute != 55 || t.second != 50 || t.gmtoff != 0) {
        fail("Did not parse timezone-offset date correctly");
    }
    try {
        t.parse3339("1980");
        fail("Did not throw error on truncated input length");
    } catch (TimeFormatException e) {
    // Successful
    }
    try {
        t.parse3339("1980-05-23T09:50:50.123+");
        fail("Did not throw error on truncated timezone offset");
    } catch (TimeFormatException e1) {
    // Successful
    }
    try {
        t.parse3339("1980-05-23T09:50:50.123+05:0");
        fail("Did not throw error on truncated timezone offset");
    } catch (TimeFormatException e1) {
    // Successful
    }
}
Also used : Time(android.text.format.Time) TimeFormatException(android.util.TimeFormatException) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 13 with TimeFormatException

use of android.util.TimeFormatException in project 360-Engine-for-Android by 360.

the class VCardHelper method getDate.

/**
 * Get Time item from supplied String.
 *
 * @param val String containing time information.
 * @return Time item generated from supplied String.
 */
protected static Time getDate(String val) {
    if (val == null) {
        return null;
    }
    List<Item> itemList = new ArrayList<Item>();
    getVCardList(val, itemList);
    ListIterator<Item> it = itemList.listIterator();
    String dateString = nextFullItem(it);
    dateString = dateString.replace("-", "");
    Time time = new Time();
    try {
        time.parse(dateString);
    } catch (TimeFormatException e) {
        return null;
    }
    return time;
}
Also used : ArrayList(java.util.ArrayList) Time(android.text.format.Time) TimeFormatException(android.util.TimeFormatException)

Example 14 with TimeFormatException

use of android.util.TimeFormatException in project GTFSOffline by wbrenna.

the class ServiceCalendar method process_db.

// Do the actual work of the getDays() call, but it makes
// sure we close the cursor on exit.
private String process_db(String service_id, String date, boolean limit, Cursor csr) {
    if (!csr.moveToFirst()) {
        return null;
    }
    // Make sure it's in a current schedule period
    final String start = csr.getString(csr.getColumnIndex("start_date"));
    final String end = csr.getString(csr.getColumnIndex("end_date"));
    if (date.compareTo(start) < 0 || date.compareTo(end) > 0) {
        // basically, need to watch RSS to get the right datasets.
        return null;
    }
    // If we're not limiting the display, return what we have
    if (!limit) {
        return getDays(csr);
    }
    // Check for exceptions
    final String[] selectargs = { date, service_id };
    final Cursor exp = mDB.rawQuery(mDBQueryDate, selectargs);
    if (exp.moveToFirst()) {
        final int exception = exp.getInt(exp.getColumnIndex("exception_type"));
        exp.close();
        if (exception == 2) {
            return null;
        }
        if (exception == 1) {
            // service added for this day
            return getDays(csr);
        }
        Log.e(TAG, "bogus exception type " + exception + " for service " + service_id + "!");
        return null;
    } else {
        exp.close();
    }
    // Check if the bus runs on the given day of the week.
    final Time t = new Time();
    try {
        t.parse(date);
        t.normalize(false);
    } catch (final TimeFormatException e) {
        Log.e(TAG, "got bogus date \"" + date + "\"");
        return null;
    }
    // 0--6
    final int weekday = t.weekDay;
    if (csr.getInt(csr.getColumnIndex(mWeekDays[weekday])) == 1) {
        return getDays(csr);
    }
    // doesn't run on given date.
    return null;
}
Also used : Time(android.text.format.Time) Cursor(android.database.Cursor) TimeFormatException(android.util.TimeFormatException)

Aggregations

Time (android.text.format.Time)14 TimeFormatException (android.util.TimeFormatException)14 SmallTest (android.test.suitebuilder.annotation.SmallTest)6 Cursor (android.database.Cursor)1 ArrayList (java.util.ArrayList)1