use of org.joda.time.Chronology in project joda-time by JodaOrg.
the class TestGJChronology method testLeap_29feb.
public void testLeap_29feb() {
Chronology chrono = GJChronology.getInstance();
DateTime dt = new DateTime(2012, 2, 29, 0, 0, chrono);
assertEquals(true, dt.year().isLeap());
assertEquals(true, dt.monthOfYear().isLeap());
assertEquals(true, dt.dayOfMonth().isLeap());
assertEquals(true, dt.dayOfYear().isLeap());
}
use of org.joda.time.Chronology in project joda-time by JodaOrg.
the class TestTextFields method testMonthNames_monthEnd.
public void testMonthNames_monthEnd() {
DateTimeFormatter printer = DateTimeFormat.forPattern("MMMM");
for (int i = 0; i < ZONES.length; i++) {
Chronology chrono = ISOChronology.getInstance(ZONES[i]);
for (int month = 1; month <= 12; month++) {
DateTime dt = new DateTime(2004, month, 1, 23, 20, 30, 40, chrono);
int lastDay = chrono.dayOfMonth().getMaximumValue(dt.getMillis());
dt = new DateTime(2004, month, lastDay, 23, 20, 30, 40, chrono);
String monthText = printer.print(dt);
assertEquals(MONTHS[month], monthText);
}
}
}
use of org.joda.time.Chronology in project joda-time by JodaOrg.
the class TestTextFields method testHalfdayNames.
public void testHalfdayNames() {
DateTimeFormatter printer = DateTimeFormat.forPattern("a");
for (int i = 0; i < ZONES.length; i++) {
Chronology chrono = ISOChronology.getInstance(ZONES[i]);
MutableDateTime mdt = new MutableDateTime(2004, 5, 30, 0, 20, 30, 40, chrono);
for (int hour = 0; hour < 24; hour++) {
mdt.setHourOfDay(hour);
int halfday = mdt.get(chrono.halfdayOfDay());
String halfdayText = printer.print(mdt);
assertEquals(HALFDAYS[halfday], halfdayText);
}
}
}
use of org.joda.time.Chronology in project joda-time by JodaOrg.
the class TestCalendarConverter method testGetChronology_Object_nullChronology.
public void testGetChronology_Object_nullChronology() throws Exception {
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("Europe/Paris"));
assertEquals(GJChronology.getInstance(PARIS), CalendarConverter.INSTANCE.getChronology(cal, (Chronology) null));
cal = new GregorianCalendar(TimeZone.getTimeZone("Europe/Moscow"));
cal.setGregorianChange(new Date(0L));
assertEquals(GJChronology.getInstance(MOSCOW, 0L, 4), CalendarConverter.INSTANCE.getChronology(cal, (Chronology) null));
cal = new GregorianCalendar(TimeZone.getTimeZone("Europe/Moscow"));
cal.setGregorianChange(new Date(Long.MAX_VALUE));
assertEquals(JulianChronology.getInstance(MOSCOW), CalendarConverter.INSTANCE.getChronology(cal, (Chronology) null));
cal = new GregorianCalendar(TimeZone.getTimeZone("Europe/Moscow"));
cal.setGregorianChange(new Date(Long.MIN_VALUE));
assertEquals(GregorianChronology.getInstance(MOSCOW), CalendarConverter.INSTANCE.getChronology(cal, (Chronology) null));
cal = new GregorianCalendar(new MockUnknownTimeZone());
assertEquals(GJChronology.getInstance(), CalendarConverter.INSTANCE.getChronology(cal, (Chronology) null));
Calendar uc = new MockUnknownCalendar(TimeZone.getTimeZone("Europe/Moscow"));
assertEquals(ISOChronology.getInstance(MOSCOW), CalendarConverter.INSTANCE.getChronology(uc, (Chronology) null));
try {
Calendar bc = (Calendar) Class.forName("sun.util.BuddhistCalendar").newInstance();
bc.setTimeZone(TimeZone.getTimeZone("Europe/Moscow"));
assertEquals(BuddhistChronology.getInstance(MOSCOW), CalendarConverter.INSTANCE.getChronology(bc, (Chronology) null));
} catch (ClassNotFoundException ex) {
// ignore not Sun JDK
} catch (IllegalAccessException ex) {
// ignore JDK 9 modules
}
}
use of org.joda.time.Chronology in project joda-time by JodaOrg.
the class TestConverterManager method testGetInstantConverterBadMultipleMatches.
public void testGetInstantConverterBadMultipleMatches() {
InstantConverter c = new InstantConverter() {
public long getInstantMillis(Object object, Chronology chrono) {
return 0;
}
public Chronology getChronology(Object object, DateTimeZone zone) {
return null;
}
public Chronology getChronology(Object object, Chronology chrono) {
return null;
}
public Class getSupportedType() {
return Serializable.class;
}
};
try {
ConverterManager.getInstance().addInstantConverter(c);
try {
ConverterManager.getInstance().getInstantConverter(new DateTime());
fail();
} catch (IllegalStateException ex) {
// Serializable and ReadableInstant both match, so cannot pick
}
} finally {
ConverterManager.getInstance().removeInstantConverter(c);
}
assertEquals(6, ConverterManager.getInstance().getInstantConverters().length);
}
Aggregations