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());
b.setFirstDayOfWeek((a.getFirstDayOfWeek() % 7) + 1); // Next day
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());