A while back I implemented a report system in a project I was working on where you would send a server two dates (a ‘from date’ and a ‘to date’) and it will return results between those two dates. Well yesterday I had to extend that report system for monthly reports so I figured a drop-down menu with month selection is more convenient to the user than forcing him to manually set the dates from the first of the month to the last of that same month. So I created the drop-down menu, populated it with 12 month entries and moved on to program the logic behind the change handler. This is where I ran into a small problem.
You see, under normal circumstances when working with Java I would use the Java.Util.Calendar class for this, but unfortunately this class is not emulated in GWT (not yet at least). There is a slightly less powerful class that does calendar manipulations though, and is found under com.google.gwt.user.datepicker.client.CalendarUtil. So I figured I’ll use this. I took a quick look at the methods it offers and I wrote a quick and dirty way to get the last day of a certain month.