示例#1
0
  public void testWithZone_DateTimeZone() {
    DateTime test = new DateTime(TEST_TIME1);
    DateTime result = test.withZone(PARIS);
    assertEquals(test.getMillis(), result.getMillis());
    assertEquals(ISO_PARIS, result.getChronology());

    test = new DateTime(TEST_TIME1, GREGORIAN_PARIS);
    result = test.withZone(null);
    assertEquals(test.getMillis(), result.getMillis());
    assertEquals(GREGORIAN_DEFAULT, result.getChronology());

    test = new DateTime(TEST_TIME1);
    result = test.withZone(null);
    assertSame(test, result);
  }
示例#2
0
  // -----------------------------------------------------------------------
  public void testWithMillis_long() {
    DateTime test = new DateTime(TEST_TIME1);
    DateTime result = test.withMillis(TEST_TIME2);
    assertEquals(TEST_TIME2, result.getMillis());
    assertEquals(test.getChronology(), result.getChronology());

    test = new DateTime(TEST_TIME1, GREGORIAN_PARIS);
    result = test.withMillis(TEST_TIME2);
    assertEquals(TEST_TIME2, result.getMillis());
    assertEquals(test.getChronology(), result.getChronology());

    test = new DateTime(TEST_TIME1);
    result = test.withMillis(TEST_TIME1);
    assertSame(test, result);
  }
示例#3
0
  // -----------------------------------------------------------------------
  public void testGetters() {
    DateTime test = new DateTime();

    assertEquals(ISO_DEFAULT, test.getChronology());
    assertEquals(LONDON, test.getZone());
    assertEquals(TEST_TIME_NOW, test.getMillis());

    assertEquals(1, test.getEra());
    assertEquals(20, test.getCenturyOfEra());
    assertEquals(2, test.getYearOfCentury());
    assertEquals(2002, test.getYearOfEra());
    assertEquals(2002, test.getYear());
    assertEquals(6, test.getMonthOfYear());
    assertEquals(9, test.getDayOfMonth());
    assertEquals(2002, test.getWeekyear());
    assertEquals(23, test.getWeekOfWeekyear());
    assertEquals(7, test.getDayOfWeek());
    assertEquals(160, test.getDayOfYear());
    assertEquals(1, test.getHourOfDay());
    assertEquals(0, test.getMinuteOfHour());
    assertEquals(60, test.getMinuteOfDay());
    assertEquals(0, test.getSecondOfMinute());
    assertEquals(60 * 60, test.getSecondOfDay());
    assertEquals(0, test.getMillisOfSecond());
    assertEquals(60 * 60 * 1000, test.getMillisOfDay());
  }
示例#4
0
  public void testToDateTime_Chronology() {
    DateTime test = new DateTime(TEST_TIME1);
    DateTime result = test.toDateTime(ISO_DEFAULT);
    assertSame(test, result);

    test = new DateTime(TEST_TIME1);
    result = test.toDateTime(GREGORIAN_PARIS);
    assertEquals(test.getMillis(), result.getMillis());
    assertEquals(GREGORIAN_PARIS, result.getChronology());

    test = new DateTime(TEST_TIME1, GREGORIAN_PARIS);
    result = test.toDateTime((Chronology) null);
    assertEquals(test.getMillis(), result.getMillis());
    assertEquals(ISO_DEFAULT, result.getChronology());

    test = new DateTime(TEST_TIME1);
    result = test.toDateTime((Chronology) null);
    assertSame(test, result);
  }
示例#5
0
  public void testToDateTimeISO() {
    DateTime test = new DateTime(TEST_TIME1);
    DateTime result = test.toDateTimeISO();
    assertSame(test, result);

    test = new DateTime(TEST_TIME1, ISO_PARIS);
    result = test.toDateTimeISO();
    assertSame(DateTime.class, result.getClass());
    assertSame(ISOChronology.class, result.getChronology().getClass());
    assertEquals(test.getMillis(), result.getMillis());
    assertEquals(ISO_PARIS, result.getChronology());
    assertNotSame(test, result);

    test = new DateTime(TEST_TIME1, BUDDHIST_DEFAULT);
    result = test.toDateTimeISO();
    assertSame(DateTime.class, result.getClass());
    assertSame(ISOChronology.class, result.getChronology().getClass());
    assertEquals(test.getMillis(), result.getMillis());
    assertEquals(ISO_DEFAULT, result.getChronology());
    assertNotSame(test, result);

    test = new DateTime(TEST_TIME1, new MockNullZoneChronology());
    result = test.toDateTimeISO();
    assertSame(DateTime.class, result.getClass());
    assertSame(ISOChronology.class, result.getChronology().getClass());
    assertEquals(test.getMillis(), result.getMillis());
    assertEquals(ISO_DEFAULT, result.getChronology());
    assertNotSame(test, result);
  }
示例#6
0
  public void testWithTime_int_int_int() {
    DateTime test = new DateTime(TEST_TIME1 - 12345L, BUDDHIST_UTC);
    DateTime result = test.withTime(12, 24, 0, 0);
    assertEquals(TEST_TIME1, result.getMillis());
    assertEquals(BUDDHIST_UTC, result.getChronology());

    test = new DateTime(TEST_TIME1);
    try {
      test.withTime(25, 1, 1, 1);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }
示例#7
0
  public void testWithZoneRetainFields_DateTimeZone() {
    DateTime test = new DateTime(TEST_TIME1);
    DateTime result = test.withZoneRetainFields(PARIS);
    assertEquals(test.getMillis() - DateTimeConstants.MILLIS_PER_HOUR, result.getMillis());
    assertEquals(ISO_PARIS, result.getChronology());

    test = new DateTime(TEST_TIME1);
    result = test.withZoneRetainFields(LONDON);
    assertSame(test, result);

    test = new DateTime(TEST_TIME1);
    result = test.withZoneRetainFields(null);
    assertSame(test, result);

    test = new DateTime(TEST_TIME1, GREGORIAN_PARIS);
    result = test.withZoneRetainFields(null);
    assertEquals(test.getMillis() + DateTimeConstants.MILLIS_PER_HOUR, result.getMillis());
    assertEquals(GREGORIAN_DEFAULT, result.getChronology());

    test = new DateTime(TEST_TIME1, new MockNullZoneChronology());
    result = test.withZoneRetainFields(LONDON);
    assertSame(test, result);
  }