1 package org.paneris.util;
2
3 import java.util.GregorianCalendar;
4
5 public class DateUtils {
6 private static final int[] monthLengths = {
7 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
8 };
9
10 private static final GregorianCalendar gregorianCalendar =
11 new GregorianCalendar();
12
13 /**
14 * The length of the given month, in days.
15 *
16 * @param y the year, as a number (2001 not 101)
17 * @param m the month, from 1 (May = 5, not 4)
18 */
19
20 public static int monthLength(int y, int m) {
21 return m == 2 ?
22 gregorianCalendar.isLeapYear(y) ? 29 : 28 :
23 monthLengths[m - 1];
24 }
25 }