use of android.icu.text.SimpleDateFormat in project j2objc by google.
the class CalendarRegressionTest method Test4061476.
@Test
public void Test4061476() {
SimpleDateFormat fmt = new SimpleDateFormat("ddMMMyy", Locale.UK);
Calendar cal = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.UK);
fmt.setCalendar(cal);
try {
Date date = fmt.parse("29MAY97");
cal.setTime(date);
} catch (Exception e) {
System.out.print("");
}
cal.set(Calendar.HOUR_OF_DAY, 13);
logln("Hour: " + cal.get(Calendar.HOUR_OF_DAY));
cal.add(Calendar.HOUR_OF_DAY, 6);
logln("Hour: " + cal.get(Calendar.HOUR_OF_DAY));
if (cal.get(Calendar.HOUR_OF_DAY) != 19)
errln("Fail: Want 19 Got " + cal.get(Calendar.HOUR_OF_DAY));
}
use of android.icu.text.SimpleDateFormat in project j2objc by google.
the class CalendarRegressionTest method Test4167060.
/**
* Calendar.getActualMaximum(YEAR) works wrong.
*/
@Test
public void Test4167060() {
int field = Calendar.YEAR;
DateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy G", Locale.US);
GregorianCalendar[] calendars = { new GregorianCalendar(100, Calendar.NOVEMBER, 1), new GregorianCalendar(-99, /* 100BC */
Calendar.JANUARY, 1), new GregorianCalendar(1996, Calendar.FEBRUARY, 29) };
String[] id = { "Hybrid", "Gregorian", "Julian" };
for (int k = 0; k < 3; ++k) {
logln("--- " + id[k] + " ---");
for (int j = 0; j < calendars.length; ++j) {
GregorianCalendar calendar = calendars[j];
if (k == 1) {
calendar.setGregorianChange(new Date(Long.MIN_VALUE));
} else if (k == 2) {
calendar.setGregorianChange(new Date(Long.MAX_VALUE));
}
format.setCalendar((Calendar) calendar.clone());
Date dateBefore = calendar.getTime();
int maxYear = calendar.getActualMaximum(field);
logln("maxYear: " + maxYear + " for " + format.format(calendar.getTime()));
logln("date before: " + format.format(dateBefore));
int[] years = { 2000, maxYear - 1, maxYear, maxYear + 1 };
for (int i = 0; i < years.length; i++) {
boolean valid = years[i] <= maxYear;
calendar.set(field, years[i]);
Date dateAfter = calendar.getTime();
int newYear = calendar.get(field);
// restore calendar for next
calendar.setTime(dateBefore);
// use
logln(" Year " + years[i] + (valid ? " ok " : " bad") + " => " + format.format(dateAfter));
if (valid && newYear != years[i]) {
errln(" FAIL: " + newYear + " should be valid; date, month and time shouldn't change");
} else if (!valid && newYear == years[i]) {
// We no longer require strict year maxima. That is, the
// calendar
// algorithm may work for values > the stated maximum.
// errln(" FAIL: " + newYear + " should be invalid");
logln(" Note: " + newYear + " > maximum, but still valid");
}
}
}
}
}
use of android.icu.text.SimpleDateFormat in project j2objc by google.
the class JapaneseTest method TestJapaneseYear3282.
@Test
public void TestJapaneseYear3282() {
Calendar c = Calendar.getInstance(ULocale.ENGLISH);
c.set(2003, Calendar.SEPTEMBER, 25);
JapaneseCalendar jcal = new JapaneseCalendar();
// jcal.setTime(new Date(1187906308151L)); alternate value
jcal.setTime(c.getTime());
logln("Now is: " + jcal.getTime());
c.setTime(jcal.getTime());
int nowYear = c.get(Calendar.YEAR);
logln("Now year: " + nowYear);
SimpleDateFormat jdf = (SimpleDateFormat) SimpleDateFormat.getDateInstance(jcal, SimpleDateFormat.DEFAULT, Locale.getDefault());
jdf.applyPattern("G yy/MM/dd");
String text = jdf.format(jcal.getTime());
logln("Now is: " + text + " (in Japan)");
try {
Date date = jdf.parse(text);
logln("But is this not the date?: " + date);
c.setTime(date);
int thenYear = c.get(Calendar.YEAR);
logln("Then year: " + thenYear);
if (thenYear != nowYear) {
errln("Nowyear " + nowYear + " is not thenyear " + thenYear);
} else {
logln("Nowyear " + nowYear + " == thenyear " + thenYear);
}
} catch (java.text.ParseException ex) {
ex.printStackTrace();
}
}
use of android.icu.text.SimpleDateFormat in project j2objc by google.
the class CopticTest method TestEraStart.
// basic check to see that we print out eras ok
// eventually should modify to use locale strings and formatter appropriate to coptic calendar
@Test
public void TestEraStart() {
SimpleDateFormat fmt = new SimpleDateFormat("EEE MMM dd, yyyy GG");
SimpleDateFormat copticFmt = new SimpleDateFormat("EEE MMM dd, yyyy GG");
copticFmt.setCalendar(new CopticCalendar());
CopticCalendar cal = new CopticCalendar(1, 0, 1);
assertEquals("Coptic Date", "Fri Jan 01, 0001 AD", copticFmt.format(cal));
assertEquals("Gregorian Date", "Fri Aug 29, 0284 AD", fmt.format(cal.getTime()));
cal.set(Calendar.ERA, 0);
cal.set(Calendar.YEAR, 1);
assertEquals("Coptic Date", "Thu Jan 01, 0001 BC", copticFmt.format(cal));
assertEquals("Gregorian Date", "Thu Aug 30, 0283 AD", fmt.format(cal.getTime()));
}
use of android.icu.text.SimpleDateFormat in project j2objc by google.
the class DataDrivenCalendarTest method testConvert.
void testConvert(String caseString, CalendarFieldsSet fromSet, Calendar fromCalendar, CalendarFieldsSet toSet, Calendar toCalendar, boolean forward) {
String thisString = caseString + (forward ? "forward" : "reverse") + " " + fromCalendar.getType() + "->" + toCalendar.getType() + " ";
fromCalendar.clear();
fromSet.setOnCalendar(fromCalendar);
CalendarFieldsSet diffSet = new CalendarFieldsSet();
diffSet.clear();
// Is the calendar sane at the first?
if (!fromSet.matches(fromCalendar, diffSet)) {
String diffs = diffSet.diffFrom(fromSet);
errln((String) "FAIL: " + thisString + ", SOURCE calendar was not set: Differences: " + diffs);
} else {
logln("PASS: " + thisString + " SOURCE calendar match.");
}
// logln("Set Source calendar: " + from);
Date fromTime = fromCalendar.getTime();
diffSet.clear();
// Is the calendar sane after being set?
if (!fromSet.matches(fromCalendar, diffSet)) {
String diffs = diffSet.diffFrom(fromSet);
errln((String) "FAIL: " + thisString + ", SET SOURCE calendar was not set: Differences: " + diffs);
} else {
logln("PASS: " + thisString + " SET SOURCE calendar match.");
}
toCalendar.clear();
toCalendar.setTime(fromTime);
diffSet.clear();
if (!toSet.matches(toCalendar, diffSet)) {
String diffs = diffSet.diffFrom(toSet);
errln((String) "FAIL: " + thisString + ", Differences: " + diffs);
DateFormat fmt = new SimpleDateFormat(new String("EEE MMM dd yyyy G"));
String fromString = fmt.format(fromTime);
logln("Source Time: " + fromString + ", Source Calendar: " + fromCalendar.getType());
} else {
logln("PASS: " + thisString + " match.");
}
}
Aggregations