java – Calendar. What does undecimber do?
The calendar class has a constant named undefcimber It describes the 13th month
Is this constant useful? In Wikipedia, it says the lunar calendar But the calendar was not implemented
Is there any solution for month 14 (duodecimber)?
I can't find so much on the Internet. I want to know more about this topic
Solution
As mentioned earlier, some lunar (and other ancient) calendars have 13 months An example is Coptic calendar
Although there is no implementation of the 13-month calendar extension Java util. Calendar, but there are some in the new API of Java 8 With new Java Time API, which also creates threeten extra project, which contains an implementation for that
This class is org threeten. extra. chrono. Coptic chronology, which extends native Java time. chrono. Chronology. I just made a sample code to create a date in this calendar and cycle its date:
// Coptic calendar CopticChronology cal = CopticChronology.INSTANCE; // range for month of year (from 1 to 13) System.out.println("month range: " + cal.range(ChronoField.MONTH_OF_YEAR)); // 1 - 13 // getting a date in Coptic calendar and loop through the months DateTimeFormatter fmt = DateTimeFormatter.ofPattern("dd/MM/yyyy"); // September 11th is equivalent to 01/01 in Coptic calendar CopticDate d = cal.date(LocalDate.of(2017,9,11)); for (int i = 0; i < 14; i++) { System.out.println(fmt.format(d)); d = d.plus(1,ChronoUnit.MONTHS); }
The output is:
month range: 1 - 13 01/01/1734 01/02/1734 01/03/1734 01/04/1734 01/05/1734 01/06/1734 01/07/1734 01/08/1734 01/09/1734 01/10/1734 01/11/1734 01/12/1734 01/13/1734 01/01/1735
Please note that this year has changed after the 13th month
For the Ethiopian calendar, threeten extra project also has an implementation, which also has 13 months
Moreover, as an example of a 14 month calendar, there is paxchronology class, which implements Pax calendar: a proposed reformed calendar system, but as far as I know, it has not been used yet
Reference Wikipedia:
And according to Javadoc:
Example:
PaxChronology paxCal = PaxChronology.INSTANCE; System.out.println("month range: " + paxCal.range(ChronoField.MONTH_OF_YEAR)); PaxDate pd = paxCal.date(1930,1,1); for (int i = 0; i < 15; i++) { // fmt is the same DateTimeFormatter from prevIoUs example System.out.println(fmt.format(pd)); // adjusting for first day of next month - using TemporalAdjuster because // adding 1 ChronoUnit.MONTHS throws an exception for 14th month (not sure why) pd = pd.plus(30,ChronoUnit.DAYS).with(TemporalAdjusters.firstDayOfMonth()); }
Output:
month range: 1 - 13/14 01/01/1930 01/02/1930 01/03/1930 01/04/1930 01/05/1930 01/06/1930 01/07/1930 01/08/1930 01/09/1930 01/10/1930 01/11/1930 01/12/1930 01/13/1930 01/14/1930 01/01/1931
You can notice that the year has changed after the 14th month The range is 1 – 13 / 14, because a few years can have 13 or 14 months, depending on whether it is a leap year