posted 14 years ago
No offense, but I have to say that class is a mess. First of all, you use a lot of formatting + parsing to get rid of the day, just to set it afterwards. Second, your getLastDay method does not take into account daylight savings time, when one day can have 23 hours instead of 24. Thirdly, your if-statement in the last method is just nasty. A switch would have made more sense:
That said, all your methods could have been written using only Date and Calendar; no formatting and re-parsing, just the final formatting:
Not only is it shorter (1 line each for the first two methods, and don't get me started on the last one), it is also more robust (the daylight savings time thingy, Calendar has proven itself*) and easier to understand.
* A lot of people recommend using Joda time over Calendar. I feel that their motivations are more based on usability than Calendar not working.