Java 类java.time.chrono.Chrono 实例源码

项目:optashift-employee-rostering    文件:Period.java   
/**
 * Adds this period to the specified date-time object.
 * <p>
 * This method is not intended to be called by application code directly. Applications should use the
 * {@code plus(PlusAdjuster)} method on the date-time object passing this period as the argument.
 * <p>
 * The calculation will add the years, then months, then days, then nanos. Only non-zero amounts will be
 * added. If the date-time has a calendar system with a fixed number of months in a year, then the years and
 * months will be combined before being added.
 * 
 * @param dateTime the date-time object to adjust, not null
 * @return an object of the same type with the adjustment made, not null
 * @throws DateTimeException if unable to add
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public DateTime doPlusAdjustment(DateTime dateTime) {

  if ((this.years | this.months) != 0) {
    DateTimeValueRange startRange = Chrono.from(dateTime).range(MONTH_OF_YEAR);
    if (startRange.isFixed() && startRange.isIntValue()) {
      long monthCount = startRange.getMaximum() - startRange.getMinimum() + 1;
      dateTime = dateTime.plus(this.years * monthCount + this.months, MONTHS);
    } else {
      if (this.years != 0) {
        dateTime = dateTime.plus(this.years, YEARS);
      }
      if (this.months != 0) {
        dateTime = dateTime.plus(this.months, MONTHS);
      }
    }
  }
  if (this.days != 0) {
    dateTime = dateTime.plus(this.days, DAYS);
  }
  if (this.nanos != 0) {
    dateTime = dateTime.plus(this.nanos, NANOS);
  }
  return dateTime;
}
项目:optashift-employee-rostering    文件:Period.java   
/**
 * Subtracts this period from the specified date-time object.
 * <p>
 * This method is not intended to be called by application code directly. Applications should use the
 * {@code minus(MinusAdjuster)} method on the date-time object passing this period as the argument.
 * <p>
 * The calculation will subtract the years, then months, then days, then nanos. Only non-zero amounts will
 * be subtracted. If the date-time has a calendar system with a fixed number of months in a year, then the
 * years and months will be combined before being subtracted.
 * 
 * @param dateTime the date-time object to adjust, not null
 * @return an object of the same type with the adjustment made, not null
 * @throws DateTimeException if unable to subtract
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public DateTime doMinusAdjustment(DateTime dateTime) {

  if ((this.years | this.months) != 0) {
    DateTimeValueRange startRange = Chrono.from(dateTime).range(MONTH_OF_YEAR);
    if (startRange.isFixed() && startRange.isIntValue()) {
      long monthCount = startRange.getMaximum() - startRange.getMinimum() + 1;
      dateTime = dateTime.minus(this.years * monthCount + this.months, MONTHS);
    } else {
      if (this.years != 0) {
        dateTime = dateTime.minus(this.years, YEARS);
      }
      if (this.months != 0) {
        dateTime = dateTime.minus(this.months, MONTHS);
      }
    }
  }
  if (this.days != 0) {
    dateTime = dateTime.minus(this.days, DAYS);
  }
  if (this.nanos != 0) {
    dateTime = dateTime.minus(this.nanos, NANOS);
  }
  return dateTime;
}
项目:gwt-time    文件:Period.java   
/**
 * Adds this period to the specified date-time object.
 * <p>
 * This method is not intended to be called by application code directly. Applications should use the
 * {@code plus(PlusAdjuster)} method on the date-time object passing this period as the argument.
 * <p>
 * The calculation will add the years, then months, then days, then nanos. Only non-zero amounts will be
 * added. If the date-time has a calendar system with a fixed number of months in a year, then the years and
 * months will be combined before being added.
 * 
 * @param dateTime the date-time object to adjust, not null
 * @return an object of the same type with the adjustment made, not null
 * @throws DateTimeException if unable to add
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public DateTime doPlusAdjustment(DateTime dateTime) {

  if ((this.years | this.months) != 0) {
    DateTimeValueRange startRange = Chrono.from(dateTime).range(MONTH_OF_YEAR);
    if (startRange.isFixed() && startRange.isIntValue()) {
      long monthCount = startRange.getMaximum() - startRange.getMinimum() + 1;
      dateTime = dateTime.plus(this.years * monthCount + this.months, MONTHS);
    } else {
      if (this.years != 0) {
        dateTime = dateTime.plus(this.years, YEARS);
      }
      if (this.months != 0) {
        dateTime = dateTime.plus(this.months, MONTHS);
      }
    }
  }
  if (this.days != 0) {
    dateTime = dateTime.plus(this.days, DAYS);
  }
  if (this.nanos != 0) {
    dateTime = dateTime.plus(this.nanos, NANOS);
  }
  return dateTime;
}
项目:gwt-time    文件:Period.java   
/**
 * Subtracts this period from the specified date-time object.
 * <p>
 * This method is not intended to be called by application code directly. Applications should use the
 * {@code minus(MinusAdjuster)} method on the date-time object passing this period as the argument.
 * <p>
 * The calculation will subtract the years, then months, then days, then nanos. Only non-zero amounts will
 * be subtracted. If the date-time has a calendar system with a fixed number of months in a year, then the
 * years and months will be combined before being subtracted.
 * 
 * @param dateTime the date-time object to adjust, not null
 * @return an object of the same type with the adjustment made, not null
 * @throws DateTimeException if unable to subtract
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public DateTime doMinusAdjustment(DateTime dateTime) {

  if ((this.years | this.months) != 0) {
    DateTimeValueRange startRange = Chrono.from(dateTime).range(MONTH_OF_YEAR);
    if (startRange.isFixed() && startRange.isIntValue()) {
      long monthCount = startRange.getMaximum() - startRange.getMinimum() + 1;
      dateTime = dateTime.minus(this.years * monthCount + this.months, MONTHS);
    } else {
      if (this.years != 0) {
        dateTime = dateTime.minus(this.years, YEARS);
      }
      if (this.months != 0) {
        dateTime = dateTime.minus(this.months, MONTHS);
      }
    }
  }
  if (this.days != 0) {
    dateTime = dateTime.minus(this.days, DAYS);
  }
  if (this.nanos != 0) {
    dateTime = dateTime.minus(this.nanos, NANOS);
  }
  return dateTime;
}
项目:java8-backports    文件:Period.java   
/**
 * Adds this period to the specified date-time object.
 * <p>
 * This method is not intended to be called by application code directly. Applications should use the
 * {@code plus(PlusAdjuster)} method on the date-time object passing this period as the argument.
 * <p>
 * The calculation will add the years, then months, then days, then nanos. Only non-zero amounts will be
 * added. If the date-time has a calendar system with a fixed number of months in a year, then the years and
 * months will be combined before being added.
 * 
 * @param dateTime the date-time object to adjust, not null
 * @return an object of the same type with the adjustment made, not null
 * @throws DateTimeException if unable to add
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public DateTime doPlusAdjustment(DateTime dateTime) {

  if ((this.years | this.months) != 0) {
    DateTimeValueRange startRange = Chrono.from(dateTime).range(MONTH_OF_YEAR);
    if (startRange.isFixed() && startRange.isIntValue()) {
      long monthCount = startRange.getMaximum() - startRange.getMinimum() + 1;
      dateTime = dateTime.plus(this.years * monthCount + this.months, MONTHS);
    } else {
      if (this.years != 0) {
        dateTime = dateTime.plus(this.years, YEARS);
      }
      if (this.months != 0) {
        dateTime = dateTime.plus(this.months, MONTHS);
      }
    }
  }
  if (this.days != 0) {
    dateTime = dateTime.plus(this.days, DAYS);
  }
  if (this.nanos != 0) {
    dateTime = dateTime.plus(this.nanos, NANOS);
  }
  return dateTime;
}
项目:java8-backports    文件:Period.java   
/**
 * Subtracts this period from the specified date-time object.
 * <p>
 * This method is not intended to be called by application code directly. Applications should use the
 * {@code minus(MinusAdjuster)} method on the date-time object passing this period as the argument.
 * <p>
 * The calculation will subtract the years, then months, then days, then nanos. Only non-zero amounts will
 * be subtracted. If the date-time has a calendar system with a fixed number of months in a year, then the
 * years and months will be combined before being subtracted.
 * 
 * @param dateTime the date-time object to adjust, not null
 * @return an object of the same type with the adjustment made, not null
 * @throws DateTimeException if unable to subtract
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public DateTime doMinusAdjustment(DateTime dateTime) {

  if ((this.years | this.months) != 0) {
    DateTimeValueRange startRange = Chrono.from(dateTime).range(MONTH_OF_YEAR);
    if (startRange.isFixed() && startRange.isIntValue()) {
      long monthCount = startRange.getMaximum() - startRange.getMinimum() + 1;
      dateTime = dateTime.minus(this.years * monthCount + this.months, MONTHS);
    } else {
      if (this.years != 0) {
        dateTime = dateTime.minus(this.years, YEARS);
      }
      if (this.months != 0) {
        dateTime = dateTime.minus(this.months, MONTHS);
      }
    }
  }
  if (this.days != 0) {
    dateTime = dateTime.minus(this.days, DAYS);
  }
  if (this.nanos != 0) {
    dateTime = dateTime.minus(this.nanos, NANOS);
  }
  return dateTime;
}
项目:java8-backports    文件:UsabilityChrono.java   
private static void newPackagePluggable() {

    Chrono<?> chrono = MinguoChrono.INSTANCE;

    ChronoLocalDate<?> date = chrono.dateNow();
    System.out.printf("now: %s%n", date);

    date = date.with(DAY_OF_MONTH, 1);
    System.out.printf("first of month: %s%n", date);

    int month = date.get(ChronoField.MONTH_OF_YEAR);
    date = date.with(DAY_OF_WEEK, 1);
    System.out.printf("start of first week: %s%n", date);

    while (date.get(ChronoField.MONTH_OF_YEAR) <= month) {
      String row = "";
      for (int i = 0; i < 7; i++) {
        row += date.get(ChronoField.DAY_OF_MONTH) + " ";
        date = date.plus(1, ChronoUnit.DAYS);
      }
      System.out.println(row);
    }
  }
项目:java8-backports    文件:UsabilityChrono.java   
/**
 * Print a month calendar with complete week rows.
 * 
 * @param date A date in some calendar
 * @param out a PrintStream
 */
private static <C extends Chrono<C>> void printMonthCal(ChronoLocalDate<C> date, PrintStream out) {

  int lengthOfMonth = date.lengthOfMonth();
  ChronoLocalDate<C> end = date.with(ChronoField.DAY_OF_MONTH, lengthOfMonth);
  end = end.plus(7 - end.get(ChronoField.DAY_OF_WEEK), ChronoUnit.DAYS);
  // Back up to the beginning of the week including the 1st of the month
  ChronoLocalDate<C> start = date.with(ChronoField.DAY_OF_MONTH, 1);
  start = start.minus(start.get(ChronoField.DAY_OF_WEEK), ChronoUnit.DAYS);

  out.printf("%9s Month %2d, %4d%n", date.getChrono().getId(), date.get(ChronoField.MONTH_OF_YEAR),
      date.get(ChronoField.YEAR));
  String[] colText = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
  printMonthRow(colText, " ", out);

  String[] cell = new String[7];
  for (; start.compareTo(end) <= 0; start = start.plus(1, ChronoUnit.DAYS)) {
    int ndx = start.get(ChronoField.DAY_OF_WEEK) - 1;
    cell[ndx] = Integer.toString(start.get(ChronoField.DAY_OF_MONTH));
    if (ndx == 6) {
      printMonthRow(cell, "|", out);
    }
  }
}
项目:java8-backports    文件:TestChronoZonedDateTime.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badWithAdjusterChrono(Chrono<?> chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoZonedDateTime czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
    DateTime.WithAdjuster adjuster = new FixedAdjuster(czdt2);
    if (chrono != chrono2) {
      try {
        czdt.with(adjuster);
        Assert.fail("WithAdjuster should have thrown a ClassCastException, " + "required: " + czdt + ", supplied: "
            + czdt2);
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      ChronoZonedDateTime<?> result = czdt.with(adjuster);
      assertEquals(result, czdt2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoZonedDateTime.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badPlusAdjusterChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoZonedDateTime czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
    DateTime.PlusAdjuster adjuster = new FixedAdjuster(czdt2);
    if (chrono != chrono2) {
      try {
        ChronoZonedDateTime<?> notreached = czdt.plus(adjuster);
        Assert.fail("WithAdjuster should have thrown a ClassCastException, " + "required: " + czdt + ", supplied: "
            + czdt2);
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoZonedDateTime<?> result = czdt.plus(adjuster);
      assertEquals(result, czdt2, "WithAdjuster failed to replace date time");
    }
  }
}
项目:java8-backports    文件:TestChronoZonedDateTime.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badMinusAdjusterChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoZonedDateTime czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
    DateTime.MinusAdjuster adjuster = new FixedAdjuster(czdt2);
    if (chrono != chrono2) {
      try {
        ChronoZonedDateTime<?> notreached = czdt.minus(adjuster);
        Assert.fail("WithAdjuster should have thrown a ClassCastException, " + "required: " + czdt + ", supplied: "
            + czdt2);
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoZonedDateTime<?> result = czdt.minus(adjuster);
      assertEquals(result, czdt2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoZonedDateTime.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badPlusPeriodUnitChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoZonedDateTime czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
    PeriodUnit adjuster = new FixedPeriodUnit(czdt2);
    if (chrono != chrono2) {
      try {
        ChronoZonedDateTime<?> notreached = czdt.plus(1, adjuster);
        Assert.fail("PeriodUnit.doPlus plus should have thrown a ClassCastException, " + czdt
            + " can not be cast to " + czdt2);
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoZonedDateTime<?> result = czdt.plus(1, adjuster);
      assertEquals(result, czdt2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoZonedDateTime.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badMinusPeriodUnitChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoZonedDateTime czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
    PeriodUnit adjuster = new FixedPeriodUnit(czdt2);
    if (chrono != chrono2) {
      try {
        ChronoZonedDateTime<?> notreached = czdt.minus(1, adjuster);
        Assert.fail("PeriodUnit.doPlus minus should have thrown a ClassCastException, " + czdt.getClass()
            + " can not be cast to " + czdt2.getClass());
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoZonedDateTime<?> result = czdt.minus(1, adjuster);
      assertEquals(result, czdt2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoZonedDateTime.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badDateTimeFieldChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoZonedDateTime czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
    DateTimeField adjuster = new FixedDateTimeField(czdt2);
    if (chrono != chrono2) {
      try {
        ChronoZonedDateTime<?> notreached = czdt.with(adjuster, 1);
        Assert.fail("DateTimeField doWith() should have thrown a ClassCastException, " + czdt.getClass()
            + " can not be cast to " + czdt2.getClass());
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoZonedDateTime<?> result = czdt.with(adjuster, 1);
      assertEquals(result, czdt2, "DateTimeField doWith() failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDate.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badWithAdjusterChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDate date = chrono.date(refDate);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDate<?> date2 = chrono2.date(refDate);
    DateTime.WithAdjuster adjuster = new FixedAdjuster(date2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDate<?> notreached = date.with(adjuster);
        Assert.fail("WithAdjuster should have thrown a ClassCastException");
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDate<?> result = date.with(adjuster);
      assertEquals(result, date2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDate.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badPlusAdjusterChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDate date = chrono.date(refDate);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDate<?> date2 = chrono2.date(refDate);
    DateTime.PlusAdjuster adjuster = new FixedAdjuster(date2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDate<?> notreached = date.plus(adjuster);
        Assert.fail("WithAdjuster should have thrown a ClassCastException");
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDate<?> result = date.plus(adjuster);
      assertEquals(result, date2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDate.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badMinusAdjusterChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDate date = chrono.date(refDate);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDate<?> date2 = chrono2.date(refDate);
    DateTime.MinusAdjuster adjuster = new FixedAdjuster(date2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDate<?> notreached = date.minus(adjuster);
        Assert.fail("WithAdjuster should have thrown a ClassCastException");
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDate<?> result = date.minus(adjuster);
      assertEquals(result, date2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDate.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badPlusPeriodUnitChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDate date = chrono.date(refDate);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDate<?> date2 = chrono2.date(refDate);
    PeriodUnit adjuster = new FixedPeriodUnit(date2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDate<?> notreached = date.plus(1, adjuster);
        Assert.fail("PeriodUnit.doPlus plus should have thrown a ClassCastException" + date.getClass()
            + ", can not be cast to " + date2.getClass());
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDate<?> result = date.plus(1, adjuster);
      assertEquals(result, date2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDate.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badMinusPeriodUnitChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDate date = chrono.date(refDate);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDate<?> date2 = chrono2.date(refDate);
    PeriodUnit adjuster = new FixedPeriodUnit(date2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDate<?> notreached = date.minus(1, adjuster);
        Assert.fail("PeriodUnit.doPlus minus should have thrown a ClassCastException" + date.getClass()
            + ", can not be cast to " + date2.getClass());
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDate<?> result = date.minus(1, adjuster);
      assertEquals(result, date2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDate.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badDateTimeFieldChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDate date = chrono.date(refDate);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDate<?> date2 = chrono2.date(refDate);
    DateTimeField adjuster = new FixedDateTimeField(date2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDate<?> notreached = date.with(adjuster, 1);
        Assert.fail("DateTimeField doWith() should have thrown a ClassCastException" + date.getClass()
            + ", can not be cast to " + date2.getClass());
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDate<?> result = date.with(adjuster, 1);
      assertEquals(result, date2, "DateTimeField doWith() failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDate.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badWithAdjusterChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDate date = chrono.date(refDate);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDate<?> date2 = chrono2.date(refDate);
    DateTime.WithAdjuster adjuster = new FixedAdjuster(date2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDate<?> notreached = date.with(adjuster);
        Assert.fail("WithAdjuster should have thrown a ClassCastException");
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDate<?> result = date.with(adjuster);
      assertEquals(result, date2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDate.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badPlusAdjusterChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDate date = chrono.date(refDate);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDate<?> date2 = chrono2.date(refDate);
    DateTime.PlusAdjuster adjuster = new FixedAdjuster(date2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDate<?> notreached = date.plus(adjuster);
        Assert.fail("WithAdjuster should have thrown a ClassCastException");
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDate<?> result = date.plus(adjuster);
      assertEquals(result, date2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDate.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badMinusAdjusterChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDate date = chrono.date(refDate);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDate<?> date2 = chrono2.date(refDate);
    DateTime.MinusAdjuster adjuster = new FixedAdjuster(date2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDate<?> notreached = date.minus(adjuster);
        Assert.fail("WithAdjuster should have thrown a ClassCastException");
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDate<?> result = date.minus(adjuster);
      assertEquals(result, date2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDate.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badPlusPeriodUnitChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDate date = chrono.date(refDate);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDate<?> date2 = chrono2.date(refDate);
    PeriodUnit adjuster = new FixedPeriodUnit(date2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDate<?> notreached = date.plus(1, adjuster);
        Assert.fail("PeriodUnit.doAdd plus should have thrown a ClassCastException" + date.getClass()
            + ", can not be cast to " + date2.getClass());
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDate<?> result = date.plus(1, adjuster);
      assertEquals(result, date2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDate.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badMinusPeriodUnitChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDate date = chrono.date(refDate);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDate<?> date2 = chrono2.date(refDate);
    PeriodUnit adjuster = new FixedPeriodUnit(date2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDate<?> notreached = date.minus(1, adjuster);
        Assert.fail("PeriodUnit.doAdd minus should have thrown a ClassCastException" + date.getClass()
            + ", can not be cast to " + date2.getClass());
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDate<?> result = date.minus(1, adjuster);
      assertEquals(result, date2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDate.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badDateTimeFieldChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDate date = chrono.date(refDate);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDate<?> date2 = chrono2.date(refDate);
    DateTimeField adjuster = new FixedDateTimeField(date2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDate<?> notreached = date.with(adjuster, 1);
        Assert.fail("DateTimeField doSet should have thrown a ClassCastException" + date.getClass()
            + ", can not be cast to " + date2.getClass());
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDate<?> result = date.with(adjuster, 1);
      assertEquals(result, date2, "DateTimeField doSet failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDateTime.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badWithAdjusterChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDateTime cdt = chrono.date(refDate).atTime(LocalTime.NOON);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
    DateTime.WithAdjuster adjuster = new FixedAdjuster(cdt2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDateTime<?> notreached = cdt.with(adjuster);
        Assert.fail("WithAdjuster should have thrown a ClassCastException, " + "required: " + cdt + ", supplied: "
            + cdt2);
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDateTime<?> result = cdt.with(adjuster);
      assertEquals(result, cdt2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDateTime.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badPlusAdjusterChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDateTime cdt = chrono.date(refDate).atTime(LocalTime.NOON);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
    DateTime.PlusAdjuster adjuster = new FixedAdjuster(cdt2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDateTime<?> notreached = cdt.plus(adjuster);
        Assert.fail("WithAdjuster should have thrown a ClassCastException, " + "required: " + cdt + ", supplied: "
            + cdt2);
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDateTime<?> result = cdt.plus(adjuster);
      assertEquals(result, cdt2, "WithAdjuster failed to replace date time");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDateTime.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badMinusAdjusterChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDateTime cdt = chrono.date(refDate).atTime(LocalTime.NOON);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
    DateTime.MinusAdjuster adjuster = new FixedAdjuster(cdt2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDateTime<?> notreached = cdt.minus(adjuster);
        Assert.fail("WithAdjuster should have thrown a ClassCastException, " + "required: " + cdt + ", supplied: "
            + cdt2);
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDateTime<?> result = cdt.minus(adjuster);
      assertEquals(result, cdt2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDateTime.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badPlusPeriodUnitChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDateTime cdt = chrono.date(refDate).atTime(LocalTime.NOON);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
    PeriodUnit adjuster = new FixedPeriodUnit(cdt2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDateTime<?> notreached = cdt.plus(1, adjuster);
        Assert.fail("PeriodUnit.doAdd plus should have thrown a ClassCastException" + cdt + ", can not be cast to "
            + cdt2);
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDateTime<?> result = cdt.plus(1, adjuster);
      assertEquals(result, cdt2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDateTime.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badMinusPeriodUnitChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDateTime cdt = chrono.date(refDate).atTime(LocalTime.NOON);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
    PeriodUnit adjuster = new FixedPeriodUnit(cdt2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDateTime<?> notreached = cdt.minus(1, adjuster);
        Assert.fail("PeriodUnit.doAdd minus should have thrown a ClassCastException" + cdt.getClass()
            + ", can not be cast to " + cdt2.getClass());
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDateTime<?> result = cdt.minus(1, adjuster);
      assertEquals(result, cdt2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDateTime.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badDateTimeFieldChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDateTime cdt = chrono.date(refDate).atTime(LocalTime.NOON);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
    DateTimeField adjuster = new FixedDateTimeField(cdt2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDateTime<?> notreached = cdt.with(adjuster, 1);
        Assert.fail("DateTimeField doSet should have thrown a ClassCastException" + cdt.getClass()
            + ", can not be cast to " + cdt2.getClass());
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDateTime<?> result = cdt.with(adjuster, 1);
      assertEquals(result, cdt2, "DateTimeField doSet failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDateTime.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badWithAdjusterChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDateTime cdt = chrono.date(refDate).atTime(LocalTime.NOON);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
    DateTime.WithAdjuster adjuster = new FixedAdjuster(cdt2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDateTime<?> notreached = cdt.with(adjuster);
        Assert.fail("WithAdjuster should have thrown a ClassCastException, " + "required: " + cdt + ", supplied: "
            + cdt2);
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDateTime<?> result = cdt.with(adjuster);
      assertEquals(result, cdt2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDateTime.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badPlusAdjusterChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDateTime cdt = chrono.date(refDate).atTime(LocalTime.NOON);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
    DateTime.PlusAdjuster adjuster = new FixedAdjuster(cdt2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDateTime<?> notreached = cdt.plus(adjuster);
        Assert.fail("WithAdjuster should have thrown a ClassCastException, " + "required: " + cdt + ", supplied: "
            + cdt2);
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDateTime<?> result = cdt.plus(adjuster);
      assertEquals(result, cdt2, "WithAdjuster failed to replace date time");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDateTime.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badMinusAdjusterChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDateTime cdt = chrono.date(refDate).atTime(LocalTime.NOON);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
    DateTime.MinusAdjuster adjuster = new FixedAdjuster(cdt2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDateTime<?> notreached = cdt.minus(adjuster);
        Assert.fail("WithAdjuster should have thrown a ClassCastException, " + "required: " + cdt + ", supplied: "
            + cdt2);
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDateTime<?> result = cdt.minus(adjuster);
      assertEquals(result, cdt2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDateTime.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badPlusPeriodUnitChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDateTime cdt = chrono.date(refDate).atTime(LocalTime.NOON);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
    PeriodUnit adjuster = new FixedPeriodUnit(cdt2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDateTime<?> notreached = cdt.plus(1, adjuster);
        Assert.fail("PeriodUnit.doPlus plus should have thrown a ClassCastException" + cdt + ", can not be cast to "
            + cdt2);
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDateTime<?> result = cdt.plus(1, adjuster);
      assertEquals(result, cdt2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDateTime.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badMinusPeriodUnitChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDateTime cdt = chrono.date(refDate).atTime(LocalTime.NOON);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
    PeriodUnit adjuster = new FixedPeriodUnit(cdt2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDateTime<?> notreached = cdt.minus(1, adjuster);
        Assert.fail("PeriodUnit.doPlus minus should have thrown a ClassCastException" + cdt.getClass()
            + ", can not be cast to " + cdt2.getClass());
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDateTime<?> result = cdt.minus(1, adjuster);
      assertEquals(result, cdt2, "WithAdjuster failed to replace date");
    }
  }
}
项目:java8-backports    文件:TestChronoLocalDateTime.java   
@Test(groups = { "tck" }, dataProvider = "calendars")
public void test_badDateTimeFieldChrono(Chrono chrono) {

  LocalDate refDate = LocalDate.of(1900, 1, 1);
  ChronoLocalDateTime cdt = chrono.date(refDate).atTime(LocalTime.NOON);
  for (Chrono[] clist : data_of_calendars()) {
    Chrono chrono2 = clist[0];
    ChronoLocalDateTime<?> cdt2 = chrono2.date(refDate).atTime(LocalTime.NOON);
    DateTimeField adjuster = new FixedDateTimeField(cdt2);
    if (chrono != chrono2) {
      try {
        ChronoLocalDateTime<?> notreached = cdt.with(adjuster, 1);
        Assert.fail("DateTimeField doWith() should have thrown a ClassCastException" + cdt.getClass()
            + ", can not be cast to " + cdt2.getClass());
      } catch (ClassCastException cce) {
        // Expected exception; not an error
      }
    } else {
      // Same chronology,
      ChronoLocalDateTime<?> result = cdt.with(adjuster, 1);
      assertEquals(result, cdt2, "DateTimeField doWith() failed to replace date");
    }
  }
}
项目:optashift-employee-rostering    文件:DateTimeBuilder.java   
/**
 * Creates a new instance of the builder.
 * 
 * @param zone the zone, may be null
 * @param chrono the chronology, may be null
 */
public DateTimeBuilder(ZoneId zone, Chrono<?> chrono) {

  if (zone != null) {
    this.objects.add(zone);
  }
  if (chrono != null) {
    this.objects.add(chrono);
  }
}
项目:gwt-time    文件:DateTimeBuilder.java   
/**
 * Creates a new instance of the builder.
 * 
 * @param zone the zone, may be null
 * @param chrono the chronology, may be null
 */
public DateTimeBuilder(ZoneId zone, Chrono<?> chrono) {

  if (zone != null) {
    this.objects.add(zone);
  }
  if (chrono != null) {
    this.objects.add(chrono);
  }
}