Search in sources :

Example 6 with Time

use of android.text.format.Time in project android_frameworks_base by ParanoidAndroid.

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 7 with Time

use of android.text.format.Time in project android_frameworks_base by ParanoidAndroid.

the class TimeTest method testClear0.

@SmallTest
public void testClear0() throws Exception {
    Time t = new Time(Time.TIMEZONE_UTC);
    t.clear(Time.TIMEZONE_UTC);
}
Also used : Time(android.text.format.Time) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 8 with Time

use of android.text.format.Time in project android_frameworks_base by ParanoidAndroid.

the class TimeTest method testMillis0.

@SmallTest
public void testMillis0() throws Exception {
    Time t = new Time(Time.TIMEZONE_UTC);
    t.set(0, 0, 0, 1, 1, 2006);
    long r = t.toMillis(true);
    // System.out.println("r=" + r);
    t.set(1, 0, 0, 1, 1, 2006);
    r = t.toMillis(true);
// System.out.println("r=" + r);
}
Also used : Time(android.text.format.Time) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 9 with Time

use of android.text.format.Time in project android_frameworks_base by ParanoidAndroid.

the class TimeTest method testNormalize0.

@SmallTest
public void testNormalize0() throws Exception {
    Time t = new Time(Time.TIMEZONE_UTC);
    t.parse("20060432T010203");
    t.normalize(false);
//        System.out.println("got: " + t.year + '-'
//                + t.month + '-' + t.monthDay
//                + ' ' + t.hour + ':' + t.minute
//                + ':' + t.second
//                + "( " + t.isDst + ',' + t.gmtoff
//                + ',' + t.weekDay
//                + ',' + t.yearDay + ')');
}
Also used : Time(android.text.format.Time) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 10 with Time

use of android.text.format.Time in project android_frameworks_base by ParanoidAndroid.

the class TimeTest method disableTestGetJulianDay.

@Suppress
public void disableTestGetJulianDay() throws Exception {
    Time time = new Time();
    // same Julian day.
    for (int monthDay = 1; monthDay <= 366; monthDay++) {
        for (int zoneIndex = 0; zoneIndex < mTimeZones.length; zoneIndex++) {
            // We leave the "month" as zero because we are changing the
            // "monthDay" from 1 to 366.  The call to normalize() will
            // then change the "month" (but we don't really care).
            time.set(0, 0, 0, monthDay, 0, 2008);
            time.timezone = mTimeZones[zoneIndex];
            long millis = time.normalize(true);
            if (zoneIndex == 0) {
                Log.i("TimeTest", time.format("%B %d, %Y"));
            }
            // This is the Julian day for 12am for this day of the year
            int julianDay = Time.getJulianDay(millis, time.gmtoff);
            // Julian day.
            for (int hour = 0; hour < 24; hour++) {
                for (int minute = 0; minute < 60; minute += 15) {
                    time.set(0, minute, hour, monthDay, 0, 2008);
                    millis = time.normalize(true);
                    int day = Time.getJulianDay(millis, time.gmtoff);
                    if (day != julianDay) {
                        Log.e("TimeTest", "Julian day: " + day + " at time " + time.hour + ":" + time.minute + " != today's Julian day: " + julianDay + " timezone: " + time.timezone);
                    }
                    assertEquals(day, julianDay);
                }
            }
        }
    }
}
Also used : Time(android.text.format.Time) Suppress(android.test.suitebuilder.annotation.Suppress)

Aggregations

Time (android.text.format.Time)394 SmallTest (android.test.suitebuilder.annotation.SmallTest)97 Test (org.junit.Test)25 ArrayList (java.util.ArrayList)23 Date (java.util.Date)21 NetworkPolicy (android.net.NetworkPolicy)16 TrustedTime (android.util.TrustedTime)16 TextView (android.widget.TextView)15 Bundle (android.os.Bundle)13 TimeFormatException (android.util.TimeFormatException)13 Suppress (android.test.suitebuilder.annotation.Suppress)12 View (android.view.View)12 Paint (android.graphics.Paint)11 IOException (java.io.IOException)11 Matcher (java.util.regex.Matcher)9 IntentFilter (android.content.IntentFilter)7 File (java.io.File)7 DateFormat (java.text.DateFormat)7 SimpleDateFormat (java.text.SimpleDateFormat)7 ContentValues (android.content.ContentValues)6