Search in sources :

Example 1 with HijrahChronology

use of java.time.chrono.HijrahChronology in project jdk8u_jdk by JetBrains.

the class TestUmmAlQuraChronology method test_aliases.

// Test for HijrahChronology Aliases
@Test
public void test_aliases() {
    HijrahChronology hc = (HijrahChronology) Chronology.of("Hijrah");
    assertEquals(hc, HijrahChronology.INSTANCE, "Alias for Hijrah-umalqura");
    hc = (HijrahChronology) Chronology.of("islamic");
    assertEquals(hc, HijrahChronology.INSTANCE, "Alias for Hijrah-umalqura");
}
Also used : HijrahChronology(java.time.chrono.HijrahChronology) Test(org.testng.annotations.Test)

Example 2 with HijrahChronology

use of java.time.chrono.HijrahChronology in project jdk8u_jdk by JetBrains.

the class TestUmmAlQuraChronology method Test_UmmAlQuraChronoRange.

// UmmAlQura chronology ranges for year, month and days for the HijrahChronology
@Test
public void Test_UmmAlQuraChronoRange() {
    HijrahChronology chrono = HijrahChronology.INSTANCE;
    ValueRange year = chrono.range(YEAR);
    assertEquals(year.getMinimum(), 1300, "Minimum year");
    assertEquals(year.getLargestMinimum(), 1300, "Largest minimum year");
    assertEquals(year.getMaximum(), 1600, "Largest year");
    assertEquals(year.getSmallestMaximum(), 1600, "Smallest Maximum year");
    ValueRange month = chrono.range(MONTH_OF_YEAR);
    assertEquals(month.getMinimum(), 1, "Minimum month");
    assertEquals(month.getLargestMinimum(), 1, "Largest minimum month");
    assertEquals(month.getMaximum(), 12, "Largest month");
    assertEquals(month.getSmallestMaximum(), 12, "Smallest Maximum month");
    ValueRange day = chrono.range(DAY_OF_MONTH);
    assertEquals(day.getMinimum(), 1, "Minimum day");
    assertEquals(day.getLargestMinimum(), 1, "Largest minimum day");
    assertEquals(day.getMaximum(), 30, "Largest day");
    assertEquals(day.getSmallestMaximum(), 29, "Smallest Maximum day");
}
Also used : ValueRange(java.time.temporal.ValueRange) HijrahChronology(java.time.chrono.HijrahChronology) Test(org.testng.annotations.Test)

Example 3 with HijrahChronology

use of java.time.chrono.HijrahChronology in project jdk8u_jdk by JetBrains.

the class TCKChronoLocalDateSerialization method test_hijrahSerialization_format.

//-----------------------------------------------------------------------
// Test HijrajDate serialization is a type, Chronology, year, month, day
//-----------------------------------------------------------------------
@Test()
public void test_hijrahSerialization_format() throws Exception {
    HijrahChronology chrono = HijrahChronology.INSTANCE;
    HijrahDate date = HijrahDate.of(1433, 10, 29);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    // Expect the type of the HijrahDate in the stream
    byte[] hijrahDateBytes = new byte[] { HIJRAH_DATE_TYPE };
    // Literal reference to Hijrah-Umalqura Chronology
    byte[] hijrahChronoBytes = new byte[] { 115, 113, 0, 126, 0, 0, /* p w   s q  ~   */
    119, 18, 1, 0, 15, 72, 105, 106, 114, 97, /* w     H i j r a */
    104, 45, 117, 109, 97, 108, 113, 117, 114, 97, /* h - u m a l q u r a */
    120 };
    // Build the sequence that represents the data in the stream
    baos = new ByteArrayOutputStream();
    try (DataOutputStream dos = new DataOutputStream(baos)) {
        dos.writeByte(ObjectStreamConstants.TC_BLOCKDATA);
        // 6 bytes follow
        dos.writeByte(6);
        dos.writeInt(date.get(YEAR));
        dos.writeByte(date.get(MONTH_OF_YEAR));
        dos.writeByte(date.get(DAY_OF_MONTH));
        dos.writeByte(ObjectStreamConstants.TC_ENDBLOCKDATA);
    }
    byte[] dateBytes = baos.toByteArray();
    assertSerializedBySer(date, hijrahDateBytes, hijrahChronoBytes, dateBytes);
}
Also used : HijrahDate(java.time.chrono.HijrahDate) DataOutputStream(java.io.DataOutputStream) HijrahChronology(java.time.chrono.HijrahChronology) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Example 4 with HijrahChronology

use of java.time.chrono.HijrahChronology in project jdk8u_jdk by JetBrains.

the class TCKHijrahChronology method test_InvalidEras.

//-----------------------------------------------------------------------
// Bad Era for Chronology.date(era,...) and Chronology.prolepticYear(Era,...)
//-----------------------------------------------------------------------
@Test
public void test_InvalidEras() {
    // Verify that the eras from every other Chronology are invalid
    for (Chronology chrono : Chronology.getAvailableChronologies()) {
        if (chrono instanceof HijrahChronology) {
            continue;
        }
        List<Era> eras = chrono.eras();
        for (Era era : eras) {
            try {
                ChronoLocalDate date = HijrahChronology.INSTANCE.date(era, 1, 1, 1);
                fail("HijrahChronology.date did not throw ClassCastException for Era: " + era);
            } catch (ClassCastException cex) {
                // ignore expected exception
                ;
            }
            try {
                @SuppressWarnings("unused") int year = HijrahChronology.INSTANCE.prolepticYear(era, 1);
                fail("HijrahChronology.prolepticYear did not throw ClassCastException for Era: " + era);
            } catch (ClassCastException cex) {
                // ignore expected exception
                ;
            }
        }
    }
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) Era(java.time.chrono.Era) HijrahEra(java.time.chrono.HijrahEra) HijrahChronology(java.time.chrono.HijrahChronology) HijrahChronology(java.time.chrono.HijrahChronology) Chronology(java.time.chrono.Chronology) IsoChronology(java.time.chrono.IsoChronology) Test(org.testng.annotations.Test)

Example 5 with HijrahChronology

use of java.time.chrono.HijrahChronology in project jdk8u_jdk by JetBrains.

the class TestUmmAlQuraChronology method Test_UmmAlQuraRanges.

// Test to verify the min/max field ranges for given dates
@Test(dataProvider = "dates")
public void Test_UmmAlQuraRanges(HijrahDate date, int minYear, int maxYear, int minMonth, int maxMonth, int minDay, int maxDay, int maxChronoDay) {
    // Check the chronology ranges
    HijrahChronology chrono = date.getChronology();
    ValueRange yearRange = chrono.range(YEAR);
    assertEquals(yearRange.getMinimum(), minYear, "Minimum year for Hijrah chronology");
    assertEquals(yearRange.getLargestMinimum(), minYear, "Largest minimum year for Hijrah chronology");
    assertEquals(yearRange.getMaximum(), maxYear, "Maximum year for Hijrah chronology");
    assertEquals(yearRange.getSmallestMaximum(), maxYear, "Smallest Maximum year for Hijrah chronology");
    ValueRange monthRange = chrono.range(MONTH_OF_YEAR);
    assertEquals(monthRange.getMinimum(), minMonth, "Minimum month for Hijrah chronology");
    assertEquals(monthRange.getMaximum(), maxMonth, "Maximum month for Hijrah chronology");
    ValueRange daysRange = chrono.range(DAY_OF_MONTH);
    assertEquals(daysRange.getMinimum(), minDay, "Minimum day for chronology");
    assertEquals(daysRange.getMaximum(), maxChronoDay, "Maximum day for Hijrah chronology");
    // Check the date ranges
    yearRange = date.range(YEAR);
    assertEquals(yearRange.getMinimum(), minYear, "Minimum year for Hijrah date");
    assertEquals(yearRange.getLargestMinimum(), minYear, "Largest minimum  year for Hijrah date");
    assertEquals(yearRange.getMaximum(), maxYear, "Maximum year for Hijrah date");
    assertEquals(yearRange.getSmallestMaximum(), maxYear, "Smallest maximum year for Hijrah date");
    monthRange = date.range(MONTH_OF_YEAR);
    assertEquals(monthRange.getMinimum(), minMonth, "Minimum month for HijrahDate");
    assertEquals(monthRange.getMaximum(), maxMonth, "Maximum month for HijrahDate");
    daysRange = date.range(DAY_OF_MONTH);
    assertEquals(daysRange.getMinimum(), minDay, "Minimum day for HijrahDate");
    assertEquals(daysRange.getMaximum(), maxDay, "Maximum day for HijrahDate");
}
Also used : ValueRange(java.time.temporal.ValueRange) HijrahChronology(java.time.chrono.HijrahChronology) Test(org.testng.annotations.Test)

Aggregations

HijrahChronology (java.time.chrono.HijrahChronology)6 Test (org.testng.annotations.Test)6 ValueRange (java.time.temporal.ValueRange)3 HijrahDate (java.time.chrono.HijrahDate)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 DateTimeException (java.time.DateTimeException)1 ChronoLocalDate (java.time.chrono.ChronoLocalDate)1 Chronology (java.time.chrono.Chronology)1 Era (java.time.chrono.Era)1 HijrahEra (java.time.chrono.HijrahEra)1 IsoChronology (java.time.chrono.IsoChronology)1 AbstractTCKTest (tck.java.time.AbstractTCKTest)1