java.time.chrono.Era Java Examples

The following examples show how to use java.time.chrono.Era. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TCKJapaneseChronology.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="prolepticYear")
public void test_isLeapYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    assertEquals(JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear);
    assertEquals(JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear).isLeap());

    JapaneseDate jdate = JapaneseDate.now();
    jdate = jdate.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
    if (isLeapYear) {
        assertEquals(jdate.lengthOfMonth(), 29);
    } else {
        assertEquals(jdate.lengthOfMonth(), 28);
    }
}
 
Example #2
Source File: TCKThaiBuddhistChronology.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="prolepticYear")
public void test_isLeapYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear) ;
    assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear - YDIFF).isLeap());

    ThaiBuddhistDate jdate = ThaiBuddhistDate.now();
    jdate = jdate.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
    if (isLeapYear) {
        assertEquals(jdate.lengthOfMonth(), 29);
    } else {
        assertEquals(jdate.lengthOfMonth(), 28);
    }
}
 
Example #3
Source File: CopticChronology.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int prolepticYear(Era era, int yearOfEra) {
    if (era instanceof CopticEra == false) {
        throw new ClassCastException("Era must be CopticEra");
    }
    return (era == CopticEra.AM ? yearOfEra : 1 - yearOfEra);
}
 
Example #4
Source File: TCKJapaneseChronology.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_JapaneseChronology_eras() {
    List<Era> actualEras = JapaneseChronology.INSTANCE.eras();
    Object[][] erasInfo = data_japanseseEras();
    assertEquals(actualEras.size(), erasInfo.length, "Wrong number of Eras");

    for (int i = 0; i < erasInfo.length; i++) {
        Object[] eraInfo = erasInfo[i];
        assertEquals(actualEras.get(i), eraInfo[0], "Singleton mismatch");
    }
}
 
Example #5
Source File: CopticChronology.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int prolepticYear(Era era, int yearOfEra) {
    if (era instanceof CopticEra == false) {
        throw new ClassCastException("Era must be CopticEra");
    }
    return (era == CopticEra.AM ? yearOfEra : 1 - yearOfEra);
}
 
Example #6
Source File: TCKEraSerialization.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "Eras")
Era[][] data_of_calendars() {
    return new Era[][] {
                {HijrahEra.AH},
                {IsoEra.BCE},
                {IsoEra.CE},
                {MinguoEra.BEFORE_ROC},
                {MinguoEra.ROC},
                {ThaiBuddhistEra.BEFORE_BE},
                {ThaiBuddhistEra.BE},
    };
}
 
Example #7
Source File: TCKMinguoChronology.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="prolepticYear")
public void test_prolepticYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    Era eraObj = MinguoChronology.INSTANCE.eraOf(eraValue);
    assertTrue(MinguoChronology.INSTANCE.eras().contains(eraObj));
    assertEquals(eraObj, era);
    assertEquals(MinguoChronology.INSTANCE.prolepticYear(era, yearOfEra), expectedProlepticYear);
}
 
Example #8
Source File: TCKMinguoChronology.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="prolepticYear")
public void test_isLeapYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    assertEquals(MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear);
    assertEquals(MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear + YDIFF).isLeap());

    MinguoDate minguo = MinguoDate.now();
    minguo = minguo.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
    if (isLeapYear) {
        assertEquals(minguo.lengthOfMonth(), 29);
    } else {
        assertEquals(minguo.lengthOfMonth(), 28);
    }
}
 
Example #9
Source File: TCKJapaneseChronology.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_Japanese_badEras() {
    int badEras[] = {-1000, -998, -997, -2, 3, 4, 1000};
    for (int badEra : badEras) {
        try {
            Era era = JapaneseChronology.INSTANCE.eraOf(badEra);
            fail("JapaneseChronology.eraOf returned " + era + " + for invalid eraValue " + badEra);
        } catch (DateTimeException ex) {
            // ignore expected exception
        }
    }
}
 
Example #10
Source File: CopticChronology.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int prolepticYear(Era era, int yearOfEra) {
    if (era instanceof CopticEra == false) {
        throw new ClassCastException("Era must be CopticEra");
    }
    return (era == CopticEra.AM ? yearOfEra : 1 - yearOfEra);
}
 
Example #11
Source File: TCKThaiBuddhistChronology.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="prolepticYear")
public void test_prolepticYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    Era eraObj = ThaiBuddhistChronology.INSTANCE.eraOf(eraValue);
    assertTrue(ThaiBuddhistChronology.INSTANCE.eras().contains(eraObj));
    assertEquals(eraObj, era);
    assertEquals(ThaiBuddhistChronology.INSTANCE.prolepticYear(era, yearOfEra), expectedProlepticYear);
}
 
Example #12
Source File: TCKThaiBuddhistChronology.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="prolepticYear")
public void test_isLeapYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear) ;
    assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear - YDIFF).isLeap());

    ThaiBuddhistDate jdate = ThaiBuddhistDate.now();
    jdate = jdate.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
    if (isLeapYear) {
        assertEquals(jdate.lengthOfMonth(), 29);
    } else {
        assertEquals(jdate.lengthOfMonth(), 28);
    }
}
 
Example #13
Source File: TCKJapaneseChronology.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_JapaneseChronology_eras() {
    List<Era> actualEras = JapaneseChronology.INSTANCE.eras();
    Object[][] erasInfo = data_japanseseEras();
    assertEquals(actualEras.size(), erasInfo.length, "Wrong number of Eras");

    for (int i = 0; i < erasInfo.length; i++) {
        Object[] eraInfo = erasInfo[i];
        assertEquals(actualEras.get(i), eraInfo[0], "Singleton mismatch");
    }
}
 
Example #14
Source File: TCKJapaneseChronology.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="japaneseEras")
public void test_JapaneseEra_singletons(Era expectedEra, int eraValue, String name) {
    JapaneseEra actualEra = JapaneseEra.valueOf(name);
    assertEquals(actualEra, expectedEra, "JapaneseEra.valueOf(name)");

    actualEra = JapaneseEra.of(eraValue);
    assertEquals(actualEra, expectedEra, "JapaneseEra.of(value)");

    String string = actualEra.toString();
    assertEquals(string, name, "JapaneseEra.toString()");
}
 
Example #15
Source File: TCKJapaneseChronology.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="prolepticYear")
public void test_prolepticYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    Era eraObj = JapaneseChronology.INSTANCE.eraOf(eraValue);
    assertTrue(JapaneseChronology.INSTANCE.eras().contains(eraObj));
    assertEquals(eraObj, era);
    assertEquals(JapaneseChronology.INSTANCE.prolepticYear(era, yearOfEra), expectedProlepticYear);
}
 
Example #16
Source File: TCKJapaneseChronology.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="prolepticYear")
public void test_isLeapYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    assertEquals(JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear);
    assertEquals(JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear).isLeap());

    JapaneseDate jdate = JapaneseDate.now();
    jdate = jdate.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
    if (isLeapYear) {
        assertEquals(jdate.lengthOfMonth(), 29);
    } else {
        assertEquals(jdate.lengthOfMonth(), 28);
    }
}
 
Example #17
Source File: TCKJapaneseChronology.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_Japanese_badEras() {
    int badEras[] = {-1000, -998, -997, -2, 4, 5, 1000};
    for (int badEra : badEras) {
        try {
            Era era = JapaneseChronology.INSTANCE.eraOf(badEra);
            fail("JapaneseChronology.eraOf returned " + era + " + for invalid eraValue " + badEra);
        } catch (DateTimeException ex) {
            // ignore expected exception
        }
    }
}
 
Example #18
Source File: TCKJapaneseChronology.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="japaneseEras")
public void test_Japanese_Eras(Era era, int eraValue, String name) {
    assertEquals(era.getValue(), eraValue, "EraValue");
    assertEquals(era.toString(), name, "Era Name");
    assertEquals(era, JapaneseChronology.INSTANCE.eraOf(eraValue), "JapaneseChronology.eraOf()");
    List<Era> eras = JapaneseChronology.INSTANCE.eras();
    assertTrue(eras.contains(era), "Era is not present in JapaneseChronology.INSTANCE.eras()");
}
 
Example #19
Source File: TCKJapaneseChronology.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_Japanese_badEras() {
    int badEras[] = {-1000, -998, -997, -2, 3, 4, 1000};
    for (int badEra : badEras) {
        try {
            Era era = JapaneseChronology.INSTANCE.eraOf(badEra);
            fail("JapaneseChronology.eraOf returned " + era + " + for invalid eraValue " + badEra);
        } catch (DateTimeException ex) {
            // ignore expected exception
        }
    }
}
 
Example #20
Source File: TCKJapaneseChronology.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="japaneseEras")
public void test_JapaneseEra_singletons(Era expectedEra, int eraValue, String name) {
    JapaneseEra actualEra = JapaneseEra.valueOf(name);
    assertEquals(actualEra, expectedEra, "JapaneseEra.valueOf(name)");

    actualEra = JapaneseEra.of(eraValue);
    assertEquals(actualEra, expectedEra, "JapaneseEra.of(value)");

    String string = actualEra.toString();
    assertEquals(string, name, "JapaneseEra.toString()");
}
 
Example #21
Source File: TCKJapaneseChronology.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_JapaneseChronology_eras() {
    List<Era> actualEras = JapaneseChronology.INSTANCE.eras();
    Object[][] erasInfo = data_japanseseEras();
    assertEquals(actualEras.size(), erasInfo.length, "Wrong number of Eras");

    for (int i = 0; i < erasInfo.length; i++) {
        Object[] eraInfo = erasInfo[i];
        assertEquals(actualEras.get(i), eraInfo[0], "Singleton mismatch");
    }
}
 
Example #22
Source File: CopticChronology.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public int prolepticYear(Era era, int yearOfEra) {
    if (era instanceof CopticEra == false) {
        throw new ClassCastException("Era must be CopticEra");
    }
    return (era == CopticEra.AM ? yearOfEra : 1 - yearOfEra);
}
 
Example #23
Source File: TCKThaiBuddhistChronology.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="prolepticYear")
public void test_prolepticYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    Era eraObj = ThaiBuddhistChronology.INSTANCE.eraOf(eraValue);
    assertTrue(ThaiBuddhistChronology.INSTANCE.eras().contains(eraObj));
    assertEquals(eraObj, era);
    assertEquals(ThaiBuddhistChronology.INSTANCE.prolepticYear(era, yearOfEra), expectedProlepticYear);
}
 
Example #24
Source File: TCKMinguoChronology.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="prolepticYear")
public void test_prolepticYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    Era eraObj = MinguoChronology.INSTANCE.eraOf(eraValue);
    assertTrue(MinguoChronology.INSTANCE.eras().contains(eraObj));
    assertEquals(eraObj, era);
    assertEquals(MinguoChronology.INSTANCE.prolepticYear(era, yearOfEra), expectedProlepticYear);
}
 
Example #25
Source File: TCKMinguoChronology.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="prolepticYear")
public void test_isLeapYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    assertEquals(MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear);
    assertEquals(MinguoChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear + YDIFF).isLeap());

    MinguoDate minguo = MinguoDate.now();
    minguo = minguo.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
    if (isLeapYear) {
        assertEquals(minguo.lengthOfMonth(), 29);
    } else {
        assertEquals(minguo.lengthOfMonth(), 28);
    }
}
 
Example #26
Source File: TCKEraSerialization.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "Eras")
Era[][] data_of_calendars() {
    return new Era[][] {
                {HijrahEra.AH},
                {IsoEra.BCE},
                {IsoEra.CE},
                {MinguoEra.BEFORE_ROC},
                {MinguoEra.ROC},
                {ThaiBuddhistEra.BEFORE_BE},
                {ThaiBuddhistEra.BE},
    };
}
 
Example #27
Source File: TCKJapaneseChronology.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="prolepticYear")
public void test_isLeapYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    assertEquals(JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear);
    assertEquals(JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear).isLeap());

    JapaneseDate jdate = JapaneseDate.now();
    jdate = jdate.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
    if (isLeapYear) {
        assertEquals(jdate.lengthOfMonth(), 29);
    } else {
        assertEquals(jdate.lengthOfMonth(), 28);
    }
}
 
Example #28
Source File: TCKThaiBuddhistChronology.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="prolepticYear")
public void test_isLeapYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear) ;
    assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear - YDIFF).isLeap());

    ThaiBuddhistDate jdate = ThaiBuddhistDate.now();
    jdate = jdate.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
    if (isLeapYear) {
        assertEquals(jdate.lengthOfMonth(), 29);
    } else {
        assertEquals(jdate.lengthOfMonth(), 28);
    }
}
 
Example #29
Source File: TCKThaiBuddhistChronology.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="prolepticYear")
public void test_isLeapYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear) ;
    assertEquals(ThaiBuddhistChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear - YDIFF).isLeap());

    ThaiBuddhistDate jdate = ThaiBuddhistDate.now();
    jdate = jdate.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
    if (isLeapYear) {
        assertEquals(jdate.lengthOfMonth(), 29);
    } else {
        assertEquals(jdate.lengthOfMonth(), 28);
    }
}
 
Example #30
Source File: TCKJapaneseChronology.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="prolepticYear")
public void test_prolepticYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    Era eraObj = JapaneseChronology.INSTANCE.eraOf(eraValue);
    assertTrue(JapaneseChronology.INSTANCE.eras().contains(eraObj));
    assertEquals(eraObj, era);
    assertEquals(JapaneseChronology.INSTANCE.prolepticYear(era, yearOfEra), expectedProlepticYear);
}