Search in sources :

Example 56 with SimpleDateFormat

use of java.text.SimpleDateFormat in project j2objc by google.

the class DateFormatTest method testDateTime.

private void testDateTime(int dStyle, int tStyle) {
    SimpleDateFormat f2 = (SimpleDateFormat) DateFormat.getDateTimeInstance(dStyle, tStyle);
    assertTrue("Wrong class", f2.getClass() == SimpleDateFormat.class);
    SimpleDateFormat date = (SimpleDateFormat) DateFormat.getDateInstance(dStyle, Locale.getDefault());
    SimpleDateFormat time = (SimpleDateFormat) DateFormat.getTimeInstance(tStyle, Locale.getDefault());
    assertEquals(f2.toPattern(), date.toPattern() + " " + time.toPattern());
    assertEquals(f2.getDateFormatSymbols(), new DateFormatSymbols());
    assertTrue("Doesn't work", f2.format(new Date()).getClass() == String.class);
}
Also used : DateFormatSymbols(java.text.DateFormatSymbols) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 57 with SimpleDateFormat

use of java.text.SimpleDateFormat in project j2objc by google.

the class DateFormatTest method test_getDateInstanceI.

/**
	 * @tests java.text.DateFormat#getDateInstance(int)
	 */
public void test_getDateInstanceI() {
    assertTrue("Default not medium", DateFormat.DEFAULT == DateFormat.MEDIUM);
    SimpleDateFormat f2 = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.SHORT);
    assertTrue("Wrong class1", f2.getClass() == SimpleDateFormat.class);
    assertTrue("Wrong default1", f2.equals(DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault())));
    assertTrue("Wrong symbols1", f2.getDateFormatSymbols().equals(new DateFormatSymbols()));
    assertTrue("Doesn't work1", f2.format(new Date()).getClass() == String.class);
    f2 = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.MEDIUM);
    assertTrue("Wrong class2", f2.getClass() == SimpleDateFormat.class);
    assertTrue("Wrong default2", f2.equals(DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault())));
    assertTrue("Wrong symbols2", f2.getDateFormatSymbols().equals(new DateFormatSymbols()));
    assertTrue("Doesn't work2", f2.format(new Date()).getClass() == String.class);
    f2 = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.LONG);
    assertTrue("Wrong class3", f2.getClass() == SimpleDateFormat.class);
    assertTrue("Wrong default3", f2.equals(DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault())));
    assertTrue("Wrong symbols3", f2.getDateFormatSymbols().equals(new DateFormatSymbols()));
    assertTrue("Doesn't work3", f2.format(new Date()).getClass() == String.class);
    f2 = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.FULL);
    assertTrue("Wrong class4", f2.getClass() == SimpleDateFormat.class);
    assertTrue("Wrong default4", f2.equals(DateFormat.getDateInstance(DateFormat.FULL, Locale.getDefault())));
    assertTrue("Wrong symbols4", f2.getDateFormatSymbols().equals(new DateFormatSymbols()));
    assertTrue("Doesn't work4", f2.format(new Date()).getClass() == String.class);
    // regression test for HARMONY-940
    try {
        DateFormat.getDateInstance(77);
        fail("Should throw IAE");
    } catch (IllegalArgumentException iae) {
    //expected
    }
}
Also used : DateFormatSymbols(java.text.DateFormatSymbols) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 58 with SimpleDateFormat

use of java.text.SimpleDateFormat in project j2objc by google.

the class SimpleTimeZoneTest method formatCalendar.

public static String formatCalendar(Calendar cal) {
    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.ENGLISH);
    format.setTimeZone(cal.getTimeZone());
    return format.format(new Date(cal.getTimeInMillis()));
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 59 with SimpleDateFormat

use of java.text.SimpleDateFormat in project j2objc by google.

the class TimeZoneTest method testPreHistoricInDaylightTime.

// http://code.google.com/p/android/issues/detail?id=14395
public void testPreHistoricInDaylightTime() throws Exception {
    Locale.setDefault(Locale.US);
    TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
    TimeZone.setDefault(tz);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
    Date date = sdf.parse("1902-11-01T00:00:00.000+0800");
    assertEquals(-2119680000000L, date.getTime());
    assertEquals(-28800000, tz.getOffset(date.getTime()));
    assertFalse(tz.inDaylightTime(date));
    assertEquals("Fri Oct 31 08:00:00 PST 1902", date.toString());
    assertEquals("31 Oct 1902 16:00:00 GMT", date.toGMTString());
    // Any time before we have transition data is considered non-daylight, even in summer.
    date = sdf.parse("1902-06-01T00:00:00.000+0800");
    assertEquals(-28800000, tz.getOffset(date.getTime()));
    assertFalse(tz.inDaylightTime(date));
}
Also used : TimeZone(java.util.TimeZone) SimpleTimeZone(java.util.SimpleTimeZone) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 60 with SimpleDateFormat

use of java.text.SimpleDateFormat in project OkVolley by googolmo.

the class OkNetwork method addCacheHeaders.

private void addCacheHeaders(Map<String, String> headers, Cache.Entry entry) {
    // If there's no cache entry, we're done.
    if (entry == null) {
        return;
    }
    if (entry.etag != null) {
        headers.put("If-None-Match", entry.etag);
    }
    if (entry.serverDate > 0) {
        Date refTime = new Date(entry.serverDate);
        final SimpleDateFormat formatter = DateFormatHolder.formatFor(PATTERN_RFC1036);
        headers.put("If-Modified-Since", formatter.format(refTime));
    }
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

SimpleDateFormat (java.text.SimpleDateFormat)3363 Date (java.util.Date)1843 ParseException (java.text.ParseException)559 DateFormat (java.text.DateFormat)526 Test (org.junit.Test)399 Calendar (java.util.Calendar)341 ArrayList (java.util.ArrayList)317 File (java.io.File)253 IOException (java.io.IOException)223 GregorianCalendar (java.util.GregorianCalendar)143 HashMap (java.util.HashMap)132 Locale (java.util.Locale)82 Map (java.util.Map)74 TimeZone (java.util.TimeZone)67 DateField (edu.uci.ics.textdb.api.field.DateField)64 DoubleField (edu.uci.ics.textdb.api.field.DoubleField)64 IField (edu.uci.ics.textdb.api.field.IField)64 IntegerField (edu.uci.ics.textdb.api.field.IntegerField)64 List (java.util.List)64 StringField (edu.uci.ics.textdb.api.field.StringField)63