Getting the last day of any particular month of the year would be a simple array lookup if it were not for February and leap years. If we were to create a function to do the array lookup of the last day of the month for all months apart from February and then apply the three leap year rules then most of the function would be code to apply those leap year rules. The shortest version of the code would look like the following with the leap year rules being applied out of order (the third leap year rule which first takes effect in 4882 comes first as that is the rule that covers when there is a leap year not exactly divisible by four).
Even discarding that third leap year rule (given that for most situations we are unlikely to be dealing with dates that far in the future) we only save one line of code.
Once we have set a date object that way simply retrieving the day of the month from it gives us the last day of the month.
This article written by Stephen Chapman, Felgall Pty Ltd.