當前位置: 首頁>>代碼示例>>Java>>正文


Java Year.MAX_VALUE屬性代碼示例

本文整理匯總了Java中java.time.Year.MAX_VALUE屬性的典型用法代碼示例。如果您正苦於以下問題:Java Year.MAX_VALUE屬性的具體用法?Java Year.MAX_VALUE怎麽用?Java Year.MAX_VALUE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在java.time.Year的用法示例。


在下文中一共展示了Year.MAX_VALUE屬性的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: prolepticYear

@Override
public int prolepticYear(Era era, int yearOfEra) {
    if (era instanceof JapaneseEra == false) {
        throw new ClassCastException("Era must be JapaneseEra");
    }

    JapaneseEra jera = (JapaneseEra) era;
    int gregorianYear = jera.getPrivateEra().getSinceDate().getYear() + yearOfEra - 1;
    if (yearOfEra == 1) {
        return gregorianYear;
    }
    if (gregorianYear >= Year.MIN_VALUE && gregorianYear <= Year.MAX_VALUE) {
        LocalGregorianCalendar.Date jdate = JCAL.newCalendarDate(null);
        jdate.setEra(jera.getPrivateEra()).setDate(yearOfEra, 1, 1);
        if (JapaneseChronology.JCAL.validate(jdate)) {
            return gregorianYear;
        }
    }
    throw new DateTimeException("Invalid yearOfEra value");
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:20,代碼來源:JapaneseChronology.java

示例2: provider_goodParseData

@DataProvider(name="goodParseData")
Object[][] provider_goodParseData() {
    return new Object[][] {
            {"0000", Year.of(0)},
            {"9999", Year.of(9999)},
            {"2000", Year.of(2000)},

            {"+12345678", Year.of(12345678)},
            {"+123456", Year.of(123456)},
            {"-1234", Year.of(-1234)},
            {"-12345678", Year.of(-12345678)},

            {"+" + Year.MAX_VALUE, Year.of(Year.MAX_VALUE)},
            {"" + Year.MIN_VALUE, Year.of(Year.MIN_VALUE)},
    };
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:TCKYear.java

示例3: factory_ofInstant_maxWithMinOffset

@Test
public void factory_ofInstant_maxWithMinOffset() {
    long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
    int year = Year.MAX_VALUE;
    long days = (year * 365L + (year / 4 - year / 100 + year / 400)) + 365 - days_0000_to_1970;
    Instant instant = Instant.ofEpochSecond((days + 1) * 24L * 60L * 60L - 1 - OFFSET_MIN.getTotalSeconds());
    ZonedDateTime test = ZonedDateTime.ofInstant(instant, OFFSET_MIN);
    assertEquals(test.getYear(), Year.MAX_VALUE);
    assertEquals(test.getMonth().getValue(), 12);
    assertEquals(test.getDayOfMonth(), 31);
    assertEquals(test.getOffset(), OFFSET_MIN);
    assertEquals(test.getHour(), 23);
    assertEquals(test.getMinute(), 59);
    assertEquals(test.getSecond(), 59);
    assertEquals(test.getNano(), 0);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:TCKZonedDateTime.java

示例4: factory_ofInstant_maxWithMaxOffset

@Test
public void factory_ofInstant_maxWithMaxOffset() {
    long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
    int year = Year.MAX_VALUE;
    long days = (year * 365L + (year / 4 - year / 100 + year / 400)) + 365 - days_0000_to_1970;
    Instant instant = Instant.ofEpochSecond((days + 1) * 24L * 60L * 60L - 1 - OFFSET_MAX.getTotalSeconds());
    ZonedDateTime test = ZonedDateTime.ofInstant(instant, OFFSET_MAX);
    assertEquals(test.getYear(), Year.MAX_VALUE);
    assertEquals(test.getMonth().getValue(), 12);
    assertEquals(test.getDayOfMonth(), 31);
    assertEquals(test.getOffset(), OFFSET_MAX);
    assertEquals(test.getHour(), 23);
    assertEquals(test.getMinute(), 59);
    assertEquals(test.getSecond(), 59);
    assertEquals(test.getNano(), 0);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:TCKZonedDateTime.java

示例5: factory_ofInstant_maxWithMinOffset

public void factory_ofInstant_maxWithMinOffset() {
    long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
    int year = Year.MAX_VALUE;
    long days = (year * 365L + (year / 4 - year / 100 + year / 400)) + 365 - days_0000_to_1970;
    Instant instant = Instant.ofEpochSecond((days + 1) * 24L * 60L * 60L - 1 - OFFSET_MIN.getTotalSeconds());
    OffsetDateTime test = OffsetDateTime.ofInstant(instant, OFFSET_MIN);
    assertEquals(test.getYear(), Year.MAX_VALUE);
    assertEquals(test.getMonth().getValue(), 12);
    assertEquals(test.getDayOfMonth(), 31);
    assertEquals(test.getOffset(), OFFSET_MIN);
    assertEquals(test.getHour(), 23);
    assertEquals(test.getMinute(), 59);
    assertEquals(test.getSecond(), 59);
    assertEquals(test.getNano(), 0);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:TestOffsetDateTime_instants.java

示例6: nextTransition

/**
 * Gets the next transition after the specified instant.
 * <p>
 * This returns details of the next transition after the specified instant.
 * For example, if the instant represents a point where "Summer" daylight savings time
 * applies, then the method will return the transition to the next "Winter" time.
 *
 * @param instant  the instant to get the next transition after, not null, but null
 *  may be ignored if the rules have a single offset for all instants
 * @return the next transition after the specified instant, null if this is after the last transition
 */
public ZoneOffsetTransition nextTransition(Instant instant) {
    if (savingsInstantTransitions.length == 0) {
        return null;
    }
    long epochSec = instant.getEpochSecond();
    // check if using last rules
    if (epochSec >= savingsInstantTransitions[savingsInstantTransitions.length - 1]) {
        if (lastRules.length == 0) {
            return null;
        }
        // search year the instant is in
        int year = findYear(epochSec, wallOffsets[wallOffsets.length - 1]);
        ZoneOffsetTransition[] transArray = findTransitionArray(year);
        for (ZoneOffsetTransition trans : transArray) {
            if (epochSec < trans.toEpochSecond()) {
                return trans;
            }
        }
        // use first from following year
        if (year < Year.MAX_VALUE) {
            transArray = findTransitionArray(year + 1);
            return transArray[0];
        }
        return null;
    }

    // using historic rules
    int index  = Arrays.binarySearch(savingsInstantTransitions, epochSec);
    if (index < 0) {
        index = -index - 1;  // switched value is the next transition
    } else {
        index += 1;  // exact match, so need to add one to get the next
    }
    return new ZoneOffsetTransition(savingsInstantTransitions[index], wallOffsets[index], wallOffsets[index + 1]);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:46,代碼來源:ZoneRules.java

示例7: factory_ofInstant_tooBig

@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);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:TestOffsetDateTime_instants.java

示例8: factory_ofInstant_tooBig

@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);
    ZonedDateTime.ofInstant(instant, ZoneOffset.UTC);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:8,代碼來源:TCKZonedDateTime.java

示例9: factory_ofInstant_maxWithMaxOffset

public void factory_ofInstant_maxWithMaxOffset() {
    long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
    int year = Year.MAX_VALUE;
    long days = (year * 365L + (year / 4 - year / 100 + year / 400)) + 365 - days_0000_to_1970;
    Instant instant = Instant.ofEpochSecond((days + 1) * 24L * 60L * 60L - 1 - OFFSET_MAX.getTotalSeconds());
    OffsetDateTime test = OffsetDateTime.ofInstant(instant, OFFSET_MAX);
    assertEquals(test.getYear(), Year.MAX_VALUE);
    assertEquals(test.getMonth().getValue(), 12);
    assertEquals(test.getDayOfMonth(), 31);
    assertEquals(test.getOffset(), OFFSET_MAX);
    assertEquals(test.getHour(), 23);
    assertEquals(test.getMinute(), 59);
    assertEquals(test.getSecond(), 59);
    assertEquals(test.getNano(), 0);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:15,代碼來源:TestOffsetDateTime_instants.java

示例10: parseYear

int parseYear(String year, int defaultYear) {
    switch (year.toLowerCase()) {
    case "min":  return 1900;
    case "max":  return Year.MAX_VALUE;
    case "only": return defaultYear;
    }
    return Integer.parseInt(year);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:TzdbZoneRulesProvider.java

示例11: provider_goodParseData

@DataProvider(name="goodParseData")
Object[][] provider_goodParseData() {
    return new Object[][] {
            {"0000-01", YearMonth.of(0, 1)},
            {"0000-12", YearMonth.of(0, 12)},
            {"9999-12", YearMonth.of(9999, 12)},
            {"2000-01", YearMonth.of(2000, 1)},
            {"2000-02", YearMonth.of(2000, 2)},
            {"2000-03", YearMonth.of(2000, 3)},
            {"2000-04", YearMonth.of(2000, 4)},
            {"2000-05", YearMonth.of(2000, 5)},
            {"2000-06", YearMonth.of(2000, 6)},
            {"2000-07", YearMonth.of(2000, 7)},
            {"2000-08", YearMonth.of(2000, 8)},
            {"2000-09", YearMonth.of(2000, 9)},
            {"2000-10", YearMonth.of(2000, 10)},
            {"2000-11", YearMonth.of(2000, 11)},
            {"2000-12", YearMonth.of(2000, 12)},

            {"+12345678-03", YearMonth.of(12345678, 3)},
            {"+123456-03", YearMonth.of(123456, 3)},
            {"0000-03", YearMonth.of(0, 3)},
            {"-1234-03", YearMonth.of(-1234, 3)},
            {"-12345678-03", YearMonth.of(-12345678, 3)},

            {"+" + Year.MAX_VALUE + "-03", YearMonth.of(Year.MAX_VALUE, 3)},
            {Year.MIN_VALUE + "-03", YearMonth.of(Year.MIN_VALUE, 3)},
    };
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:29,代碼來源:TCKYearMonth.java

示例12: test_plusYears_big

@Test
public void test_plusYears_big() {
    long years = 20L + Year.MAX_VALUE;
    assertEquals(Year.of(-40).plusYears(years), Year.of((int) (-40L + years)));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:5,代碼來源:TCKYear.java

示例13: test_plusYears_long_big

@Test
public void test_plusYears_long_big() {
    long years = 20L + Year.MAX_VALUE;
    LocalDate test = LocalDate.of(-40, 6, 1).plusYears(years);
    assertEquals(test, LocalDate.of((int) (-40L + years), 6, 1));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:6,代碼來源:TCKLocalDate.java


注:本文中的java.time.Year.MAX_VALUE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。