use of android.icu.util.Calendar in project j2objc by google.
the class DateFormatRegressionTest method Test4151706.
/**
* @bug 4151706
* 'z' at end of date format throws index exception in SimpleDateFormat
* CANNOT REPRODUCE THIS BUG ON 1.2FCS
*/
@Test
public void Test4151706() {
String dateString = "Thursday, 31-Dec-98 23:00:00 GMT";
SimpleDateFormat fmt = new SimpleDateFormat("EEEE, dd-MMM-yy HH:mm:ss z", Locale.US);
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.US);
cal.clear();
cal.set(1998, Calendar.DECEMBER, 31, 23, 0, 0);
Date d = new Date();
try {
d = fmt.parse(dateString);
// {sfb} what about next two lines?
if (d.getTime() != cal.getTime().getTime())
errln("Incorrect value: " + d);
} catch (Exception e) {
errln("Fail: " + e);
}
StringBuffer temp = new StringBuffer("");
FieldPosition pos = new FieldPosition(0);
logln(dateString + " . " + fmt.format(d, temp, pos));
}
use of android.icu.util.Calendar in project j2objc by google.
the class DateFormatRegressionTest method Test4065240.
/**
* @bug 4065240
*/
@Test
public void Test4065240() {
Date curDate;
DateFormat shortdate, fulldate;
String strShortDate, strFullDate;
Locale saveLocale = Locale.getDefault();
TimeZone saveZone = TimeZone.getDefault();
try {
Locale curLocale = new Locale("de", "DE");
Locale.setDefault(curLocale);
// {sfb} adoptDefault instead of setDefault
// TimeZone.setDefault(TimeZone.createTimeZone("EST"));
TimeZone.setDefault(TimeZone.getTimeZone("EST"));
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(98 + 1900, 0, 1);
curDate = cal.getTime();
shortdate = DateFormat.getDateInstance(DateFormat.SHORT);
fulldate = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
strShortDate = "The current date (short form) is ";
String temp;
temp = shortdate.format(curDate);
strShortDate += temp;
strFullDate = "The current date (long form) is ";
String temp2 = fulldate.format(curDate);
strFullDate += temp2;
logln(strShortDate);
logln(strFullDate);
// {sfb} What to do with resource bundle stuff?????
// Check to see if the resource is present; if not, we can't test
// ResourceBundle bundle = //The variable is never used
// ICULocaleData.getBundle("DateFormatZoneData", curLocale);
// {sfb} API change to ResourceBundle -- add getLocale()
/*if (bundle.getLocale().getLanguage().equals("de")) {
// UPDATE THIS AS ZONE NAME RESOURCE FOR <EST> in de_DE is updated
if (!strFullDate.endsWith("GMT-05:00"))
errln("Fail: Want GMT-05:00");
} else {
logln("*** TEST COULD NOT BE COMPLETED BECAUSE DateFormatZoneData ***");
logln("*** FOR LOCALE de OR de_DE IS MISSING ***");
}*/
} catch (Exception e) {
logln(e.getMessage());
} finally {
Locale.setDefault(saveLocale);
TimeZone.setDefault(saveZone);
}
}
use of android.icu.util.Calendar in project j2objc by google.
the class DateFormatRegressionTest method Test4071441.
/*
DateFormat.equals is too narrowly defined. As a result, MessageFormat
does not work correctly. DateFormat.equals needs to be written so
that the Calendar sub-object is not compared using Calendar.equals,
but rather compared for equivalency. This may necessitate adding a
(package private) method to Calendar to test for equivalency.
Currently this bug breaks MessageFormat.toPattern
*/
/**
* @bug 4071441
*/
@Test
public void Test4071441() {
DateFormat fmtA = DateFormat.getInstance();
DateFormat fmtB = DateFormat.getInstance();
// {sfb} Is it OK to cast away const here?
Calendar calA = fmtA.getCalendar();
Calendar calB = fmtB.getCalendar();
calA.clear();
calA.set(1900, 0, 0);
calB.clear();
calB.set(1900, 0, 0);
if (!calA.equals(calB))
errln("Fail: Can't complete test; Calendar instances unequal");
if (!fmtA.equals(fmtB))
errln("Fail: DateFormat unequal when Calendars equal");
calB.clear();
calB.set(1961, Calendar.DECEMBER, 25);
if (calA.equals(calB))
errln("Fail: Can't complete test; Calendar instances equal");
if (!fmtA.equals(fmtB))
errln("Fail: DateFormat unequal when Calendars equivalent");
logln("DateFormat.equals ok");
}
use of android.icu.util.Calendar in project j2objc by google.
the class DateFormatRegressionTestJ method Test4250359.
// DateFormat.format works wrongly?
@Test
public void Test4250359() {
Locale.setDefault(Locale.US);
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(101 + 1900, 9, 9, 17, 53);
Date d = cal.getTime();
DateFormat tf = DateFormat.getTimeInstance(DateFormat.SHORT);
String act_result = tf.format(d);
String exp_result = "5:53 PM";
if (!act_result.equals(exp_result)) {
errln("The result is not expected");
}
}
use of android.icu.util.Calendar in project j2objc by google.
the class TimeZoneTest method TestRuleAPI.
@Test
public void TestRuleAPI() {
// ErrorCode status = ZERO_ERROR;
// Pick a weird offset
int offset = (int) (60 * 60 * 1000 * 1.75);
SimpleTimeZone zone = new SimpleTimeZone(offset, "TestZone");
if (zone.useDaylightTime())
errln("FAIL: useDaylightTime should return false");
// Establish our expected transition times. Do this with a non-DST
// calendar with the (above) declared local offset.
GregorianCalendar gc = new GregorianCalendar(zone);
gc.clear();
gc.set(1990, Calendar.MARCH, 1);
// Local Std time midnight
long marchOneStd = gc.getTime().getTime();
gc.clear();
gc.set(1990, Calendar.JULY, 1);
// Local Std time midnight
long julyOneStd = gc.getTime().getTime();
// Starting and ending hours, WALL TIME
int startHour = (int) (2.25 * 3600000);
int endHour = (int) (3.5 * 3600000);
zone.setStartRule(Calendar.MARCH, 1, 0, startHour);
zone.setEndRule(Calendar.JULY, 1, 0, endHour);
gc = new GregorianCalendar(zone);
// if (failure(status, "new GregorianCalendar")) return;
long marchOne = marchOneStd + startHour;
// Adjust from wall to Std time
long julyOne = julyOneStd + endHour - 3600000;
long expMarchOne = 636251400000L;
if (marchOne != expMarchOne) {
errln("FAIL: Expected start computed as " + marchOne + " = " + new Date(marchOne));
logln(" Should be " + expMarchOne + " = " + new Date(expMarchOne));
}
long expJulyOne = 646793100000L;
if (julyOne != expJulyOne) {
errln("FAIL: Expected start computed as " + julyOne + " = " + new Date(julyOne));
logln(" Should be " + expJulyOne + " = " + new Date(expJulyOne));
}
Calendar cal1 = Calendar.getInstance();
cal1.set(1990, Calendar.JANUARY, 1);
Calendar cal2 = Calendar.getInstance();
cal2.set(1990, Calendar.JUNE, 1);
_testUsingBinarySearch(zone, cal1.getTimeInMillis(), cal2.getTimeInMillis(), marchOne);
cal1.set(1990, Calendar.JUNE, 1);
cal2.set(1990, Calendar.DECEMBER, 31);
_testUsingBinarySearch(zone, cal1.getTimeInMillis(), cal2.getTimeInMillis(), julyOne);
if (zone.inDaylightTime(new Date(marchOne - 1000)) || !zone.inDaylightTime(new Date(marchOne)))
errln("FAIL: Start rule broken");
if (!zone.inDaylightTime(new Date(julyOne - 1000)) || zone.inDaylightTime(new Date(julyOne)))
errln("FAIL: End rule broken");
zone.setStartYear(1991);
if (zone.inDaylightTime(new Date(marchOne)) || zone.inDaylightTime(new Date(julyOne - 1000)))
errln("FAIL: Start year broken");
// failure(status, "TestRuleAPI");
// delete gc;
// delete zone;
}
Aggregations