Java 类java.time.calendrical.DateTimeAdjusters 实例源码

项目:java8-backports    文件:TzdbZoneRulesCompiler.java   
private LocalDateTime toDateTime(int year) {

      adjustToFowards(year);
      LocalDate date;
      if (this.dayOfMonth == -1) {
        this.dayOfMonth = this.month.length(Year.isLeap(year));
        date = LocalDate.of(year, this.month, this.dayOfMonth);
        if (this.dayOfWeek != null) {
          date = date.with(DateTimeAdjusters.previousOrSame(this.dayOfWeek));
        }
      } else {
        date = LocalDate.of(year, this.month, this.dayOfMonth);
        if (this.dayOfWeek != null) {
          date = date.with(DateTimeAdjusters.nextOrSame(this.dayOfWeek));
        }
      }
      date = deduplicate(date);
      LocalDateTime ldt = LocalDateTime.of(date, this.time);
      if (this.endOfDay) {
        ldt = ldt.plusDays(1);
      }
      return ldt;
    }
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void test_next() {

  for (Month month : Month.values()) {
    for (int i = 1; i <= month.length(false); i++) {
      LocalDate date = date(2007, month, i);

      for (DayOfWeek dow : DayOfWeek.values()) {
        LocalDate test = (LocalDate) DateTimeAdjusters.next(dow).doWithAdjustment(date);

        assertSame(test.getDayOfWeek(), dow, date + " " + test);

        if (test.getYear() == 2007) {
          int dayDiff = test.getDayOfYear() - date.getDayOfYear();
          assertTrue(dayDiff > 0 && dayDiff < 8);
        } else {
          assertSame(month, Month.DECEMBER);
          assertTrue(date.getDayOfMonth() > 24);
          assertEquals(test.getYear(), 2008);
          assertSame(test.getMonth(), Month.JANUARY);
          assertTrue(test.getDayOfMonth() < 8);
        }
      }
    }
  }
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void test_previous() {

  for (Month month : Month.values()) {
    for (int i = 1; i <= month.length(false); i++) {
      LocalDate date = date(2007, month, i);

      for (DayOfWeek dow : DayOfWeek.values()) {
        LocalDate test = (LocalDate) DateTimeAdjusters.previous(dow).doWithAdjustment(date);

        assertSame(test.getDayOfWeek(), dow, date + " " + test);

        if (test.getYear() == 2007) {
          int dayDiff = test.getDayOfYear() - date.getDayOfYear();
          assertTrue(dayDiff < 0 && dayDiff > -8, dayDiff + " " + test);
        } else {
          assertSame(month, Month.JANUARY);
          assertTrue(date.getDayOfMonth() < 8);
          assertEquals(test.getYear(), 2006);
          assertSame(test.getMonth(), Month.DECEMBER);
          assertTrue(test.getDayOfMonth() > 24);
        }
      }
    }
  }
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void test_firstDayOfMonth_nonLeap() {

  for (Month month : Month.values()) {
    for (int i = 1; i <= month.length(false); i++) {
      LocalDate date = date(2007, month, i);
      LocalDate test = (LocalDate) DateTimeAdjusters.firstDayOfMonth().doWithAdjustment(date);
      assertEquals(test.getYear(), 2007);
      assertEquals(test.getMonth(), month);
      assertEquals(test.getDayOfMonth(), 1);
    }
  }
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void test_firstDayOfMonth_leap() {

  for (Month month : Month.values()) {
    for (int i = 1; i <= month.length(true); i++) {
      LocalDate date = date(2008, month, i);
      LocalDate test = (LocalDate) DateTimeAdjusters.firstDayOfMonth().doWithAdjustment(date);
      assertEquals(test.getYear(), 2008);
      assertEquals(test.getMonth(), month);
      assertEquals(test.getDayOfMonth(), 1);
    }
  }
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void test_lastDayOfMonth_nonLeap() {

  for (Month month : Month.values()) {
    for (int i = 1; i <= month.length(false); i++) {
      LocalDate date = date(2007, month, i);
      LocalDate test = (LocalDate) DateTimeAdjusters.lastDayOfMonth().doWithAdjustment(date);
      assertEquals(test.getYear(), 2007);
      assertEquals(test.getMonth(), month);
      assertEquals(test.getDayOfMonth(), month.length(false));
    }
  }
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void test_lastDayOfMonth_leap() {

  for (Month month : Month.values()) {
    for (int i = 1; i <= month.length(true); i++) {
      LocalDate date = date(2008, month, i);
      LocalDate test = (LocalDate) DateTimeAdjusters.lastDayOfMonth().doWithAdjustment(date);
      assertEquals(test.getYear(), 2008);
      assertEquals(test.getMonth(), month);
      assertEquals(test.getDayOfMonth(), month.length(true));
    }
  }
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void test_firstDayOfNextMonth_nonLeap() {

  for (Month month : Month.values()) {
    for (int i = 1; i <= month.length(false); i++) {
      LocalDate date = date(2007, month, i);
      LocalDate test = (LocalDate) DateTimeAdjusters.firstDayOfNextMonth().doWithAdjustment(date);
      assertEquals(test.getYear(), month == DECEMBER ? 2008 : 2007);
      assertEquals(test.getMonth(), month.plus(1));
      assertEquals(test.getDayOfMonth(), 1);
    }
  }
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void test_firstDayOfNextMonth_leap() {

  for (Month month : Month.values()) {
    for (int i = 1; i <= month.length(true); i++) {
      LocalDate date = date(2008, month, i);
      LocalDate test = (LocalDate) DateTimeAdjusters.firstDayOfNextMonth().doWithAdjustment(date);
      assertEquals(test.getYear(), month == DECEMBER ? 2009 : 2008);
      assertEquals(test.getMonth(), month.plus(1));
      assertEquals(test.getDayOfMonth(), 1);
    }
  }
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void test_firstDayOfYear_nonLeap() {

  for (Month month : Month.values()) {
    for (int i = 1; i <= month.length(false); i++) {
      LocalDate date = date(2007, month, i);
      LocalDate test = (LocalDate) DateTimeAdjusters.firstDayOfYear().doWithAdjustment(date);
      assertEquals(test.getYear(), 2007);
      assertEquals(test.getMonth(), Month.JANUARY);
      assertEquals(test.getDayOfMonth(), 1);
    }
  }
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void test_firstDayOfYear_leap() {

  for (Month month : Month.values()) {
    for (int i = 1; i <= month.length(true); i++) {
      LocalDate date = date(2008, month, i);
      LocalDate test = (LocalDate) DateTimeAdjusters.firstDayOfYear().doWithAdjustment(date);
      assertEquals(test.getYear(), 2008);
      assertEquals(test.getMonth(), Month.JANUARY);
      assertEquals(test.getDayOfMonth(), 1);
    }
  }
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void test_lastDayOfYear_nonLeap() {

  for (Month month : Month.values()) {
    for (int i = 1; i <= month.length(false); i++) {
      LocalDate date = date(2007, month, i);
      LocalDate test = (LocalDate) DateTimeAdjusters.lastDayOfYear().doWithAdjustment(date);
      assertEquals(test.getYear(), 2007);
      assertEquals(test.getMonth(), Month.DECEMBER);
      assertEquals(test.getDayOfMonth(), 31);
    }
  }
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void test_lastDayOfYear_leap() {

  for (Month month : Month.values()) {
    for (int i = 1; i <= month.length(true); i++) {
      LocalDate date = date(2008, month, i);
      LocalDate test = (LocalDate) DateTimeAdjusters.lastDayOfYear().doWithAdjustment(date);
      assertEquals(test.getYear(), 2008);
      assertEquals(test.getMonth(), Month.DECEMBER);
      assertEquals(test.getDayOfMonth(), 31);
    }
  }
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void test_firstDayOfNextYear_nonLeap() {

  for (Month month : Month.values()) {
    for (int i = 1; i <= month.length(false); i++) {
      LocalDate date = date(2007, month, i);
      LocalDate test = (LocalDate) DateTimeAdjusters.firstDayOfNextYear().doWithAdjustment(date);
      assertEquals(test.getYear(), 2008);
      assertEquals(test.getMonth(), JANUARY);
      assertEquals(test.getDayOfMonth(), 1);
    }
  }
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void test_firstDayOfNextYear_leap() {

  for (Month month : Month.values()) {
    for (int i = 1; i <= month.length(true); i++) {
      LocalDate date = date(2008, month, i);
      LocalDate test = (LocalDate) DateTimeAdjusters.firstDayOfNextYear().doWithAdjustment(date);
      assertEquals(test.getYear(), 2009);
      assertEquals(test.getMonth(), JANUARY);
      assertEquals(test.getDayOfMonth(), 1);
    }
  }
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" }, dataProvider = "dayOfWeekInMonth_positive")
public void test_dayOfWeekInMonth_positive(int year, int month, DayOfWeek dow, LocalDate expected) {

  for (int ordinal = 1; ordinal <= 5; ordinal++) {
    for (int day = 1; day <= Month.of(month).length(false); day++) {
      LocalDate date = date(year, month, day);
      LocalDate test = (LocalDate) DateTimeAdjusters.dayOfWeekInMonth(ordinal, dow).doWithAdjustment(date);
      assertEquals(test, expected.plusWeeks(ordinal - 1));
    }
  }
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" }, dataProvider = "dayOfWeekInMonth_zero")
public void test_dayOfWeekInMonth_zero(int year, int month, DayOfWeek dow, LocalDate expected) {

  for (int day = 1; day <= Month.of(month).length(false); day++) {
    LocalDate date = date(year, month, day);
    LocalDate test = (LocalDate) DateTimeAdjusters.dayOfWeekInMonth(0, dow).doWithAdjustment(date);
    assertEquals(test, expected);
  }
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" }, dataProvider = "dayOfWeekInMonth_negative")
public void test_dayOfWeekInMonth_negative(int year, int month, DayOfWeek dow, LocalDate expected) {

  for (int ordinal = 0; ordinal < 5; ordinal++) {
    for (int day = 1; day <= Month.of(month).length(false); day++) {
      LocalDate date = date(year, month, day);
      LocalDate test = (LocalDate) DateTimeAdjusters.dayOfWeekInMonth(-1 - ordinal, dow).doWithAdjustment(date);
      assertEquals(test, expected.minusWeeks(ordinal));
    }
  }
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" }, dataProvider = "dayOfWeekInMonth_positive")
public void test_firstInMonth(int year, int month, DayOfWeek dow, LocalDate expected) {

  for (int day = 1; day <= Month.of(month).length(false); day++) {
    LocalDate date = date(year, month, day);
    LocalDate test = (LocalDate) DateTimeAdjusters.firstInMonth(dow).doWithAdjustment(date);
    assertEquals(test, expected, "day-of-month=" + day);
  }
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" }, dataProvider = "dayOfWeekInMonth_negative")
public void test_lastInMonth(int year, int month, DayOfWeek dow, LocalDate expected) {

  for (int day = 1; day <= Month.of(month).length(false); day++) {
    LocalDate date = date(year, month, day);
    LocalDate test = (LocalDate) DateTimeAdjusters.lastInMonth(dow).doWithAdjustment(date);
    assertEquals(test, expected, "day-of-month=" + day);
  }
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void test_nextOrSame() {

  for (Month month : Month.values()) {
    for (int i = 1; i <= month.length(false); i++) {
      LocalDate date = date(2007, month, i);

      for (DayOfWeek dow : DayOfWeek.values()) {
        LocalDate test = (LocalDate) DateTimeAdjusters.nextOrSame(dow).doWithAdjustment(date);

        assertSame(test.getDayOfWeek(), dow);

        if (test.getYear() == 2007) {
          int dayDiff = test.getDayOfYear() - date.getDayOfYear();
          assertTrue(dayDiff < 8);
          assertEquals(date.equals(test), date.getDayOfWeek() == dow);
        } else {
          assertFalse(date.getDayOfWeek() == dow);
          assertSame(month, Month.DECEMBER);
          assertTrue(date.getDayOfMonth() > 24);
          assertEquals(test.getYear(), 2008);
          assertSame(test.getMonth(), Month.JANUARY);
          assertTrue(test.getDayOfMonth() < 8);
        }
      }
    }
  }
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void test_previousOrSame() {

  for (Month month : Month.values()) {
    for (int i = 1; i <= month.length(false); i++) {
      LocalDate date = date(2007, month, i);

      for (DayOfWeek dow : DayOfWeek.values()) {
        LocalDate test = (LocalDate) DateTimeAdjusters.previousOrSame(dow).doWithAdjustment(date);

        assertSame(test.getDayOfWeek(), dow);

        if (test.getYear() == 2007) {
          int dayDiff = test.getDayOfYear() - date.getDayOfYear();
          assertTrue(dayDiff <= 0 && dayDiff > -7);
          assertEquals(date.equals(test), date.getDayOfWeek() == dow);
        } else {
          assertFalse(date.getDayOfWeek() == dow);
          assertSame(month, Month.JANUARY);
          assertTrue(date.getDayOfMonth() < 7);
          assertEquals(test.getYear(), 2006);
          assertSame(test.getMonth(), Month.DECEMBER);
          assertTrue(test.getDayOfMonth() > 25);
        }
      }
    }
  }
}
项目:java8-backports    文件:TestDateTimeAdjusters.java   
@SuppressWarnings("rawtypes")
public void test_constructor() throws Exception {

  for (Constructor constructor : DateTimeAdjusters.class.getDeclaredConstructors()) {
    assertTrue(Modifier.isPrivate(constructor.getModifiers()));
    constructor.setAccessible(true);
    constructor.newInstance(Collections.nCopies(constructor.getParameterTypes().length, null).toArray());
  }
}
项目:java8-backports    文件:TestThaiBuddhistChrono.java   
@Test(groups = { "tck" })
public void test_adjust1() {

  ChronoLocalDate<ThaiBuddhistChrono> base = ThaiBuddhistChrono.INSTANCE.date(1728, 10, 29);
  ChronoLocalDate<ThaiBuddhistChrono> test = base.with(DateTimeAdjusters.lastDayOfMonth());
  assertEquals(test, ThaiBuddhistChrono.INSTANCE.date(1728, 10, 31));
}
项目:java8-backports    文件:TestThaiBuddhistChrono.java   
@Test(groups = { "tck" })
public void test_adjust2() {

  ChronoLocalDate<ThaiBuddhistChrono> base = ThaiBuddhistChrono.INSTANCE.date(1728, 12, 2);
  ChronoLocalDate<ThaiBuddhistChrono> test = base.with(DateTimeAdjusters.lastDayOfMonth());
  assertEquals(test, ThaiBuddhistChrono.INSTANCE.date(1728, 12, 31));
}
项目:java8-backports    文件:TestHijrahChrono.java   
@Test(groups = { "tck" })
public void test_adjust1() {

  ChronoLocalDate<?> base = HijrahChrono.INSTANCE.date(1728, 10, 28);
  ChronoLocalDate<?> test = base.with(DateTimeAdjusters.lastDayOfMonth());
  assertEquals(test, HijrahChrono.INSTANCE.date(1728, 10, 29));
}
项目:java8-backports    文件:TestHijrahChrono.java   
@Test(groups = { "tck" })
public void test_adjust2() {

  ChronoLocalDate<?> base = HijrahChrono.INSTANCE.date(1728, 12, 2);
  ChronoLocalDate<?> test = base.with(DateTimeAdjusters.lastDayOfMonth());
  assertEquals(test, HijrahChrono.INSTANCE.date(1728, 12, 30));
}
项目:java8-backports    文件:TestMinguoChrono.java   
@Test(groups = { "tck" })
public void test_adjust1() {

  ChronoLocalDate<MinguoChrono> base = MinguoChrono.INSTANCE.date(2012, 10, 29);
  ChronoLocalDate<MinguoChrono> test = base.with(DateTimeAdjusters.lastDayOfMonth());
  assertEquals(test, MinguoChrono.INSTANCE.date(2012, 10, 31));
}
项目:java8-backports    文件:TestMinguoChrono.java   
@Test(groups = { "tck" })
public void test_adjust2() {

  ChronoLocalDate<MinguoChrono> base = MinguoChrono.INSTANCE.date(1728, 12, 2);
  ChronoLocalDate<MinguoChrono> test = base.with(DateTimeAdjusters.lastDayOfMonth());
  assertEquals(test, MinguoChrono.INSTANCE.date(1728, 12, 31));
}
项目:java8-backports    文件:TestJapaneseChrono.java   
@Test(groups = { "tck" })
public void test_adjust1() {

  ChronoLocalDate<JapaneseChrono> base = JapaneseChrono.INSTANCE.date(1728, 10, 29);
  ChronoLocalDate<JapaneseChrono> test = base.with(DateTimeAdjusters.lastDayOfMonth());
  assertEquals(test, JapaneseChrono.INSTANCE.date(1728, 10, 31));
}
项目:java8-backports    文件:TestJapaneseChrono.java   
@Test(groups = { "tck" })
public void test_adjust2() {

  ChronoLocalDate<JapaneseChrono> base = JapaneseChrono.INSTANCE.date(1728, 12, 2);
  ChronoLocalDate<JapaneseChrono> test = base.with(DateTimeAdjusters.lastDayOfMonth());
  assertEquals(test, JapaneseChrono.INSTANCE.date(1728, 12, 31));
}
项目:java8-backports    文件:TestISOChrono.java   
@Test(groups = { "tck" })
public void test_adjust1() {

  ChronoLocalDate<ISOChrono> base = ISOChrono.INSTANCE.date(1728, 10, 28);
  ChronoLocalDate<ISOChrono> test = base.with(DateTimeAdjusters.lastDayOfMonth());
  assertEquals(test, ISOChrono.INSTANCE.date(1728, 10, 31));
}
项目:java8-backports    文件:TestISOChrono.java   
@Test(groups = { "tck" })
public void test_adjust2() {

  ChronoLocalDate<ISOChrono> base = ISOChrono.INSTANCE.date(1728, 12, 2);
  ChronoLocalDate<ISOChrono> test = base.with(DateTimeAdjusters.lastDayOfMonth());
  assertEquals(test, ISOChrono.INSTANCE.date(1728, 12, 31));
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void factory_firstDayOfMonth() {

  assertNotNull(DateTimeAdjusters.firstDayOfMonth());
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void factory_lastDayOfMonth() {

  assertNotNull(DateTimeAdjusters.lastDayOfMonth());
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void factory_firstDayOfNextMonth() {

  assertNotNull(DateTimeAdjusters.firstDayOfNextMonth());
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void factory_firstDayOfYear() {

  assertNotNull(DateTimeAdjusters.firstDayOfYear());
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void factory_lastDayOfYear() {

  assertNotNull(DateTimeAdjusters.lastDayOfYear());
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void factory_firstDayOfNextYear() {

  assertNotNull(DateTimeAdjusters.firstDayOfNextYear());
}
项目:java8-backports    文件:TCKDateTimeAdjusters.java   
@Test(groups = { "tck" })
public void factory_dayOfWeekInMonth() {

  assertNotNull(DateTimeAdjusters.dayOfWeekInMonth(1, MONDAY));
}