4

I'm trying to set hijri calendar to for example 3rd Wednesday of hijri months.
After some search, I reach to this code:

 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 calendar to 3rd Wednesday of gregorian calendar.
Is there any way to set 3rd Wednesday of month for other calendars in time4j lib?

Ole V.V.
  • 65,573
  • 11
  • 96
  • 117
max
  • 5,014
  • 11
  • 37
  • 66
  • I have opened a new [issue](https://github.com/MenoData/Time4J/issues/653) on the issue tracker of Time4J. In the meantime, the only workaround for this missing new feature would just be: iterating over all days of a given month and counting how often the searched weekday has happened. – Meno Hochschild May 26 '17 at 19:06
  • I have now implemented the new feature for version v3.33 (but not yet released). – Meno Hochschild Jun 14 '17 at 11:54
  • great job my friend with this lib . I look forward to seeing the new release. – max Jun 14 '17 at 12:55

1 Answers1

0

Sorry for late answer although the solution is already available since end of July 2017 in release v4.28/3.33. (I am now busy with overnext release v4.29/3.34 (sunrise/sunset-calculations)).

Every month-based calendar (including the HijriCalendar) supports a WEEKDAY_IN_MONTH-element since Time4A-version v3.33-2017b. It is chronology-specific because the month definition is different for every calendar. 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 how to use the new element can be found in the JUnit-test. The new element can also be used in format patterns with the CLDR-pattern-symbol "F". I show both the builder- and the 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: The new FrenchRepublicanCalendar (also introduced in v4.28/3.33) has no support for WEEKDAY_IN_MONTH because a) it uses a 10-day-week and b) some days (the sansculottides) are not part of any month.

Meno Hochschild
  • 38,305
  • 7
  • 88
  • 115