I'm writing a class that is dependent on months and how many days each month has. At the beginning of my class, I've written:
static final int JAN = 1;
static final int FEB = 2;
...
static final int DEC = 12;
It looks like a messy way of doing this, and I feel that enums would be more efficient. I need to be able to "increment" the month (where DEC + 1 = JAN), and need to be able to know have many days there are in the month (with FEB having 28).
I see two ways of doing this:
My current way, defining static final ints and using a switch statement to find the number of days, and when incrementing I always checks for whether the value would be greater than 12.
Create a set of enums, each with inputs for which month of the year it is and how many days it contains, and defining an "increment" method.
Is there a better way of doing this, or is (presumably) 2. the best way of doing this?
Date,Calendar,SimpleDateFormat, etc. are bloody awful, a train wreck of poor design, written by people who did not understand the subtleties nor complexities of date-time handling. Use only their replacement, the modern java.time classes built into Java 8 and later.