Debian Codegraph @

src/com/drew/lang/DateUtil.java

raw symbols SCIP
1 /*
2 * Copyright 2002-2019 Drew Noakes and contributors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * More information about this project is available at:
17 *
18 * https://drewnoakes.com/code/exif/
19 * https://github.com/drewnoakes/metadata-extractor
20 */
21 package com.drew.lang;
22
23 import java.util.Date;
24
25 /**
26 * @author Drew Noakes http://drewnoakes.com
27 */
28 public class DateUtil
29 {
30 private static int[] _daysInMonth365 = new int[] {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
31
32 /**
33 * The offset (in milliseconds) to add to a MP4 date/time integer value to
34 * align with Java's Epoch.
35 */
36 private static final long EPOCH_1_JAN_1904 = -2082844800000L;
37
38 public static boolean isValidDate(int year, int month, int day)
39 {
40 if (year < 1 || year > 9999 || month < 0 || month > 11)
41 return false;
42
43 int daysInMonth = _daysInMonth365[month];
44 if (month == 1)
45 {
46 boolean isLeapYear = year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
47 if (isLeapYear)
48 daysInMonth++;
49 }
50
51 return day >= 1 && day <= daysInMonth;
52 }
53
54 public static boolean isValidTime(int hours, int minutes, int seconds)
55 {
56 return hours >= 0 && hours < 24
57 && minutes >= 0 && minutes < 60
58 && seconds >= 0 && seconds < 60;
59 }
60
61 public static Date get1Jan1904EpochDate(long seconds)
62 {
63 return new Date((seconds * 1000) + EPOCH_1_JAN_1904);
64 }
65 }