Search in sources :

Example 21 with HijrahDate

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

the class TestUmmAlQuraChronology method test_lastDayOfMonth.

// Test to get the last day of the month by adjusting the date with lastDayOfMonth() method
@Test(dataProvider = "monthDays")
public void test_lastDayOfMonth(int year, int month, int numDays) {
    HijrahDate hDate = HijrahChronology.INSTANCE.date(year, month, 1);
    hDate = hDate.with(TemporalAdjusters.lastDayOfMonth());
    assertEquals(hDate.get(ChronoField.DAY_OF_MONTH), numDays);
}
Also used : HijrahDate(java.time.chrono.HijrahDate) Test(org.testng.annotations.Test)

Example 22 with HijrahDate

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

the class TestExampleCode method test_library.

@Test
public void test_library() {
    HijrahDate date = HijrahDate.now();
    HijrahDate next = next(date);
    ChronoLocalDateTime<HijrahDate> noonTomorrow = tomorrowNoon(date);
    HijrahDate hd3 = noonTomorrow.toLocalDate();
    System.out.printf("  now: %s, noon tomorrow: %s%n", date, noonTomorrow);
}
Also used : HijrahDate(java.time.chrono.HijrahDate) Test(org.testng.annotations.Test)

Example 23 with HijrahDate

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

the class TestExampleCode method HijrahExample1.

void HijrahExample1() {
    HijrahDate hd2 = HijrahChronology.INSTANCE.date(1200, 1, 1);
    ChronoLocalDateTime<HijrahDate> hdt = hd2.atTime(LocalTime.MIDNIGHT);
    ChronoZonedDateTime<HijrahDate> zhdt = hdt.atZone(ZoneId.of("GMT"));
    HijrahDate hd3 = zhdt.toLocalDate();
    ChronoLocalDateTime<HijrahDate> hdt2 = zhdt.toLocalDateTime();
    HijrahDate hd4 = hdt2.toLocalDate();
    HijrahDate hd5 = next(hd2);
}
Also used : HijrahDate(java.time.chrono.HijrahDate)

Example 24 with HijrahDate

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

the class TestUmmAlQuraChronology method test_hijrahDateLimits.

// Check the date limits
@Test
public void test_hijrahDateLimits() {
    HijrahChronology chrono = HijrahChronology.INSTANCE;
    ValueRange yearRange = chrono.range(YEAR);
    ValueRange monthRange = chrono.range(MONTH_OF_YEAR);
    ValueRange dayRange = chrono.range(DAY_OF_MONTH);
    HijrahDate xx = chrono.date(1434, 1, 1);
    HijrahDate minDate = chrono.date((int) yearRange.getLargestMinimum(), (int) monthRange.getMinimum(), (int) dayRange.getMinimum());
    try {
        HijrahDate before = minDate.minus(1, ChronoUnit.DAYS);
        fail("Exception did not occur, minDate: " + minDate + ".minus(1, DAYS) = " + before);
    } catch (DateTimeException ex) {
    // ignore, this exception was expected
    }
    HijrahDate maxDate = chrono.date((int) yearRange.getSmallestMaximum(), (int) monthRange.getMaximum(), 1);
    int monthLen = maxDate.lengthOfMonth();
    maxDate = maxDate.with(DAY_OF_MONTH, monthLen);
    try {
        HijrahDate after = maxDate.plus(1, ChronoUnit.DAYS);
        fail("Exception did not occur, maxDate: " + maxDate + ".plus(1, DAYS) = " + after);
    } catch (DateTimeException ex) {
    // ignore, this exception was expected
    }
}
Also used : ValueRange(java.time.temporal.ValueRange) HijrahDate(java.time.chrono.HijrahDate) DateTimeException(java.time.DateTimeException) HijrahChronology(java.time.chrono.HijrahChronology) Test(org.testng.annotations.Test)

Example 25 with HijrahDate

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

the class TestUmmAlQuraChronology method test_getDayOfYear.

//-----------------------------------------------------------------------
// HijrahDate.with(DAY_OF_YEAR, n)
//-----------------------------------------------------------------------
@Test
public void test_getDayOfYear() {
    HijrahDate hd1 = HijrahChronology.INSTANCE.dateYearDay(1434, 1);
    for (int i = 1; i <= hd1.lengthOfYear(); i++) {
        HijrahDate hd = HijrahChronology.INSTANCE.dateYearDay(1434, i);
        int doy = hd.get(DAY_OF_YEAR);
        assertEquals(doy, i, "get(DAY_OF_YEAR) incorrect for " + i);
    }
}
Also used : HijrahDate(java.time.chrono.HijrahDate) Test(org.testng.annotations.Test)

Aggregations

HijrahDate (java.time.chrono.HijrahDate)26 Test (org.testng.annotations.Test)25 TemporalField (java.time.temporal.TemporalField)11 HashMap (java.util.HashMap)11 DateTimeException (java.time.DateTimeException)6 HijrahChronology (java.time.chrono.HijrahChronology)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 OffsetDateTime (java.time.OffsetDateTime)1 ZonedDateTime (java.time.ZonedDateTime)1 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 ValueRange (java.time.temporal.ValueRange)1 AbstractTCKTest (tck.java.time.AbstractTCKTest)1