use of org.joda.time.DurationField in project joda-time by JodaOrg.
the class TestScaledDurationField method test_hashCode.
public void test_hashCode() {
assertEquals(iField.hashCode(), iField.hashCode());
assertEquals(false, iField.hashCode() == ISOChronology.getInstance().minutes().hashCode());
DurationField dummy = new ScaledDurationField(MillisDurationField.INSTANCE, DurationFieldType.minutes(), 2);
assertEquals(false, iField.hashCode() == dummy.hashCode());
dummy = new ScaledDurationField(MillisDurationField.INSTANCE, DurationFieldType.minutes(), 90);
assertEquals(true, iField.hashCode() == dummy.hashCode());
dummy = new ScaledDurationField(MillisDurationField.INSTANCE, DurationFieldType.millis(), 90);
assertEquals(false, iField.hashCode() == dummy.hashCode());
}
use of org.joda.time.DurationField in project joda-time by JodaOrg.
the class TestScaledDurationField method test_equals.
//-----------------------------------------------------------------------
public void test_equals() {
assertEquals(true, iField.equals(iField));
assertEquals(false, iField.equals(ISOChronology.getInstance().minutes()));
DurationField dummy = new ScaledDurationField(MillisDurationField.INSTANCE, DurationFieldType.minutes(), 2);
assertEquals(false, iField.equals(dummy));
dummy = new ScaledDurationField(MillisDurationField.INSTANCE, DurationFieldType.minutes(), 90);
assertEquals(true, iField.equals(dummy));
dummy = new ScaledDurationField(MillisDurationField.INSTANCE, DurationFieldType.millis(), 90);
assertEquals(false, iField.equals(dummy));
assertEquals(false, iField.equals(""));
assertEquals(false, iField.equals(null));
}
use of org.joda.time.DurationField in project joda-time by JodaOrg.
the class TestScaledDurationField method test_compareTo.
//-----------------------------------------------------------------------
public void test_compareTo() {
assertEquals(0, iField.compareTo(iField));
assertEquals(-1, iField.compareTo(ISOChronology.getInstance().minutes()));
DurationField dummy = new PreciseDurationField(DurationFieldType.minutes(), 0);
assertEquals(1, iField.compareTo(dummy));
// } catch (ClassCastException ex) {}
try {
iField.compareTo(null);
fail();
} catch (NullPointerException ex) {
}
}
use of org.joda.time.DurationField in project joda-time by JodaOrg.
the class TestScaledDurationField method testSerialization.
//-----------------------------------------------------------------------
public void testSerialization() throws Exception {
DurationField test = iField;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(test);
oos.close();
byte[] bytes = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
DurationField result = (DurationField) ois.readObject();
ois.close();
assertEquals(test, result);
}
use of org.joda.time.DurationField in project joda-time by JodaOrg.
the class TestCopticChronology method testDurationMonth.
public void testDurationMonth() {
// Leap 1723
DateTime dt11 = new DateTime(1723, 11, 2, 0, 0, 0, 0, COPTIC_UTC);
DateTime dt12 = new DateTime(1723, 12, 2, 0, 0, 0, 0, COPTIC_UTC);
DateTime dt13 = new DateTime(1723, 13, 2, 0, 0, 0, 0, COPTIC_UTC);
DateTime dt01 = new DateTime(1724, 1, 2, 0, 0, 0, 0, COPTIC_UTC);
DurationField fld = dt11.monthOfYear().getDurationField();
assertEquals(COPTIC_UTC.months(), fld);
assertEquals(1L * 30L * MILLIS_PER_DAY, fld.getMillis(1, dt11.getMillis()));
assertEquals(2L * 30L * MILLIS_PER_DAY, fld.getMillis(2, dt11.getMillis()));
assertEquals((2L * 30L + 6L) * MILLIS_PER_DAY, fld.getMillis(3, dt11.getMillis()));
assertEquals((3L * 30L + 6L) * MILLIS_PER_DAY, fld.getMillis(4, dt11.getMillis()));
assertEquals(1L * 30L * MILLIS_PER_DAY, fld.getMillis(1));
assertEquals(2L * 30L * MILLIS_PER_DAY, fld.getMillis(2));
assertEquals(13L * 30L * MILLIS_PER_DAY, fld.getMillis(13));
assertEquals(1L * 30L * MILLIS_PER_DAY, fld.getMillis(1L, dt11.getMillis()));
assertEquals(2L * 30L * MILLIS_PER_DAY, fld.getMillis(2L, dt11.getMillis()));
assertEquals((2L * 30L + 6L) * MILLIS_PER_DAY, fld.getMillis(3L, dt11.getMillis()));
assertEquals((3L * 30L + 6L) * MILLIS_PER_DAY, fld.getMillis(4L, dt11.getMillis()));
assertEquals(1L * 30L * MILLIS_PER_DAY, fld.getMillis(1L));
assertEquals(2L * 30L * MILLIS_PER_DAY, fld.getMillis(2L));
assertEquals(13L * 30L * MILLIS_PER_DAY, fld.getMillis(13L));
assertEquals(0, fld.getValue(1L * 30L * MILLIS_PER_DAY - 1L, dt11.getMillis()));
assertEquals(1, fld.getValue(1L * 30L * MILLIS_PER_DAY, dt11.getMillis()));
assertEquals(1, fld.getValue(1L * 30L * MILLIS_PER_DAY + 1L, dt11.getMillis()));
assertEquals(1, fld.getValue(2L * 30L * MILLIS_PER_DAY - 1L, dt11.getMillis()));
assertEquals(2, fld.getValue(2L * 30L * MILLIS_PER_DAY, dt11.getMillis()));
assertEquals(2, fld.getValue(2L * 30L * MILLIS_PER_DAY + 1L, dt11.getMillis()));
assertEquals(2, fld.getValue((2L * 30L + 6L) * MILLIS_PER_DAY - 1L, dt11.getMillis()));
assertEquals(3, fld.getValue((2L * 30L + 6L) * MILLIS_PER_DAY, dt11.getMillis()));
assertEquals(3, fld.getValue((2L * 30L + 6L) * MILLIS_PER_DAY + 1L, dt11.getMillis()));
assertEquals(3, fld.getValue((3L * 30L + 6L) * MILLIS_PER_DAY - 1L, dt11.getMillis()));
assertEquals(4, fld.getValue((3L * 30L + 6L) * MILLIS_PER_DAY, dt11.getMillis()));
assertEquals(4, fld.getValue((3L * 30L + 6L) * MILLIS_PER_DAY + 1L, dt11.getMillis()));
assertEquals(dt12.getMillis(), fld.add(dt11.getMillis(), 1));
assertEquals(dt13.getMillis(), fld.add(dt11.getMillis(), 2));
assertEquals(dt01.getMillis(), fld.add(dt11.getMillis(), 3));
assertEquals(dt12.getMillis(), fld.add(dt11.getMillis(), 1L));
assertEquals(dt13.getMillis(), fld.add(dt11.getMillis(), 2L));
assertEquals(dt01.getMillis(), fld.add(dt11.getMillis(), 3L));
}
Aggregations