Is it possible to have month 13 on a date in Java?

Asked

Viewed 574 times

22

I was looking at the class documentation Formatter java 7, this link from Oracle itself, when I noticed myself with the following example below:

Screenshot da tela do browser

What intrigued me was the example given for the month formatting option, m: which are the numbers from 1 to 13.

All the examples given for the other formatting options are valid and have coherent values, which leads me to believe that yes, it is possible to have a 13th month in Java. The point is, what date UTC, and on what calendar, would return me one month 13?

Or really this is the only example of the page that does not match the reality, and the value 13 was typed by chance, without thinking?

  • 8

    It is used in HR systems so that they can pay the 13th salary of their employees :)

  • 1

    @Math I don’t doubt it should be some gambiarra! Let’s see if anyone knows :D

  • 1

    See this link too, I was curious about this lunatic thing Calendar of 13 moons

2 answers

19


Looking further down, the documentation you linked has the same repeated snippet, only this time with a more detailed explanation, and it says:

Month, Formatted as two digits with Leading zeros as necessary, i.e. 01 - 13, Where "01" is the first Month of the year and ("13" is a special value required to support lunar calendars).

In free translation:

Month, formatted with two digits with zero preceding when needed. Ex: 01 to 13, where "01" is the first month of the year and ("13" is a special value required to support lunar calendars).

The name of the month in English is UNDECIMBER :

Value of the MONTH field indicating the Thirteenth Month of the year. Although Gregoriancalendar does not use this value, lunar calendars do.

In free translation:

Value of the MONTH field indicating the thirteenth month of the year. Although Gregoriancalendar does not use this value, lunar calendars use.

(In), fortunately, there is no standard Java class that supports the lunar calendar, but it is possible to find implementations made by lunatics like this one: hoveychen/lunar_calendar @ Github

When trying to use month 13 on a Gregorian calendar object, we get the first month of the following year. Example:

import java.util.Calendar;

public class Lunatico {
    public static void main(String[] args) {
        Calendar c1 = Calendar.getInstance();
        c1.set(2015, Calendar.DECEMBER, 20);   //data: 20/12/2015

        Calendar c2 = Calendar.getInstance();
        c2.set(2015, Calendar.UNDECIMBER, 20); //data: 20/13/2015

        System.out.println(String.format("Dia normal: %1$te/%1$tm/%1$tY", c1));
        System.out.println(String.format("Dia (quase) lunático: %1$te/%1$tm/%1$tY", c2));

        System.out.println(String.format("\nMês: %1$tB", c2)); //escrevendo por extenso
    }
}

Upshot:

Normal day: 20/12/2015
Lunatic day (almost) 20/01/2016

Month: January

Notice that inside the String.format() I used the m, as the documentation explains.

  • Thanks, Math! Killed! This page is so big that I never noticed that it kind of repeats twice the explanations! Passed beaten! :)

  • 2

    Yes, she is a giant indeed, I found it kind of lucky. And it’s a curious fact to know :)

  • 1

    My Facebook friends were intrigued, and I will take the test... What would be the "name" of this month?! :)

  • @carlosrafaelgn after you find out tell us, also I’m curious, but I’m not with the hand in the dough now to make the test.

  • 4

    What about Onzembro? P

  • 5

    Well I thought Java programmers were lunatics, here’s the proof!

  • 2

    I suggest Thirteen, but he already has a name, look Lunar Calendar :P

  • 2

    Following the logic of October, November, December would be onzembro haha

  • 1

    @abfurlan As soon as I finish what I’m doing, I’ll take the test! I’m shocked! D

  • 2

    So much for my late afternoon, now I’m going to research lunar calendars, why December and not December, test Datetime and so on :-/

  • 1

    @carlosrafaelgn I found the name of the damned: UNDECIMBER, we need to see how this looks in Portuguese. I will collect more legal information and improve the response :)

  • I liked the pun using lunatics.

Show 7 more comments

12

Some calendars may be 13 months, for example Igbo calendar.

The main reason a lunar calendar is 13 months is that each lunar cycle is approximately 28 days (4 weeks). If we multiply 28 by 13, the result is 364 days. That is, in one year we have 13 complete lunar cycles (and another 1 or 2 days left). In purely lunar calendars, each lunar cycle corresponds to a month, and therefore the year would be 13 months.

However, not all calendars with 13 months are necessarily lunar, such as coptic calendar and the ethiopian calendar. In these calendars we have 12 months with 30 days each and a thirteenth-month short with only 5 days.

Some other calendars, although based on lunar cycles, are 12 months long, such as the islamic calendar and the hindu calendar.

In a few years, the hebrew calendar have a thirteenth leap month as well.

The name of the 13th month is undezembre, which would be the eleventh month (not counting January and February) because December was the tenth month before the Romans make a reformation on the calendar in the year 46 before Christ. Also, the fourteenth month, for calendars where this may exist, is called twelfth.

  • 1

    Fantastic, Victor! Your knowledge of calendars haunts! D

  • 4

    I recovered my late afternoon, I don’t need to research anything else :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.