Search in sources :

Example 11 with Chronology

use of org.joda.time.Chronology in project joda-time by JodaOrg.

the class TestConverterManager method testGetPartialConverterBadMultipleMatches.

public void testGetPartialConverterBadMultipleMatches() {
    PartialConverter c = new PartialConverter() {

        public int[] getPartialValues(ReadablePartial partial, Object object, Chronology chrono) {
            return null;
        }

        public int[] getPartialValues(ReadablePartial partial, Object object, Chronology chrono, DateTimeFormatter parser) {
            return null;
        }

        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().addPartialConverter(c);
        try {
            ConverterManager.getInstance().getPartialConverter(new DateTime());
            fail();
        } catch (IllegalStateException ex) {
        // Serializable and ReadablePartial both match, so cannot pick
        }
    } finally {
        ConverterManager.getInstance().removePartialConverter(c);
    }
    assertEquals(PARTIAL_SIZE, ConverterManager.getInstance().getPartialConverters().length);
}
Also used : Serializable(java.io.Serializable) ReadablePartial(org.joda.time.ReadablePartial) Chronology(org.joda.time.Chronology) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) ReadableDateTime(org.joda.time.ReadableDateTime)

Example 12 with Chronology

use of org.joda.time.Chronology in project joda-time by JodaOrg.

the class TestConverterManager method testGetPartialConverterOKMultipleMatches.

public void testGetPartialConverterOKMultipleMatches() {
    PartialConverter c = new PartialConverter() {

        public int[] getPartialValues(ReadablePartial partial, Object object, Chronology chrono) {
            return null;
        }

        public int[] getPartialValues(ReadablePartial partial, Object object, Chronology chrono, DateTimeFormatter parser) {
            return null;
        }

        public Chronology getChronology(Object object, DateTimeZone zone) {
            return null;
        }

        public Chronology getChronology(Object object, Chronology chrono) {
            return null;
        }

        public Class getSupportedType() {
            return ReadableDateTime.class;
        }
    };
    try {
        ConverterManager.getInstance().addPartialConverter(c);
        PartialConverter ok = ConverterManager.getInstance().getPartialConverter(new DateTime());
        // ReadableDateTime and ReadablePartial both match, but RI discarded as less specific
        assertEquals(ReadableDateTime.class, ok.getSupportedType());
    } finally {
        ConverterManager.getInstance().removePartialConverter(c);
    }
    assertEquals(PARTIAL_SIZE, ConverterManager.getInstance().getPartialConverters().length);
}
Also used : ReadablePartial(org.joda.time.ReadablePartial) ReadableDateTime(org.joda.time.ReadableDateTime) Chronology(org.joda.time.Chronology) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) ReadableDateTime(org.joda.time.ReadableDateTime)

Example 13 with Chronology

use of org.joda.time.Chronology in project joda-time by JodaOrg.

the class TestDateConverter method testGetInstantMillis_Object_Chronology.

//-----------------------------------------------------------------------
public void testGetInstantMillis_Object_Chronology() throws Exception {
    Date date = new Date(123L);
    long millis = DateConverter.INSTANCE.getInstantMillis(date, JULIAN);
    assertEquals(123L, millis);
    assertEquals(123L, DateConverter.INSTANCE.getInstantMillis(date, (Chronology) null));
}
Also used : Chronology(org.joda.time.Chronology) ISOChronology(org.joda.time.chrono.ISOChronology) JulianChronology(org.joda.time.chrono.JulianChronology) CopticChronology(org.joda.time.chrono.CopticChronology) Date(java.util.Date)

Example 14 with Chronology

use of org.joda.time.Chronology in project joda-time by JodaOrg.

the class TestISOChronology method testLeap_29feb.

public void testLeap_29feb() {
    Chronology chrono = ISOChronology.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 15 with Chronology

use of org.joda.time.Chronology in project joda-time by JodaOrg.

the class TestJulianChronology method testLeap_28feb.

public void testLeap_28feb() {
    Chronology chrono = JulianChronology.getInstance();
    DateTime dt = new DateTime(2012, 2, 28, 0, 0, chrono);
    assertEquals(true, dt.year().isLeap());
    assertEquals(true, dt.monthOfYear().isLeap());
    assertEquals(false, dt.dayOfMonth().isLeap());
    assertEquals(false, dt.dayOfYear().isLeap());
}
Also used : Chronology(org.joda.time.Chronology) DateTime(org.joda.time.DateTime)

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