use of java.util.GregorianCalendar in project j2objc by google.
the class Support_MessageFormat method t_format_with_FieldPosition.
public void t_format_with_FieldPosition() {
// This test assumes a default DateFormat.is24Hour setting.
/* J2ObjC: DateFormat.is24Hour is Android-specific.
DateFormat.is24Hour = null;*/
String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} hamburger{2,choice,1#|1<s} and drank {1, number} liters of coke. That was {0,choice,1#just enough|1<more than enough} food!";
MessageFormat format = new MessageFormat(pattern, Locale.US);
Date date = new GregorianCalendar(2005, 1, 28, 14, 20, 16).getTime();
Integer hamburgers = new Integer(8);
Object[] objects = new Object[] { hamburgers, new Double(3.5), hamburgers, date, date };
super.text = "On Feb 28, 2005 at 2:20:16 PM, he ate 8 hamburgers and drank 3.5 liters of coke. That was more than enough food!";
// test with MessageFormat.Field.ARGUMENT
t_FormatWithField(1, format, objects, null, Field.ARGUMENT, 3, 15);
// test other format fields that are included in the formatted text
t_FormatWithField(2, format, objects, null, DateFormat.Field.AM_PM, 0, 0);
t_FormatWithField(3, format, objects, null, NumberFormat.Field.FRACTION, 0, 0);
// test fields that are not included in the formatted text
t_FormatWithField(4, format, objects, null, DateFormat.Field.ERA, 0, 0);
t_FormatWithField(5, format, objects, null, NumberFormat.Field.EXPONENT_SIGN, 0, 0);
}
use of java.util.GregorianCalendar in project j2objc by google.
the class Support_SimpleDateFormat method t_format_with_FieldPosition.
public void t_format_with_FieldPosition() {
TimeZone tz = TimeZone.getTimeZone("EST");
Calendar cal = new GregorianCalendar(tz);
cal.set(1999, Calendar.SEPTEMBER, 13, 17, 19, 01);
cal.set(Calendar.MILLISECOND, 0);
Date date = cal.getTime();
SimpleDateFormat format = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.US);
format.setTimeZone(tz);
// test with all pattern chars, and multiple occurences
format.applyPattern("G GGGG y yy yyyy M MM MMM MMMM d dd ddd " + "k kk kkk H HH HHH h hh hhh m mmm s ss sss S SS SSS EE EEEE " + "D DD DDD F FF w www W WWW " + "a aaa K KKK z zzzz Z ZZZZ");
StringBuffer textBuffer = new StringBuffer();
// Really, GGGG should be "Anno Domini", but the RI doesn't support that and no one cares.
textBuffer.append("AD AD 1999 99 1999 9 09 Sep September 13 13 013 ");
textBuffer.append("17 17 017 17 17 017 5 05 005 19 019 1 01 001 0 00 000 Mon Monday ");
textBuffer.append("256 256 256 2 02 38 038 3 003 ");
textBuffer.append("PM PM 5 005 GMT-5 GMT-05:00 -0500 GMT-05:00");
// to avoid passing the huge StringBuffer each time.
super.text = textBuffer.toString();
// test if field positions are set correctly for these fields occurring
// multiple times.
t_FormatWithField(0, format, date, null, Field.ERA, 0, 2);
t_FormatWithField(1, format, date, null, Field.YEAR, 6, 10);
t_FormatWithField(2, format, date, null, Field.MONTH, 19, 20);
t_FormatWithField(3, format, date, null, Field.DAY_OF_MONTH, 38, 40);
t_FormatWithField(4, format, date, null, Field.HOUR_OF_DAY1, 48, 50);
t_FormatWithField(5, format, date, null, Field.HOUR_OF_DAY0, 58, 60);
t_FormatWithField(6, format, date, null, Field.HOUR1, 68, 69);
t_FormatWithField(7, format, date, null, Field.MINUTE, 77, 79);
t_FormatWithField(8, format, date, null, Field.SECOND, 84, 85);
t_FormatWithField(9, format, date, null, Field.MILLISECOND, 93, 94);
t_FormatWithField(10, format, date, null, Field.DAY_OF_WEEK, 102, 105);
t_FormatWithField(11, format, date, null, Field.DAY_OF_YEAR, 113, 116);
t_FormatWithField(12, format, date, null, Field.DAY_OF_WEEK_IN_MONTH, 125, 126);
t_FormatWithField(13, format, date, null, Field.WEEK_OF_YEAR, 130, 132);
t_FormatWithField(14, format, date, null, Field.WEEK_OF_MONTH, 137, 138);
t_FormatWithField(15, format, date, null, Field.AM_PM, 143, 145);
t_FormatWithField(16, format, date, null, Field.HOUR0, 151, 152);
t_FormatWithField(17, format, date, null, Field.TIME_ZONE, 157, 162);
// test fields that are not included in the formatted text
t_FormatWithField(18, format, date, null, NumberFormat.Field.EXPONENT_SIGN, 0, 0);
// test with simple example
format.applyPattern("h:m z");
super.text = "5:19 GMT-5";
t_FormatWithField(21, format, date, null, Field.HOUR1, 0, 1);
t_FormatWithField(22, format, date, null, Field.MINUTE, 2, 4);
t_FormatWithField(23, format, date, null, Field.TIME_ZONE, 5, 10);
// test fields that are not included in the formatted text
t_FormatWithField(24, format, date, null, Field.ERA, 0, 0);
t_FormatWithField(25, format, date, null, Field.YEAR, 0, 0);
t_FormatWithField(26, format, date, null, Field.MONTH, 0, 0);
t_FormatWithField(27, format, date, null, Field.DAY_OF_MONTH, 0, 0);
t_FormatWithField(28, format, date, null, Field.HOUR_OF_DAY1, 0, 0);
t_FormatWithField(29, format, date, null, Field.HOUR_OF_DAY0, 0, 0);
t_FormatWithField(30, format, date, null, Field.SECOND, 0, 0);
t_FormatWithField(31, format, date, null, Field.MILLISECOND, 0, 0);
t_FormatWithField(32, format, date, null, Field.DAY_OF_WEEK, 0, 0);
t_FormatWithField(33, format, date, null, Field.DAY_OF_YEAR, 0, 0);
t_FormatWithField(34, format, date, null, Field.DAY_OF_WEEK_IN_MONTH, 0, 0);
t_FormatWithField(35, format, date, null, Field.WEEK_OF_YEAR, 0, 0);
t_FormatWithField(36, format, date, null, Field.WEEK_OF_MONTH, 0, 0);
t_FormatWithField(37, format, date, null, Field.AM_PM, 0, 0);
t_FormatWithField(38, format, date, null, Field.HOUR0, 0, 0);
t_FormatWithField(39, format, date, null, NumberFormat.Field.EXPONENT, 0, 0);
// test with simple example with pattern char Z
format.applyPattern("h:m Z z");
super.text = "5:19 -0500 GMT-5";
t_FormatWithField(40, format, date, null, Field.HOUR1, 0, 1);
t_FormatWithField(41, format, date, null, Field.MINUTE, 2, 4);
t_FormatWithField(42, format, date, null, Field.TIME_ZONE, 5, 10);
}
use of java.util.GregorianCalendar in project j2objc by google.
the class SimpleDateFormatTest method test_get2DigitYearStart.
public void test_get2DigitYearStart() {
// Test for method java.util.Date
// java.text.SimpleDateFormat.get2DigitYearStart()
SimpleDateFormat f1 = new SimpleDateFormat("y");
Date date = f1.get2DigitYearStart();
Calendar cal = new GregorianCalendar();
int year = cal.get(Calendar.YEAR);
cal.setTime(date);
assertTrue("Wrong default year start", cal.get(Calendar.YEAR) == (year - 80));
}
use of java.util.GregorianCalendar in project j2objc by google.
the class Support_MessageFormat method t_formatToCharacterIterator.
public void t_formatToCharacterIterator() {
// This test assumes a default DateFormat.is24Hour setting.
/* J2ObjC: DateFormat.is24Hour is Android-specific.
DateFormat.is24Hour = null;*/
String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} hamburger{2,choice,1#|1<s} and drank {1, number} liters of coke. That was {0,choice,1#just enough|1<more than enough} food!";
MessageFormat format = new MessageFormat(pattern, Locale.US);
Date date = new GregorianCalendar(2005, 1, 28, 14, 20, 16).getTime();
Integer hamburgers = new Integer(8);
Object[] objects = new Object[] { hamburgers, new Double(3.5), hamburgers, date, date };
t_Format(1, objects, format, getMessageVector1());
}
use of java.util.GregorianCalendar in project j2objc by google.
the class SimpleDateFormatTest method test_parseLjava_lang_StringLjava_text_ParsePosition.
public void test_parseLjava_lang_StringLjava_text_ParsePosition() throws Exception {
// Test for method java.util.Date
// java.text.SimpleDateFormat.parse(java.lang.String,
// java.text.ParsePosition)
Calendar cal = new GregorianCalendar(1970, Calendar.JANUARY, 1);
Date time = cal.getTime();
assertParse("h", " 12", time, 1, 3);
assertParse("H", " 0", time, 1, 2);
assertParse("k", " 24", time, 1, 3);
assertParse("K", " 0", time, 1, 2);
cal = new GregorianCalendar(1970, Calendar.JANUARY, 1, 1, 0);
time = cal.getTime();
assertParse("h", "1", time, 0, 1);
assertParse("H", "1 ", time, 0, 1);
assertParse("k", "1", time, 0, 1);
assertParse("K", "1", time, 0, 1);
cal = new GregorianCalendar(1970, Calendar.JANUARY, 1, 11, 0);
time = cal.getTime();
assertParse("h", "0011 ", time, 0, 4);
assertParse("K", "11", time, 0, 2);
cal = new GregorianCalendar(1970, Calendar.JANUARY, 1, 23, 0);
time = cal.getTime();
assertParse("H", "23", time, 0, 2);
assertParse("k", "23", time, 0, 2);
assertParse("h a", " 3 AM", new GregorianCalendar(1970, Calendar.JANUARY, 1, 3, 0).getTime(), 1, 5);
assertParse("K a", " 3 pm ", new GregorianCalendar(1970, Calendar.JANUARY, 1, 15, 0).getTime(), 1, 5);
assertParse("m:s", "0:59 ", new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 0, 59).getTime(), 0, 4);
assertParse("m:s", "59:0", new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 59, 0).getTime(), 0, 4);
assertParse("ms", "059", new GregorianCalendar(1970, Calendar.JANUARY, 1, 0, 0, 59).getTime(), 0, 3);
cal = new GregorianCalendar(1970, Calendar.JANUARY, 1);
assertParse("S", "0", cal.getTime(), 0, 1);
cal.setTimeZone(TimeZone.getTimeZone("HST"));
cal.set(Calendar.MILLISECOND, 999);
assertParse("S z", "999 HST", cal.getTime(), 0, 7);
cal = new GregorianCalendar(1970, Calendar.JANUARY, 1);
cal.set(Calendar.ERA, GregorianCalendar.BC);
assertParse("G", "Bc ", cal.getTime(), 0, 2);
}
Aggregations