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);
}
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
}
}
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()));
}
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));
}
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));
}
}
Aggregations