use of android.icu.util.GregorianCalendar in project j2objc by google.
the class CalendarRegressionTest method Test4145983.
/**
* Maximum value for YEAR field wrong.
*/
@Test
public void Test4145983() {
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTimeZone(TimeZone.getTimeZone("GMT"));
Date[] DATES = { new Date(Long.MAX_VALUE), new Date(Long.MIN_VALUE) };
for (int i = 0; i < DATES.length; ++i) {
calendar.setTime(DATES[i]);
int year = calendar.get(Calendar.YEAR);
int maxYear = calendar.getMaximum(Calendar.YEAR);
if (year > maxYear) {
errln("Failed for " + DATES[i].getTime() + " ms: year=" + year + ", maxYear=" + maxYear);
}
}
}
use of android.icu.util.GregorianCalendar in project j2objc by google.
the class CalendarRegressionTest method Test4136399.
/**
* Calendar and GregorianCalendar hashCode() methods need improvement.
* Calendar needs a good implementation that subclasses can override, and
* GregorianCalendar should use that implementation.
*/
@Test
public void Test4136399() {
/*
* Note: This test is actually more strict than it has to be.
* Technically, there is no requirement that unequal objects have
* unequal hashes. We only require equal objects to have equal hashes.
* It is desirable for unequal objects to have distributed hashes, but
* there is no hard requirement here.
*
* In this test we make assumptions about certain attributes of calendar
* objects getting represented in the hash, which need not always be the
* case (although it does work currently with the given test).
*/
Calendar a = Calendar.getInstance();
Calendar b = (Calendar) a.clone();
if (a.hashCode() != b.hashCode()) {
errln("Calendar hash code unequal for cloned objects");
}
TimeZone atz1 = a.getTimeZone();
TimeZone atz2 = (TimeZone) atz1.clone();
if (!atz1.equals(atz2)) {
errln("The clone timezones are not equal");
}
if (atz1.hashCode() != atz2.hashCode()) {
errln("TimeZone hash code unequal for cloned objects");
}
b.setMinimalDaysInFirstWeek(7 - a.getMinimalDaysInFirstWeek());
if (a.hashCode() == b.hashCode()) {
errln("Calendar hash code ignores minimal days in first week");
}
b.setMinimalDaysInFirstWeek(a.getMinimalDaysInFirstWeek());
// Next day
b.setFirstDayOfWeek((a.getFirstDayOfWeek() % 7) + 1);
if (a.hashCode() == b.hashCode()) {
errln("Calendar hash code ignores first day of week");
}
b.setFirstDayOfWeek(a.getFirstDayOfWeek());
b.setLenient(!a.isLenient());
if (a.hashCode() == b.hashCode()) {
errln("Calendar hash code ignores lenient setting");
}
b.setLenient(a.isLenient());
// Assume getTimeZone() returns a reference, not a clone
// of a reference -- this is true as of this writing
TimeZone atz = a.getTimeZone();
TimeZone btz = b.getTimeZone();
btz.setRawOffset(atz.getRawOffset() + 60 * 60 * 1000);
if (atz.hashCode() == btz.hashCode()) {
errln(atz.hashCode() + "==" + btz.hashCode());
}
if (a.getTimeZone() != b.getTimeZone() && a.hashCode() == b.hashCode()) {
errln("Calendar hash code ignores zone");
}
b.getTimeZone().setRawOffset(a.getTimeZone().getRawOffset());
GregorianCalendar c = new GregorianCalendar();
GregorianCalendar d = (GregorianCalendar) c.clone();
if (c.hashCode() != d.hashCode()) {
errln("GregorianCalendar hash code unequal for clones objects");
}
Date cutover = c.getGregorianChange();
d.setGregorianChange(new Date(cutover.getTime() + 24 * 60 * 60 * 1000));
if (c.hashCode() == d.hashCode()) {
errln("GregorianCalendar hash code ignores cutover");
}
}
use of android.icu.util.GregorianCalendar in project j2objc by google.
the class EthiopicTest 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");
fmt.setCalendar(new EthiopicCalendar());
EthiopicCalendar cal = new EthiopicCalendar(1, 0, 1);
assertEquals("Ethiopic Date", "Wed Jan 01, 0001 AD", fmt.format(cal));
cal.set(Calendar.ERA, 0);
cal.set(Calendar.YEAR, 5500);
assertEquals("Ethiopic Date", "Tue Jan 01, 5500 BC", fmt.format(cal));
// The gregorian calendar gets off by two days when
// the date gets low, unless the gregorian changeover is set to
// very early. The funny thing is, it's ok for dates in the year
// 283, but not in the year 7, and it claims to be ok until the year 4.
// should track down when the dates start to differ...
GregorianCalendar gc = new GregorianCalendar();
// act like proleptic Gregorian
gc.setGregorianChange(new Date(Long.MIN_VALUE));
gc.setTime(cal.getTime());
fmt.setCalendar(new GregorianCalendar());
assertEquals("Gregorian Date", "Tue Aug 28, 0007 AD", fmt.format(gc));
}
use of android.icu.util.GregorianCalendar in project j2objc by google.
the class HolidayTest method init.
@Before
public void init() throws Exception {
if (cal == null) {
cal = new GregorianCalendar(1, 0, 1);
longTimeAgo = cal.getTime();
now = new Date();
}
}
use of android.icu.util.GregorianCalendar in project j2objc by google.
the class IndianTest method TestYear.
@Test
public void TestYear() {
// Gregorian Calendar
Calendar gCal = new GregorianCalendar();
Date gToday = gCal.getTime();
gCal.add(GregorianCalendar.MONTH, 2);
Date gFuture = gCal.getTime();
DateFormat gDF = DateFormat.getDateInstance(gCal, DateFormat.FULL);
logln("gregorian calendar: " + gDF.format(gToday) + " + 2 months = " + gDF.format(gFuture));
// Indian Calendar
IndianCalendar iCal = new IndianCalendar();
Date iToday = iCal.getTime();
iCal.add(IndianCalendar.MONTH, 2);
Date iFuture = iCal.getTime();
DateFormat iDF = DateFormat.getDateInstance(iCal, DateFormat.FULL);
logln("Indian calendar: " + iDF.format(iToday) + " + 2 months = " + iDF.format(iFuture));
}
Aggregations