java.time.Period#of ( )源码实例Demo

下面列出了java.time.Period#of ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk8u-dev-jdk   文件: CopticDate.java
@Override
public Period until(ChronoLocalDate endDate) {
    // TODO: untested
    CopticDate end = getChronology().date(endDate);
    long totalMonths = (end.prolepticYear - this.prolepticYear) * 13 + (end.month - this.month);  // safe
    int days = end.day - this.day;
    if (totalMonths > 0 && days < 0) {
        totalMonths--;
        CopticDate calcDate = this.plusMonths(totalMonths);
        days = (int) (end.toEpochDay() - calcDate.toEpochDay());  // safe
    } else if (totalMonths < 0 && days > 0) {
        totalMonths++;
        days -= end.lengthOfMonth();
    }
    long years = totalMonths / 13;  // safe
    int months = (int) (totalMonths % 13);  // safe
    return Period.of(Math.toIntExact(years), months, days);
}
 
源代码2 项目: threeten-jaxb   文件: XmlAdaptersTest.java
XmlAdaptersTest() throws JAXBException {
    jaxbContext = JAXBContext.newInstance(Bean.class);

    final Bean expectedBean = new Bean();
    expectedBean.duration = Duration.ofDays(2).plusHours(3).plusMinutes(4);
    expectedBean.instant = LocalDateTime.of(2007, 12, 3, 10, 15, 30)
            .toInstant(ZoneOffset.UTC);
    expectedBean.localDateTime = LocalDateTime.of(2007, 12, 3, 10, 15, 30);
    expectedBean.localDate = LocalDate.of(2014, 12, 31);
    expectedBean.localTime = LocalTime.of(10, 15, 30);
    expectedBean.monthDay = MonthDay.of(Month.DECEMBER, 3);
    expectedBean.offsetDateTime = OffsetDateTime
            .of(2007, 12, 3, 10, 15, 30, 0, ZoneOffset.ofHours(1));
    expectedBean.offsetTime = OffsetTime
            .of(10, 15, 30, 0, ZoneOffset.ofHours(1));
    expectedBean.period = Period.of(1, 2, 25);
    expectedBean.year = Year.of(-2014);
    expectedBean.yearMonth = YearMonth.of(2014, 12);
    expectedBean.zoneId = ZoneId.of("America/New_York");
    expectedBean.zoneOffset = ZoneOffset.ofHoursMinutes(-12, 0);
    expectedBean.zonedDateTime = ZonedDateTime
            .of(2007, 12, 3, 10, 15, 30, 0, ZoneId.of("Europe/Paris"));
    this.expectedBean = expectedBean;

    this.expectedMarshalledBean = getClass().getResource("expectedBean.xml");
}
 
源代码3 项目: jdk8u60   文件: 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);
}
 
源代码4 项目: hottub   文件: TCKYear.java
@DataProvider(name="plusInvalidUnit")
Object[][] data_plusInvalidUnit() {
    return new Object[][] {
            {Period.of(0, 1, 0)},
            {Period.of(0, 0, 1)},
            {Period.of(0, 1, 1)},
            {Period.of(1, 1, 1)},
            {Duration.ofDays(1)},
            {Duration.ofHours(1)},
            {Duration.ofMinutes(1)},
            {Duration.ofSeconds(1)},
    };
}
 
源代码5 项目: jdk8u-dev-jdk   文件: TCKPeriod.java
@DataProvider(name="toStringAndParse")
Object[][] data_toString() {
    return new Object[][] {
            {Period.ZERO, "P0D"},
            {Period.ofDays(0), "P0D"},
            {Period.ofYears(1), "P1Y"},
            {Period.ofMonths(1), "P1M"},
            {Period.ofDays(1), "P1D"},
            {Period.of(1, 2, 0), "P1Y2M"},
            {Period.of(0, 2, 3), "P2M3D"},
            {Period.of(1, 2, 3), "P1Y2M3D"},
    };
}
 
源代码6 项目: jdk8u-dev-jdk   文件: TCKYear.java
@DataProvider(name="plusInvalidUnit")
Object[][] data_plusInvalidUnit() {
    return new Object[][] {
            {Period.of(0, 1, 0)},
            {Period.of(0, 0, 1)},
            {Period.of(0, 1, 1)},
            {Period.of(1, 1, 1)},
            {Duration.ofDays(1)},
            {Duration.ofHours(1)},
            {Duration.ofMinutes(1)},
            {Duration.ofSeconds(1)},
    };
}
 
源代码7 项目: jackson-modules-java8   文件: PeriodDeserTest.java
@Test
public void testDeserialization01() throws Exception
{
    Period period = Period.of(1, 6, 15);
    Period value = MAPPER.readValue('"' + period.toString() + '"', Period.class);
    assertEquals("The value is not correct.", period, value);
}
 
源代码8 项目: jdk8u60   文件: TCKYear.java
@DataProvider(name="plusInvalidUnit")
Object[][] data_plusInvalidUnit() {
    return new Object[][] {
            {Period.of(0, 1, 0)},
            {Period.of(0, 0, 1)},
            {Period.of(0, 1, 1)},
            {Period.of(1, 1, 1)},
            {Duration.ofDays(1)},
            {Duration.ofHours(1)},
            {Duration.ofMinutes(1)},
            {Duration.ofSeconds(1)},
    };
}
 
源代码9 项目: openjdk-8   文件: TCKPeriod.java
public void test_equals_otherClass() {
    Period test = Period.of(1, 2, 3);
    assertEquals(test.equals(""), false);
}
 
源代码10 项目: j2objc   文件: TCKPeriod.java
private static Period pymd(int y, int m, int d) {
    return Period.of(y, m, d);
}
 
源代码11 项目: j2objc   文件: TCKPeriod.java
@Test
public void factory_from_TemporalAmount_Period() {
    TemporalAmount amount = Period.of(1, 2, 3);
    assertPeriod(Period.from(amount), 1, 2, 3);
}
 
源代码12 项目: jdk8u-jdk   文件: TCKPeriod.java
public void test_equals_self() {
    Period test = Period.of(1, 2, 3);
    assertEquals(test.equals(test), true);
}
 
源代码13 项目: hottub   文件: TCKPeriod.java
@Test(dataProvider="BadTemporalUnit", expectedExceptions=DateTimeException.class)
public void test_bad_getUnit(TemporalUnit unit) {
    Period period = Period.of(2, 2, 2);
    period.get(unit);
}
 
源代码14 项目: dragonwell8_jdk   文件: TCKPeriod.java
@DataProvider(name="parseSuccess")
Object[][] data_factory_parseSuccess() {
    return new Object[][] {
            {"P1Y", Period.ofYears(1)},
            {"P12Y", Period.ofYears(12)},
            {"P987654321Y", Period.ofYears(987654321)},
            {"P+1Y", Period.ofYears(1)},
            {"P+12Y", Period.ofYears(12)},
            {"P+987654321Y", Period.ofYears(987654321)},
            {"P+0Y", Period.ofYears(0)},
            {"P0Y", Period.ofYears(0)},
            {"P-0Y", Period.ofYears(0)},
            {"P-25Y", Period.ofYears(-25)},
            {"P-987654321Y", Period.ofYears(-987654321)},
            {"P" + Integer.MAX_VALUE + "Y", Period.ofYears(Integer.MAX_VALUE)},
            {"P" + Integer.MIN_VALUE + "Y", Period.ofYears(Integer.MIN_VALUE)},

            {"P1M", Period.ofMonths(1)},
            {"P12M", Period.ofMonths(12)},
            {"P987654321M", Period.ofMonths(987654321)},
            {"P+1M", Period.ofMonths(1)},
            {"P+12M", Period.ofMonths(12)},
            {"P+987654321M", Period.ofMonths(987654321)},
            {"P+0M", Period.ofMonths(0)},
            {"P0M", Period.ofMonths(0)},
            {"P-0M", Period.ofMonths(0)},
            {"P-25M", Period.ofMonths(-25)},
            {"P-987654321M", Period.ofMonths(-987654321)},
            {"P" + Integer.MAX_VALUE + "M", Period.ofMonths(Integer.MAX_VALUE)},
            {"P" + Integer.MIN_VALUE + "M", Period.ofMonths(Integer.MIN_VALUE)},

            {"P1W", Period.ofDays(1 * 7)},
            {"P12W", Period.ofDays(12 * 7)},
            {"P7654321W", Period.ofDays(7654321 * 7)},
            {"P+1W", Period.ofDays(1 * 7)},
            {"P+12W", Period.ofDays(12 * 7)},
            {"P+7654321W", Period.ofDays(7654321 * 7)},
            {"P+0W", Period.ofDays(0)},
            {"P0W", Period.ofDays(0)},
            {"P-0W", Period.ofDays(0)},
            {"P-25W", Period.ofDays(-25 * 7)},
            {"P-7654321W", Period.ofDays(-7654321 * 7)},

            {"P1D", Period.ofDays(1)},
            {"P12D", Period.ofDays(12)},
            {"P987654321D", Period.ofDays(987654321)},
            {"P+1D", Period.ofDays(1)},
            {"P+12D", Period.ofDays(12)},
            {"P+987654321D", Period.ofDays(987654321)},
            {"P+0D", Period.ofDays(0)},
            {"P0D", Period.ofDays(0)},
            {"P-0D", Period.ofDays(0)},
            {"P-25D", Period.ofDays(-25)},
            {"P-987654321D", Period.ofDays(-987654321)},
            {"P" + Integer.MAX_VALUE + "D", Period.ofDays(Integer.MAX_VALUE)},
            {"P" + Integer.MIN_VALUE + "D", Period.ofDays(Integer.MIN_VALUE)},

            {"P0Y0M0D", Period.of(0, 0, 0)},
            {"P2Y0M0D", Period.of(2, 0, 0)},
            {"P0Y3M0D", Period.of(0, 3, 0)},
            {"P0Y0M4D", Period.of(0, 0, 4)},
            {"P2Y3M25D", Period.of(2, 3, 25)},
            {"P-2Y3M25D", Period.of(-2, 3, 25)},
            {"P2Y-3M25D", Period.of(2, -3, 25)},
            {"P2Y3M-25D", Period.of(2, 3, -25)},
            {"P-2Y-3M-25D", Period.of(-2, -3, -25)},

            {"P0Y0M0W0D", Period.of(0, 0, 0)},
            {"P2Y3M4W25D", Period.of(2, 3, 4 * 7 + 25)},
            {"P-2Y-3M-4W-25D", Period.of(-2, -3, -4 * 7 - 25)},
    };
}
 
源代码15 项目: joyrpc   文件: PeriodHandle.java
@Override
public Period readResolve() {
    return Period.of(years, months, days);
}
 
源代码16 项目: openjdk-jdk8u   文件: TCKPeriod.java
public void test_equals_otherClass() {
    Period test = Period.of(1, 2, 3);
    assertEquals(test.equals(""), false);
}
 
源代码17 项目: Java8CN   文件: IsoChronology.java
/**
 * Obtains a period for this chronology based on years, months and days.
 * <p>
 * This returns a period tied to the ISO chronology using the specified
 * years, months and days. See {@link Period} for further details.
 *
 * @param years  the number of years, may be negative
 * @param months  the number of years, may be negative
 * @param days  the number of years, may be negative
 * @return the period in terms of this chronology, not null
 * @return the ISO period, not null
 */
@Override  // override with covariant return type
public Period period(int years, int months, int days) {
    return Period.of(years, months, days);
}
 
源代码18 项目: jdk8u-jdk   文件: IsoChronology.java
/**
 * Obtains a period for this chronology based on years, months and days.
 * <p>
 * This returns a period tied to the ISO chronology using the specified
 * years, months and days. See {@link Period} for further details.
 *
 * @param years  the number of years, may be negative
 * @param months  the number of years, may be negative
 * @param days  the number of years, may be negative
 * @return the period in terms of this chronology, not null
 * @return the ISO period, not null
 */
@Override  // override with covariant return type
public Period period(int years, int months, int days) {
    return Period.of(years, months, days);
}
 
源代码19 项目: openjdk-jdk9   文件: IsoChronology.java
/**
 * Obtains a period for this chronology based on years, months and days.
 * <p>
 * This returns a period tied to the ISO chronology using the specified
 * years, months and days. See {@link Period} for further details.
 *
 * @param years  the number of years, may be negative
 * @param months  the number of years, may be negative
 * @param days  the number of years, may be negative
 * @return the period in terms of this chronology, not null
 * @return the ISO period, not null
 */
@Override  // override with covariant return type
public Period period(int years, int months, int days) {
    return Period.of(years, months, days);
}
 
源代码20 项目: desugar_jdk_libs   文件: IsoChronology.java
/**
 * Obtains a period for this chronology based on years, months and days.
 * <p>
 * This returns a period tied to the ISO chronology using the specified
 * years, months and days. See {@link Period} for further details.
 *
 * @param years  the number of years, may be negative
 * @param months  the number of years, may be negative
 * @param days  the number of years, may be negative
 * @return the period in terms of this chronology, not null
 * @return the ISO period, not null
 */
@Override  // override with covariant return type
public Period period(int years, int months, int days) {
    return Period.of(years, months, days);
}