use of android.icu.util.GregorianCalendar in project j2objc by google.
the class CalendarRegressionTest method Test4073929.
@Test
public void Test4073929() {
GregorianCalendar foo1 = new GregorianCalendar(1997, 8, 27);
foo1.add(Calendar.DAY_OF_MONTH, +1);
int testyear = foo1.get(Calendar.YEAR);
int testmonth = foo1.get(Calendar.MONTH);
int testday = foo1.get(Calendar.DAY_OF_MONTH);
if (testyear != 1997 || testmonth != 8 || testday != 28)
errln("Fail: Calendar not initialized");
}
use of android.icu.util.GregorianCalendar in project j2objc by google.
the class CalendarRegressionTest method TestT9452.
/**
* Test case for ticket 9452
* Calendar addition fall onto the missing date - 2011-12-30 in Samoa
*/
@Test
public void TestT9452() {
TimeZone samoaTZ = TimeZone.getTimeZone("Pacific/Apia");
GregorianCalendar cal = new GregorianCalendar(samoaTZ);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZZZZZ");
sdf.setTimeZone(samoaTZ);
// Set date to 2011-12-29 00:00
cal.clear();
cal.set(2011, Calendar.DECEMBER, 29, 0, 0, 0);
Date d = cal.getTime();
String dstr = sdf.format(d);
logln("Initial date: " + dstr);
// Add 1 day
cal.add(Calendar.DATE, 1);
d = cal.getTime();
dstr = sdf.format(d);
logln("+1 day: " + dstr);
assertEquals("Add 1 day", "2011-12-31T00:00:00+14:00", dstr);
// Subtract 1 day
cal.add(Calendar.DATE, -1);
d = cal.getTime();
dstr = sdf.format(d);
logln("-1 day: " + dstr);
assertEquals("Subtract 1 day", "2011-12-29T00:00:00-10:00", dstr);
}
use of android.icu.util.GregorianCalendar in project j2objc by google.
the class AstroTest method TestBasics.
@Test
public void TestBasics() {
// Check that our JD computation is the same as the book's (p. 88)
CalendarAstronomer astro = new CalendarAstronomer();
GregorianCalendar cal3 = new GregorianCalendar(TimeZone.getTimeZone("GMT"), Locale.US);
DateFormat d3 = DateFormat.getDateTimeInstance(cal3, DateFormat.MEDIUM, DateFormat.MEDIUM, Locale.US);
cal3.clear();
cal3.set(Calendar.YEAR, 1980);
cal3.set(Calendar.MONTH, Calendar.JULY);
cal3.set(Calendar.DATE, 27);
astro.setDate(cal3.getTime());
double jd = astro.getJulianDay() - 2447891.5;
double exp = -3444;
if (jd == exp) {
logln(d3.format(cal3.getTime()) + " => " + jd);
} else {
errln("FAIL: " + d3.format(cal3.getTime()) + " => " + jd + ", expected " + exp);
}
// cal3.clear();
// cal3.set(cal3.YEAR, 1990);
// cal3.set(cal3.MONTH, Calendar.JANUARY);
// cal3.set(cal3.DATE, 1);
// cal3.add(cal3.DATE, -1);
// astro.setDate(cal3.getTime());
// astro.foo();
}
use of android.icu.util.GregorianCalendar in project j2objc by google.
the class MyNumberFormat method Now.
public String Now() {
GregorianCalendar calendar = new GregorianCalendar();
Date t = calendar.getTime();
String nowStr = _dateFormat.format(t);
return nowStr;
}
use of android.icu.util.GregorianCalendar in project j2objc by google.
the class CurrencyTest method testCurrencyMetaInfoRanges.
// A real test of CurrencyMetaInfo.
@Test
public void testCurrencyMetaInfoRanges() {
CurrencyMetaInfo metainfo = CurrencyMetaInfo.getInstance(true);
assertNotNull("have metainfo", metainfo);
// must be capitalized
CurrencyFilter filter = CurrencyFilter.onRegion("DE");
List<CurrencyInfo> currenciesInGermany = metainfo.currencyInfo(filter);
logln("currencies: " + currenciesInGermany.size());
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z");
fmt.setTimeZone(TimeZone.getTimeZone("GMT"));
Date demLastDate = new Date(Long.MAX_VALUE);
Date eurFirstDate = new Date(Long.MIN_VALUE);
for (CurrencyInfo info : currenciesInGermany) {
logln(info.toString());
logln("from: " + fmt.format(info.from) + Long.toHexString(info.from));
logln(" to: " + fmt.format(info.to) + Long.toHexString(info.to));
if (info.code.equals("DEM")) {
demLastDate = new Date(info.to);
} else if (info.code.equals("EUR")) {
eurFirstDate = new Date(info.from);
}
}
// the Euro and Deutschmark overlapped for several years
assertEquals("DEM available at last date", 2, metainfo.currencyInfo(filter.withDate(demLastDate)).size());
// demLastDate + 1 millisecond is not the start of the last day, we consider it the next day, so...
Date demLastDatePlus1ms = new Date(demLastDate.getTime() + 1);
assertEquals("DEM not available after very start of last date", 1, metainfo.currencyInfo(filter.withDate(demLastDatePlus1ms)).size());
// both available for start of euro
assertEquals("EUR available on start of first date", 2, metainfo.currencyInfo(filter.withDate(eurFirstDate)).size());
// but not one millisecond before the start of the first day
Date eurFirstDateMinus1ms = new Date(eurFirstDate.getTime() - 1);
assertEquals("EUR not avilable before very start of first date", 1, metainfo.currencyInfo(filter.withDate(eurFirstDateMinus1ms)).size());
// end time is last millisecond of day
GregorianCalendar cal = new GregorianCalendar();
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
cal.setTime(demLastDate);
assertEquals("hour is 23", 23, cal.get(GregorianCalendar.HOUR_OF_DAY));
assertEquals("minute is 59", 59, cal.get(GregorianCalendar.MINUTE));
assertEquals("second is 59", 59, cal.get(GregorianCalendar.SECOND));
assertEquals("millisecond is 999", 999, cal.get(GregorianCalendar.MILLISECOND));
// start time is first millisecond of day
cal.setTime(eurFirstDate);
assertEquals("hour is 0", 0, cal.get(GregorianCalendar.HOUR_OF_DAY));
assertEquals("minute is 0", 0, cal.get(GregorianCalendar.MINUTE));
assertEquals("second is 0", 0, cal.get(GregorianCalendar.SECOND));
assertEquals("millisecond is 0", 0, cal.get(GregorianCalendar.MILLISECOND));
}
Aggregations