Java 类java.time.DateTimeException 实例源码

项目:jdk8u-jdk    文件:TCKMinguoChronology.java   
@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_strict(int y, int m, int d, MinguoDate expected, Object smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
    if (strict) {
        MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:openjdk-jdk10    文件:TCKJapaneseChronology.java   
@Test(dataProvider = "resolve_eymd")
public void test_resolve_eymd(ResolverStyle style, JapaneseEra era, int yoe, int m, int d, JapaneseDate expected) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.ERA, (long) era.getValue());
    fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
    if (expected != null) {
        JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:openjdk-jdk10    文件:AbstractChronology.java   
ChronoLocalDate resolveYMD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle) {
    int y = range(YEAR).checkValidIntValue(fieldValues.remove(YEAR), YEAR);
    if (resolverStyle == ResolverStyle.LENIENT) {
        long months = Math.subtractExact(fieldValues.remove(MONTH_OF_YEAR), 1);
        long days = Math.subtractExact(fieldValues.remove(DAY_OF_MONTH), 1);
        return date(y, 1, 1).plus(months, MONTHS).plus(days, DAYS);
    }
    int moy = range(MONTH_OF_YEAR).checkValidIntValue(fieldValues.remove(MONTH_OF_YEAR), MONTH_OF_YEAR);
    ValueRange domRange = range(DAY_OF_MONTH);
    int dom = domRange.checkValidIntValue(fieldValues.remove(DAY_OF_MONTH), DAY_OF_MONTH);
    if (resolverStyle == ResolverStyle.SMART) {  // previous valid
        try {
            return date(y, moy, dom);
        } catch (DateTimeException ex) {
            return date(y, moy, 1).with(TemporalAdjusters.lastDayOfMonth());
        }
    }
    return date(y, moy, dom);
}
项目:openjdk-jdk10    文件:TCKThaiBuddhistChronology.java   
@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_strict(int y, int m, int d, ThaiBuddhistDate expected, Object smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
    if (strict) {
        ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:OpenJSharp    文件:DateTimeFormatterBuilder.java   
@Override
public boolean format(DateTimePrintContext context, StringBuilder buf) {
    int preLen = buf.length();
    if (printerParser.format(context, buf) == false) {
        return false;
    }
    int len = buf.length() - preLen;
    if (len > padWidth) {
        throw new DateTimeException(
            "Cannot print as output of " + len + " characters exceeds pad width of " + padWidth);
    }
    for (int i = 0; i < padWidth - len; i++) {
        buf.insert(preLen, padChar);
    }
    return true;
}
项目:openjdk-jdk10    文件:TCKThaiBuddhistChronology.java   
@Test(dataProvider = "resolve_ymaa")
public void test_resolve_ymaa_strict(int y, int m, int w, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
    fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
    if (strict) {
        ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:openjdk-jdk10    文件:TCKThaiBuddhistChronology.java   
@Test(dataProvider = "resolve_yearOfEra")
public void test_resolve_yearOfEra(ResolverStyle style, Integer e, Integer yoe, Integer y, ChronoField field, Integer expected) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    if (e != null) {
        fieldValues.put(ChronoField.ERA, (long) e);
    }
    if (yoe != null) {
        fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
    }
    if (y != null) {
        fieldValues.put(ChronoField.YEAR, (long) y);
    }
    if (field != null) {
        ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, style);
        assertEquals(date, null);
        assertEquals(fieldValues.get(field), (Long) expected.longValue());
        assertEquals(fieldValues.size(), 1);
    } else {
        try {
            ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, style);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKLocalDateTime.java   
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), LocalDateTime.of(2012, 3, 4, 23, 5, 0, 0), null},
            {LocalDateTime.of(2012, Month.MARCH, 4, 0, 0), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), LocalDateTime.of(2012, 3, 4, 0, 0), null},
            {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MAX, LocalDateTime.of(2012, 3, 4, 23, 5), null},
            {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MIN, LocalDateTime.of(2012, 3, 4, 23, 5), null},
            {LocalDateTime.MAX, LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MAX, null},
            {LocalDateTime.MIN, LocalDateTime.of(2012, 3, 4, 23, 5), LocalDateTime.MIN, null},

            {LocalDateTime.of(2012, 3, 4, 23, 5), OffsetDateTime.of(2210, 2, 2, 0, 0, 0, 0, ZoneOffset.UTC), OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, ZoneOffset.UTC), null},
            {LocalDateTime.of(2012, 3, 4, 23, 5), OffsetDateTime.of(2210, 2, 2, 0, 0, 0, 0, OFFSET_PONE), OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), null},
            {LocalDateTime.of(2012, 3, 4, 23, 5), ZonedDateTime.of(2210, 2, 2, 0, 0, 0, 0, ZONE_PARIS), ZonedDateTime.of(2012, 3, 4, 23, 5, 0, 0, ZONE_PARIS), null},

            {LocalDateTime.of(2012, 3, 4, 23, 5), LocalDate.of(2210, 2, 2), null, DateTimeException.class},
            {LocalDateTime.of(2012, 3, 4, 23, 5), LocalTime.of(22, 3, 0), null, DateTimeException.class},
            {LocalDateTime.of(2012, 3, 4, 23, 5), OffsetTime.of(22, 3, 0, 0, ZoneOffset.UTC), null, DateTimeException.class},
            {LocalDateTime.of(2012, 3, 4, 23, 5), null, null, NullPointerException.class},

    };
}
项目:jdk8u-jdk    文件:TCKInstant.java   
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {Instant.ofEpochSecond(10, 200), Instant.ofEpochSecond(20), Instant.ofEpochSecond(10, 200), null},
            {Instant.ofEpochSecond(10, -200), Instant.now(), Instant.ofEpochSecond(10, -200), null},
            {Instant.ofEpochSecond(-10), Instant.EPOCH, Instant.ofEpochSecond(-10), null},
            {Instant.ofEpochSecond(10), Instant.MIN, Instant.ofEpochSecond(10), null},
            {Instant.ofEpochSecond(10), Instant.MAX, Instant.ofEpochSecond(10), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20).toInstant(ZoneOffset.UTC), Instant.ofEpochSecond(10, 200), null},
            {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZoneOffset.UTC), OffsetDateTime.of(1970, 1, 1, 0, 0, 10, 200, ZoneOffset.UTC), null},
            {Instant.ofEpochSecond(10, 200), OffsetDateTime.of(1970, 1, 1, 0, 0, 20, 10, OFFSET_PTWO), OffsetDateTime.of(1970, 1, 1, 2, 0, 10, 200, OFFSET_PTWO), null},
            {Instant.ofEpochSecond(10, 200), ZonedDateTime.of(1970, 1, 1, 0, 0, 20, 10, ZONE_PARIS), ZonedDateTime.of(1970, 1, 1, 1, 0, 10, 200, ZONE_PARIS), null},

            {Instant.ofEpochSecond(10, 200), LocalDateTime.of(1970, 1, 1, 0, 0, 20), null, DateTimeException.class},
            {Instant.ofEpochSecond(10, 200), null, null, NullPointerException.class},

    };
}
项目:jdk8u-jdk    文件:Parsed.java   
private void crossCheck(TemporalAccessor target) {
    for (Iterator<Entry<TemporalField, Long>> it = fieldValues.entrySet().iterator(); it.hasNext(); ) {
        Entry<TemporalField, Long> entry = it.next();
        TemporalField field = entry.getKey();
        if (target.isSupported(field)) {
            long val1;
            try {
                val1 = target.getLong(field);
            } catch (RuntimeException ex) {
                continue;
            }
            long val2 = entry.getValue();
            if (val1 != val2) {
                throw new DateTimeException("Conflict found: Field " + field + " " + val1 +
                        " differs from " + field + " " + val2 + " derived from " + target);
            }
            it.remove();
        }
    }
}
项目:openjdk-jdk10    文件:TCKIsoChronology.java   
@Test(dataProvider = "resolve_yd")
public void test_resolve_yd_smart(int y, int d, LocalDate expected, boolean smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
    if (smart) {
        LocalDate date = IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            IsoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:openjdk-jdk10    文件:TCKOffsetTime.java   
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(LocalTime.of(1, 1, 1, 100), ZoneOffset.UTC), OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.MAX, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.MIN, OffsetTime.of(LocalTime.of(23 , 5), OFFSET_PONE), null},
            {OffsetTime.MAX, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(OffsetTime.MAX.toLocalTime(), ZoneOffset.ofHours(-18)), null},
            {OffsetTime.MIN, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(OffsetTime.MIN.toLocalTime(), ZoneOffset.ofHours(18)), null},


            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), ZonedDateTime.of(LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), ZONE_GAZA), ZonedDateTime.of(LocalDateTime.of(2012, 3, 4, 23, 5), ZONE_GAZA), null},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetDateTime.of(LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), ZoneOffset.UTC), OffsetDateTime.of(LocalDateTime.of(2012, 3, 4, 23, 5), OFFSET_PONE), null},

            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), null, DateTimeException.class},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalDate.of(2210, 2, 2), null, DateTimeException.class},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalTime.of(22, 3, 0), null, DateTimeException.class},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null, null, NullPointerException.class},

    };
}
项目:jdk8u-jdk    文件:TCKOffsetDateTime.java   
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), OffsetDateTime.of(2012, 3, 4, 1, 1, 1, 100, ZoneOffset.UTC), OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), null},
            {OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), OffsetDateTime.MAX, OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), null},
            {OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), OffsetDateTime.MIN, OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), null},
            {OffsetDateTime.MAX, OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), OffsetDateTime.of(OffsetDateTime.MAX.toLocalDateTime(), ZoneOffset.ofHours(-18)), null},
            {OffsetDateTime.MIN, OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), OffsetDateTime.of(OffsetDateTime.MIN.toLocalDateTime(), ZoneOffset.ofHours(18)), null},


            {OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE),
                    ZonedDateTime.of(2012, 3, 4, 1, 1, 1, 100, ZONE_GAZA), ZonedDateTime.of(2012, 3, 4, 23, 5, 0, 0, ZONE_GAZA), null},

            {OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), null, DateTimeException.class},
            {OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), LocalDate.of(2210, 2, 2), null, DateTimeException.class},
            {OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), LocalTime.of(22, 3, 0), null, DateTimeException.class},
            {OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), OffsetTime.of(22, 3, 0, 0, ZoneOffset.UTC), null, DateTimeException.class},
            {OffsetDateTime.of(2012, 3, 4, 23, 5, 0, 0, OFFSET_PONE), null, null, NullPointerException.class},

    };
}
项目:optashift-employee-rostering    文件:ChronoZonedDateTimeImpl.java   
@Override
public long periodUntil(DateTime endDateTime, PeriodUnit unit) {

  if (endDateTime instanceof ChronoZonedDateTime == false) {
    throw new DateTimeException("Unable to calculate period between objects of two different types");
  }
  @SuppressWarnings("unchecked")
  ChronoZonedDateTime<C> end = (ChronoZonedDateTime<C>) endDateTime;
  if (getDate().getChrono().equals(end.getDate().getChrono()) == false) {
    throw new DateTimeException("Unable to calculate period between two different chronologies");
  }
  if (unit instanceof ChronoUnit) {
    end = end.withZoneSameInstant(this.offset);
    return this.dateTime.periodUntil(end.getDateTime(), unit);
  }
  return unit.between(this, endDateTime).getAmount();
}
项目:jdk8u-jdk    文件:TCKWeekFields.java   
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoy_strict(DayOfWeek firstDayOfWeek, int minDays) {
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField woyField = week.weekOfYear();
    DateTimeFormatter f = new DateTimeFormatterBuilder()
            .appendValue(YEAR).appendLiteral(':')
            .appendValue(woyField).appendLiteral(':')
            .appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(STRICT);
    String str = "2012:0:1";
    try {
        LocalDate date = LocalDate.parse(str, f);
        assertEquals(date.getYear(), 2012);
        assertEquals(date.get(woyField), 0);
        assertEquals(date.get(DAY_OF_WEEK), 1);
    } catch (DateTimeException ex) {
        // expected
    }
}
项目:optashift-employee-rostering    文件:Chrono.java   
/**
 * Creates a zoned date-time in this chronology from another date-time object.
 * <p>
 * This creates a date-time in this chronology based on the specified {@code DateTimeAccessor}.
 * <p>
 * This should obtain a {@code ZoneId} using {@link ZoneId#from(DateTimeAccessor)}. The date-time should be
 * obtained by obtaining an {@code Instant}. If that fails, the local date-time should be used.
 * 
 * @param dateTime the date-time object to convert, not null
 * @return the zoned date-time in this chronology, not null
 * @throws DateTimeException if unable to create the date-time
 */
public ChronoZonedDateTime<C> zonedDateTime(DateTimeAccessor dateTime) {

  try {
    ZoneId zoneId = ZoneId.from(dateTime);
    ChronoDateTimeImpl<C> cldt;
    try {
      Instant instant = Instant.from(dateTime);
      cldt = localInstant(instant, zoneId);
    } catch (DateTimeException ex1) {
      cldt = ensureChronoLocalDateTime(localDateTime(dateTime));
    }
    return ChronoZonedDateTimeImpl.ofBest(cldt, zoneId, null);
  } catch (DateTimeException ex) {
    throw new DateTimeException("Unable to convert DateTimeAccessor to ZonedDateTime: " + dateTime.getClass(), ex);
  }
}
项目:openjdk-jdk10    文件:TCKThaiBuddhistChronology.java   
@Test(dataProvider = "resolve_ymaa")
public void test_resolve_ymaa_smart(int y, int m, int w, int d, ThaiBuddhistDate expected, boolean smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.ALIGNED_WEEK_OF_MONTH, (long) w);
    fieldValues.put(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, (long) d);
    if (smart) {
        ThaiBuddhistDate date = ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            ThaiBuddhistChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKOffsetTime.java   
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(LocalTime.of(1, 1, 1, 100), ZoneOffset.UTC), OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.MAX, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.MIN, OffsetTime.of(LocalTime.of(23 , 5), OFFSET_PONE), null},
            {OffsetTime.MAX, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(OffsetTime.MAX.toLocalTime(), ZoneOffset.ofHours(-18)), null},
            {OffsetTime.MIN, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(OffsetTime.MIN.toLocalTime(), ZoneOffset.ofHours(18)), null},


            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), ZonedDateTime.of(LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), ZONE_GAZA), ZonedDateTime.of(LocalDateTime.of(2012, 3, 4, 23, 5), ZONE_GAZA), null},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetDateTime.of(LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), ZoneOffset.UTC), OffsetDateTime.of(LocalDateTime.of(2012, 3, 4, 23, 5), OFFSET_PONE), null},

            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), null, DateTimeException.class},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalDate.of(2210, 2, 2), null, DateTimeException.class},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalTime.of(22, 3, 0), null, DateTimeException.class},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null, null, NullPointerException.class},

    };
}
项目:openjdk-jdk10    文件:TestUmmAlQuraChronology.java   
@DataProvider(name="zonedDateTime")
Object[][] data_zonedDateTime() {
    return new Object[][] {
        {ZonedDateTime.of(2012, 2, 29, 2, 7, 1, 1, ZONE_RIYADH), HijrahChronology.INSTANCE.date(1433, 4, 7), LocalTime.of(2, 7, 1, 1), null},
        {OffsetDateTime.of(2012, 2, 29, 2, 7, 1, 1, OFFSET_PTWO), HijrahChronology.INSTANCE.date(1433, 4, 7), LocalTime.of(2, 7, 1, 1), null},
        {LocalDateTime.of(2012, 2, 29, 2, 7), null, null, DateTimeException.class},
        {JapaneseDate.of(2012, 2, 29), null, null, DateTimeException.class},
        {ThaiBuddhistDate.of(2012 + 543, 2, 29), null, null, DateTimeException.class},
        {LocalDate.of(2012, 2, 29), null, null, DateTimeException.class},
        {LocalTime.of(20, 30, 29, 0), null, null, DateTimeException.class},
    };
}
项目:openjdk-jdk10    文件:TCKZonedDateTime.java   
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofStrict_LDT_ZI_ZO_inGap() {
    try {
        ZonedDateTime.ofStrict(TEST_PARIS_GAP_2008_03_30_02_30, OFFSET_0100, ZONE_PARIS);
    } catch (DateTimeException ex) {
        assertEquals(ex.getMessage().contains(" gap"), true);
        throw ex;
    }
}
项目:jdk8u-jdk    文件:HijrahChronology.java   
/**
 * Returns month length for the year and month.
 *
 * @param prolepticYear a proleptic year
 * @param monthOfYear a month, 1-origin.
 * @return the length of the month
 */
int getMonthLength(int prolepticYear, int monthOfYear) {
    int epochMonth = yearToEpochMonth(prolepticYear) + (monthOfYear - 1);
    if (epochMonth < 0 || epochMonth >= hijrahEpochMonthStartDays.length) {
        throw new DateTimeException("Invalid Hijrah date, year: " +
                prolepticYear +  ", month: " + monthOfYear);
    }
    return epochMonthLength(epochMonth);
}
项目:openjdk-jdk10    文件:TCKZonedDateTime.java   
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofStrict_LDT_ZI_ZO_invalidOffset() {
    try {
        ZonedDateTime.ofStrict(TEST_LOCAL_2008_06_30_11_30_59_500, OFFSET_0130, ZONE_PARIS);
    } catch (DateTimeException ex) {
        assertEquals(ex.getMessage().contains(" is not valid for "), true);
        throw ex;
    }
}
项目:jdk8u-jdk    文件:TCKChronoPeriod.java   
@Test(dataProvider="calendars", expectedExceptions=DateTimeException.class)
public void test_plus_wrongChrono(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoPeriod isoPeriod = Period.of(2, 3, 4);
    ChronoPeriod thaiPeriod = ThaiBuddhistChronology.INSTANCE.period(2, 3, 4);
    // one of these two will fail
    period.plus(isoPeriod);
    period.plus(thaiPeriod);
}
项目:jdk8u-jdk    文件:TCKYearMonth.java   
@DataProvider(name="plus_long_TemporalUnit")
Object[][] data_plus_long_TemporalUnit() {
    return new Object[][] {
        {YearMonth.of(1, 10), 1, ChronoUnit.YEARS, YearMonth.of(2, 10), null},
        {YearMonth.of(1, 10), -12, ChronoUnit.YEARS, YearMonth.of(-11, 10), null},
        {YearMonth.of(1, 10), 0, ChronoUnit.YEARS, YearMonth.of(1, 10), null},
        {YearMonth.of(999999999, 12), 0, ChronoUnit.YEARS, YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), 0, ChronoUnit.YEARS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 1), -999999999, ChronoUnit.YEARS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(0, 12), 999999999, ChronoUnit.YEARS, YearMonth.of(999999999, 12), null},

        {YearMonth.of(1, 10), 1, ChronoUnit.MONTHS, YearMonth.of(1, 11), null},
        {YearMonth.of(1, 10), -12, ChronoUnit.MONTHS, YearMonth.of(0, 10), null},
        {YearMonth.of(1, 10), 0, ChronoUnit.MONTHS, YearMonth.of(1, 10), null},
        {YearMonth.of(999999999, 12), 0, ChronoUnit.MONTHS, YearMonth.of(999999999, 12), null},
        {YearMonth.of(-999999999, 1), 0, ChronoUnit.MONTHS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(-999999999, 2), -1, ChronoUnit.MONTHS, YearMonth.of(-999999999, 1), null},
        {YearMonth.of(999999999, 3), 9, ChronoUnit.MONTHS, YearMonth.of(999999999, 12), null},

        {YearMonth.of(-1, 10), 1, ChronoUnit.ERAS, YearMonth.of(2, 10), null},
        {YearMonth.of(5, 10), 1, ChronoUnit.CENTURIES, YearMonth.of(105, 10), null},
        {YearMonth.of(5, 10), 1, ChronoUnit.DECADES, YearMonth.of(15, 10), null},

        {YearMonth.of(999999999, 12), 1, ChronoUnit.MONTHS, null, DateTimeException.class},
        {YearMonth.of(-999999999, 1), -1, ChronoUnit.MONTHS, null, DateTimeException.class},

        {YearMonth.of(1, 1), 0, ChronoUnit.DAYS, null, DateTimeException.class},
        {YearMonth.of(1, 1), 0, ChronoUnit.WEEKS, null, DateTimeException.class},
    };
}
项目:openjdk-jdk10    文件:TestOffsetDateTime_instants.java   
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofInstant_tooBig() {
    long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
    long year = Year.MAX_VALUE + 1L;
    long days = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970;
    Instant instant = Instant.ofEpochSecond(days * 24L * 60L * 60L);
    OffsetDateTime.ofInstant(instant, ZoneOffset.UTC);
}
项目:openjdk-jdk10    文件:TCKDateTimeFormatters.java   
@DataProvider(name="sample_isoTime")
Object[][] provider_sample_isoTime() {
    return new Object[][]{
            {11, null, null, null, null, null, null, DateTimeException.class},
            {null, 5, null, null, null, null, null, DateTimeException.class},
            {null, null, 30, null, null, null, null, DateTimeException.class},
            {null, null, null, 1, null, null, null, DateTimeException.class},
            {null, null, null, null, "+01:00", null, null, DateTimeException.class},
            {null, null, null, null, null, "Europe/Paris", null, DateTimeException.class},

            {11, 5, null, null, null, null,     "11:05", null},
            {11, 5, 30, null, null, null,       "11:05:30", null},
            {11, 5, 30, 500000000, null, null,  "11:05:30.5", null},
            {11, 5, 30, 1, null, null,          "11:05:30.000000001", null},

            {11, 5, null, null, "+01:00", null,     "11:05+01:00", null},
            {11, 5, 30, null, "+01:00", null,       "11:05:30+01:00", null},
            {11, 5, 30, 500000000, "+01:00", null,  "11:05:30.5+01:00", null},
            {11, 5, 30, 1, "+01:00", null,          "11:05:30.000000001+01:00", null},

            {11, 5, null, null, "+01:00", "Europe/Paris",       "11:05+01:00", null},
            {11, 5, 30, null, "+01:00", "Europe/Paris",         "11:05:30+01:00", null},
            {11, 5, 30, 500000000, "+01:00", "Europe/Paris",    "11:05:30.5+01:00", null},
            {11, 5, 30, 1, "+01:00", "Europe/Paris",            "11:05:30.000000001+01:00", null},

            {11, 5, null, null, null, "Europe/Paris",       "11:05", null},
            {11, 5, 30, null, null, "Europe/Paris",         "11:05:30", null},
            {11, 5, 30, 500000000, null, "Europe/Paris",    "11:05:30.5", null},
            {11, 5, 30, 1, null, "Europe/Paris",            "11:05:30.000000001", null},
    };
}
项目:OpenJSharp    文件:Parsed.java   
private void updateCheckConflict(LocalTime timeToSet, Period periodToSet) {
    if (time != null) {
        if (time.equals(timeToSet) == false) {
            throw new DateTimeException("Conflict found: Fields resolved to different times: " + time + " " + timeToSet);
        }
        if (excessDays.isZero() == false && periodToSet.isZero() == false && excessDays.equals(periodToSet) == false) {
            throw new DateTimeException("Conflict found: Fields resolved to different excess periods: " + excessDays + " " + periodToSet);
        } else {
            excessDays = periodToSet;
        }
    } else {
        time = timeToSet;
        excessDays = periodToSet;
    }
}
项目:jdk8u-jdk    文件:JapaneseEra.java   
/**
 * Obtains an instance of {@code JapaneseEra} from a date.
 *
 * @param date  the date, not null
 * @return the Era singleton, never null
 */
static JapaneseEra from(LocalDate date) {
    if (date.isBefore(MEIJI_6_ISODATE)) {
        throw new DateTimeException("JapaneseDate before Meiji 6 are not supported");
    }
    for (int i = KNOWN_ERAS.length - 1; i > 0; i--) {
        JapaneseEra era = KNOWN_ERAS[i];
        if (date.compareTo(era.since) >= 0) {
            return era;
        }
    }
    return null;
}
项目:openjdk-jdk10    文件:HijrahChronology.java   
/**
 * Return the epoch day computed from Hijrah year, month, and day.
 *
 * @param prolepticYear the year to represent, 0-origin
 * @param monthOfYear the month-of-year to represent, 1-origin
 * @param dayOfMonth the day-of-month to represent, 1-origin
 * @return the epoch day
 */
long getEpochDay(int prolepticYear, int monthOfYear, int dayOfMonth) {
    checkCalendarInit();    // ensure that the chronology is initialized
    checkValidMonth(monthOfYear);
    int epochMonth = yearToEpochMonth(prolepticYear) + (monthOfYear - 1);
    if (epochMonth < 0 || epochMonth >= hijrahEpochMonthStartDays.length) {
        throw new DateTimeException("Invalid Hijrah date, year: " +
                prolepticYear +  ", month: " + monthOfYear);
    }
    if (dayOfMonth < 1 || dayOfMonth > getMonthLength(prolepticYear, monthOfYear)) {
        throw new DateTimeException("Invalid Hijrah day of month: " + dayOfMonth);
    }
    return epochMonthToEpochDay(epochMonth) + (dayOfMonth - 1);
}
项目:OperatieBRP    文件:DatumFormatterUtil.java   
private boolean isGeldigeKalendarDatum() {
    try {
        if (isJaarOnbekend || isMaandOnbekend) {
            return true;
        } else if (isDagOnbekend) {
            YearMonth.parse(jaar + maand, FORMATTER_JAAR_MND);
        } else {
            LocalDate.parse(jaar + maand + dag, DateTimeFormatter.BASIC_ISO_DATE);
        }
    } catch (final DateTimeException e) {
        LOG.trace("Fout bij het parsen van datum " + this, e);
        return false;
    }
    return true;
}
项目:OperatieBRP    文件:DatumElement.java   
private boolean bepaalGeldigeKalenderDatum() {
    try {
        LocalDate.from(DATE_FORMATTER.parse(String.valueOf(getWaarde())));
        return true;
    } catch (DateTimeException e) {
        LOG.trace("Datum voldoet niet aan de Gregoriaanse kalender", e);
        return false;
    }
}
项目:openjdk-jdk10    文件:TCKZonedDateTime.java   
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofInstant_tooLow() {
    long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
    int year = Year.MIN_VALUE - 1;
    long days = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970;
    Instant instant = Instant.ofEpochSecond(days * 24L * 60L * 60L);
    ZonedDateTime.ofInstant(instant, ZoneOffset.UTC);
}
项目:openjdk-jdk10    文件:TCKLocalDateTime.java   
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_5intsMonth_hourTooLow() {
    LocalDateTime.of(2007, Month.JULY, 15, -1, 30, 40);
}
项目:openjdk-jdk10    文件:TCKLocalDateTime.java   
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_6intsMonth_yearTooLow() {
    LocalDateTime.of(Integer.MIN_VALUE, Month.JULY, 15, 12, 30, 40, 987654321);
}
项目:jdk8u-jdk    文件:TCKLocalDateTime.java   
@Test(expectedExceptions=DateTimeException.class)
public void test_from_TemporalAccessor_invalid_noDerive() {
    LocalDateTime.from(LocalTime.of(12, 30));
}
项目:jdk8u-jdk    文件:TCKLocalDateTime.java   
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_6ints_minuteTooHigh() {
    LocalDateTime.of(2007, 7, 15, 12, 60, 40);
}
项目:jdk8u-jdk    文件:TCKLocalDate.java   
@Test(expectedExceptions=DateTimeException.class )
public void test_with_TemporalField_long_invalidValue() {
    TEST_2007_07_15.with(ChronoField.DAY_OF_WEEK, -1);
}
项目:jdk8u-jdk    文件:TCKLocalDateTime.java   
@Test(expectedExceptions=DateTimeException.class)
public void test_minusDays_invalidTooSmall() {
    createDateMidnight(Year.MIN_VALUE, 1, 1).minusDays(1);
}
项目:jdk8u-jdk    文件:TCKLocalDateTime.java   
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_5ints_hourTooLow() {
    LocalDateTime.of(2007, 7, 15, -1, 30);
}