Exemplo n.º 1
0
  // -----------------------------------------------------------------------
  public void testProperty() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    assertEquals(test.hourOfDay(), test.property(DateTimeFieldType.hourOfDay()));
    assertEquals(test.minuteOfHour(), test.property(DateTimeFieldType.minuteOfHour()));
    assertEquals(test.secondOfMinute(), test.property(DateTimeFieldType.secondOfMinute()));
    assertEquals(test.millisOfSecond(), test.property(DateTimeFieldType.millisOfSecond()));
    assertEquals(test.millisOfDay(), test.property(DateTimeFieldType.millisOfDay()));

    assertEquals(test, test.property(DateTimeFieldType.minuteOfDay()).getLocalTime());
    assertEquals(test, test.property(DateTimeFieldType.secondOfDay()).getLocalTime());
    assertEquals(test, test.property(DateTimeFieldType.millisOfDay()).getLocalTime());
    assertEquals(test, test.property(DateTimeFieldType.hourOfHalfday()).getLocalTime());
    assertEquals(test, test.property(DateTimeFieldType.halfdayOfDay()).getLocalTime());
    assertEquals(test, test.property(DateTimeFieldType.clockhourOfHalfday()).getLocalTime());
    assertEquals(test, test.property(DateTimeFieldType.clockhourOfDay()).getLocalTime());

    try {
      test.property(DateTimeFieldType.dayOfWeek());
      fail();
    } catch (IllegalArgumentException ex) {
    }
    try {
      test.property(null);
      fail();
    } catch (IllegalArgumentException ex) {
    }
  }
Exemplo n.º 2
0
  public void testIsSupported_DateTimeFieldType() {
    LocalTime test = new LocalTime(10, 20, 30, 40);
    assertEquals(true, test.isSupported(DateTimeFieldType.hourOfDay()));
    assertEquals(true, test.isSupported(DateTimeFieldType.minuteOfHour()));
    assertEquals(true, test.isSupported(DateTimeFieldType.secondOfMinute()));
    assertEquals(true, test.isSupported(DateTimeFieldType.millisOfSecond()));
    assertEquals(true, test.isSupported(DateTimeFieldType.minuteOfDay()));
    assertEquals(true, test.isSupported(DateTimeFieldType.secondOfDay()));
    assertEquals(true, test.isSupported(DateTimeFieldType.millisOfDay()));

    assertEquals(true, test.isSupported(DateTimeFieldType.hourOfHalfday()));
    assertEquals(true, test.isSupported(DateTimeFieldType.halfdayOfDay()));
    assertEquals(true, test.isSupported(DateTimeFieldType.clockhourOfHalfday()));
    assertEquals(true, test.isSupported(DateTimeFieldType.clockhourOfDay()));

    assertEquals(false, test.isSupported(DateTimeFieldType.dayOfMonth()));
    assertEquals(false, test.isSupported((DateTimeFieldType) null));

    DateTimeFieldType d =
        new DateTimeFieldType("hours") {
          private static final long serialVersionUID = 1L;

          public DurationFieldType getDurationType() {
            return DurationFieldType.hours();
          }

          public DurationFieldType getRangeDurationType() {
            return null;
          }

          public DateTimeField getField(Chronology chronology) {
            return chronology.hourOfDay();
          }
        };
    assertEquals(false, test.isSupported(d));

    d =
        new DateTimeFieldType("hourOfYear") {
          private static final long serialVersionUID = 1L;

          public DurationFieldType getDurationType() {
            return DurationFieldType.hours();
          }

          public DurationFieldType getRangeDurationType() {
            return DurationFieldType.years();
          }

          public DateTimeField getField(Chronology chronology) {
            return chronology.hourOfDay();
          }
        };
    assertEquals(false, test.isSupported(d));
  }
Exemplo n.º 3
0
 // -----------------------------------------------------------------------
 public void testGet_DateTimeFieldType() {
   LocalTime test = new LocalTime(10, 20, 30, 40);
   assertEquals(10, test.get(DateTimeFieldType.hourOfDay()));
   assertEquals(20, test.get(DateTimeFieldType.minuteOfHour()));
   assertEquals(30, test.get(DateTimeFieldType.secondOfMinute()));
   assertEquals(40, test.get(DateTimeFieldType.millisOfSecond()));
   assertEquals(TEST_TIME_NOW / 60000, test.get(DateTimeFieldType.minuteOfDay()));
   assertEquals(TEST_TIME_NOW / 1000, test.get(DateTimeFieldType.secondOfDay()));
   assertEquals(TEST_TIME_NOW, test.get(DateTimeFieldType.millisOfDay()));
   assertEquals(10, test.get(DateTimeFieldType.hourOfHalfday()));
   assertEquals(DateTimeConstants.AM, test.get(DateTimeFieldType.halfdayOfDay()));
   test = new LocalTime(12, 30);
   assertEquals(0, test.get(DateTimeFieldType.hourOfHalfday()));
   assertEquals(12, test.get(DateTimeFieldType.clockhourOfHalfday()));
   assertEquals(12, test.get(DateTimeFieldType.clockhourOfDay()));
   assertEquals(DateTimeConstants.PM, test.get(DateTimeFieldType.halfdayOfDay()));
   test = new LocalTime(14, 30);
   assertEquals(2, test.get(DateTimeFieldType.hourOfHalfday()));
   assertEquals(2, test.get(DateTimeFieldType.clockhourOfHalfday()));
   assertEquals(14, test.get(DateTimeFieldType.clockhourOfDay()));
   assertEquals(DateTimeConstants.PM, test.get(DateTimeFieldType.halfdayOfDay()));
   test = new LocalTime(0, 30);
   assertEquals(0, test.get(DateTimeFieldType.hourOfHalfday()));
   assertEquals(12, test.get(DateTimeFieldType.clockhourOfHalfday()));
   assertEquals(24, test.get(DateTimeFieldType.clockhourOfDay()));
   assertEquals(DateTimeConstants.AM, test.get(DateTimeFieldType.halfdayOfDay()));
   try {
     test.get(null);
     fail();
   } catch (IllegalArgumentException ex) {
   }
   try {
     test.get(DateTimeFieldType.dayOfMonth());
     fail();
   } catch (IllegalArgumentException ex) {
   }
 }