Search in sources :

Example 6 with Chronology

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());
}
Also used : Chronology(org.joda.time.Chronology) DateTime(org.joda.time.DateTime)

Example 7 with Chronology

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);
        }
    }
}
Also used : Chronology(org.joda.time.Chronology) ISOChronology(org.joda.time.chrono.ISOChronology) DateTime(org.joda.time.DateTime) MutableDateTime(org.joda.time.MutableDateTime)

Example 8 with Chronology

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);
        }
    }
}
Also used : MutableDateTime(org.joda.time.MutableDateTime) Chronology(org.joda.time.Chronology) ISOChronology(org.joda.time.chrono.ISOChronology)

Example 9 with Chronology

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
    }
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Chronology(org.joda.time.Chronology) GJChronology(org.joda.time.chrono.GJChronology) GregorianChronology(org.joda.time.chrono.GregorianChronology) ISOChronology(org.joda.time.chrono.ISOChronology) JulianChronology(org.joda.time.chrono.JulianChronology) BuddhistChronology(org.joda.time.chrono.BuddhistChronology) Date(java.util.Date)

Example 10 with Chronology

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);
}
Also used : Serializable(java.io.Serializable) Chronology(org.joda.time.Chronology) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) ReadableDateTime(org.joda.time.ReadableDateTime)

Aggregations

Chronology (org.joda.time.Chronology)69 DateTime (org.joda.time.DateTime)32 ISOChronology (org.joda.time.chrono.ISOChronology)30 GJChronology (org.joda.time.chrono.GJChronology)18 BuddhistChronology (org.joda.time.chrono.BuddhistChronology)17 LocalDate (org.joda.time.LocalDate)14 DateTimeZone (org.joda.time.DateTimeZone)13 MutableDateTime (org.joda.time.MutableDateTime)7 LocalDateTime (org.joda.time.LocalDateTime)4 ReadableDateTime (org.joda.time.ReadableDateTime)4 JulianChronology (org.joda.time.chrono.JulianChronology)3 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)3 Serializable (java.io.Serializable)2 Date (java.util.Date)2 Duration (org.joda.time.Duration)2 Period (org.joda.time.Period)2 ReadableDuration (org.joda.time.ReadableDuration)2 ReadableInstant (org.joda.time.ReadableInstant)2 ReadablePartial (org.joda.time.ReadablePartial)2 Calendar (java.util.Calendar)1