Search in sources :

Example 16 with HijrahDate

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

the class TestUmmAlQuraChronology method test_formatterOfLocalizedDate.

// Test to verify the localized dates using ofLocalizedDate() method
@Test(dataProvider = "chronoDateTimes")
public void test_formatterOfLocalizedDate(int year, int month, int day, String expected) {
    HijrahDate hd = HijrahChronology.INSTANCE.date(year, month, day);
    ChronoLocalDateTime<HijrahDate> hdt = hd.atTime(LocalTime.NOON);
    hdt = hdt.plus(1, ChronoUnit.YEARS);
    hdt = hdt.plus(1, ChronoUnit.MONTHS);
    hdt = hdt.plus(1, ChronoUnit.DAYS);
    hdt = hdt.plus(1, ChronoUnit.HOURS);
    hdt = hdt.plus(1, ChronoUnit.MINUTES);
    hdt = hdt.plus(1, ChronoUnit.SECONDS);
    DateTimeFormatter df = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).withChronology(Chronology.of("Hijrah-umalqura")).withLocale(Locale.US);
    assertEquals(df.format(hdt), expected);
}
Also used : HijrahDate(java.time.chrono.HijrahDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.testng.annotations.Test)

Example 17 with HijrahDate

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

the class TestUmmAlQuraChronology method test_temporalDayAdjustments.

// Test to get the adjusted date from a given date using TemporalAdjuster methods
@Test
public void test_temporalDayAdjustments() {
    HijrahDate date = HijrahDate.of(1554, 7, 21);
    assertEquals(date.with(TemporalAdjusters.firstDayOfMonth()), HijrahDate.of(1554, 7, 1));
    assertEquals(date.with(TemporalAdjusters.lastDayOfMonth()), HijrahDate.of(1554, 7, 29));
    assertEquals(date.with(TemporalAdjusters.firstDayOfNextMonth()), HijrahDate.of(1554, 8, 1));
    assertEquals(date.with(TemporalAdjusters.firstDayOfNextYear()), HijrahDate.of(1555, 1, 1));
    assertEquals(date.with(TemporalAdjusters.firstDayOfYear()), HijrahDate.of(1554, 1, 1));
    assertEquals(date.with(TemporalAdjusters.lastDayOfYear()), HijrahDate.of(1554, 12, 30));
}
Also used : HijrahDate(java.time.chrono.HijrahDate) Test(org.testng.annotations.Test)

Example 18 with HijrahDate

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

the class TestUmmAlQuraChronology method test_withDayOfYearTooLarge.

@Test(expectedExceptions = java.time.DateTimeException.class)
public void test_withDayOfYearTooLarge() {
    HijrahDate hd = HijrahChronology.INSTANCE.dateYearDay(1435, 1);
    HijrahDate hd2 = hd.with(DAY_OF_YEAR, hd.lengthOfYear() + 1);
}
Also used : HijrahDate(java.time.chrono.HijrahDate) Test(org.testng.annotations.Test)

Example 19 with HijrahDate

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

the class TestUmmAlQuraChronology method test_withDayOfYearTooSmall.

@Test(expectedExceptions = java.time.DateTimeException.class)
public void test_withDayOfYearTooSmall() {
    HijrahDate hd = HijrahChronology.INSTANCE.dateYearDay(1435, 1);
    HijrahDate hd2 = hd.with(DAY_OF_YEAR, 0);
}
Also used : HijrahDate(java.time.chrono.HijrahDate) Test(org.testng.annotations.Test)

Example 20 with HijrahDate

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

the class TCKHijrahChronology method test_resolve_yearOfEra_yearOfEraOnly_valid.

@Test(dataProvider = "resolve_styles")
public void test_resolve_yearOfEra_yearOfEraOnly_valid(ResolverStyle style) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR_OF_ERA, 1343L);
    HijrahDate date = HijrahChronology.INSTANCE.resolveDate(fieldValues, style);
    assertEquals(date, null);
    assertEquals(fieldValues.get(ChronoField.YEAR_OF_ERA), (style != ResolverStyle.STRICT) ? null : (Long) 1343L);
    assertEquals(fieldValues.get(ChronoField.YEAR), (style == ResolverStyle.STRICT) ? null : (Long) 1343L);
    assertEquals(fieldValues.size(), 1);
}
Also used : HijrahDate(java.time.chrono.HijrahDate) TemporalField(java.time.temporal.TemporalField) HashMap(java.util.HashMap) 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