File: DateUtil.java

package info (click to toggle)
libmetadata-extractor-java 2.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 6,416 kB
  • sloc: java: 35,343; xml: 200; sh: 11; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 884 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.drew.lang;

/**
 * @author Drew Noakes http://drewnoakes.com
 */
public class DateUtil
{
    private static int[] _daysInMonth365 = new int[] {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    public static boolean isValidDate(int year, int month, int day)
    {
        if (year < 1 || year > 9999 || month < 0 || month > 11)
            return false;

        int daysInMonth = _daysInMonth365[month];
        if (month == 1)
        {
            boolean isLeapYear = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
            if (isLeapYear)
                daysInMonth++;
        }

        return day >= 1 && day <= daysInMonth;
    }

    public static boolean isValidTime(int hours, int minutes, int seconds)
    {
        return hours >= 0 && hours < 24
            && minutes >= 0 && minutes < 60
            && seconds >= 0 && seconds < 60;
    }
}