Java – get the weekly week in Hijri calendar in time4j

I'm trying to set the Hijri calendar to, for example, the third Wednesday of the Hijri month

PlainDate date = PlainDate.of(2017,3,1); // first of march 2017
 System.out.println(date.with(WEEKDAY_IN_MONTH.setToThird(WEDNESDAY)));

But as you can see, this sets the calendar to the third Wednesday of the Gregorian calendar Is there any way to set the third Wednesday for other calendars in time4j lib?

Solution

Sorry for the late answer, although the solution was released in version v4.0 at the end of July 2017 28 / 3.33. (I am now busy with the following version v4.29 / 3.34 (Sunrise / sunset calculation))

From time4a version v3 From 33-2017b, weekday is supported in the calendar of each month (including hijricalendar)_ IN_ The month element It is arranged in chronological order because the month definitions of each calendar are different Example:

HijriCalendar hijri =
  HijriCalendar.of(
    HijriCalendar.VARIANT_UMALQURA,1395,HijriMonth.RAMADAN,1); // Sunday,1975-09-07
assertThat(
  hijri.with(HijriCalendar.WEEKDAY_IN_MONTH.setTo(3,Weekday.WEDNESDAY)),is(hijri.plus(17,HijriCalendar.Unit.DAYS))); // AH-1395-09-18

More examples of how to use new elements can be found in JUnit - test The new element can also be used for format patterns with cldr pattern symbol "F" I showed the builder and pattern based approach:

ChronoFormatter<HijriCalendar> f1 =
        ChronoFormatter.setUp(HijriCalendar.family(),Locale.ENGLISH)
            .addEnglishOrdinal(HijriCalendar.WEEKDAY_IN_MONTH)
            .addPattern(" EEEE 'in' MMMM",PatternType.CLDR)
            .build();
    assertThat(f1.format(hijri),is("1st Sunday in Ramadan"));

    ChronoFormatter<HijriCalendar> f2 =
        ChronoFormatter.ofPattern(
            "F. EEEE 'im' MMMM",PatternType.CLDR,Locale.GERMAN,HijriCalendar.family());
    assertThat(f2.format(hijri),is("1. Sonntag im Ramadan"));

Side note: weekday is not supported in the new French Republic calendar (also introduced in v4.28 / 3.33)_ IN_ Month, because a) it uses a 10 day week and b) some days are not part of any month

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>