001 /**
002 * Copyright 2007 Mike Kroutikov.
003 *
004 * This program is free software; you can redistribute it and/or modify
005 * it under the terms of the Lesser GNU General Public License as
006 * published by the Free Software Foundation; either version 3 of
007 * the License, or (at your option) any later version.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012 * Lesser GNU General Public License for more details.
013 *
014 * You should have received a copy of the Lesser GNU General Public License
015 * along with this program. If not, see <http://www.gnu.org/licenses/>.
016 */
017
018 package org.otfeed.support;
019
020 import java.util.Calendar;
021 import java.util.Date;
022
023 /**
024 * Utility class: provides misc helper functions to conveniently
025 * instantiate Date class. Note that this class implicitly uses
026 * current time zone, and, therefore may not be appropriate for the
027 * applications that may be deployed in different timezones.
028 */
029 public final class DateUtil {
030 private DateUtil() { } // no instancies!
031
032 /**
033 * Builds Date object from date/time components.
034 *
035 * @param year year.
036 * @param month month.
037 * @param day day.
038 * @param hour hour.
039 * @param minute minute.
040 * @param second second.
041 * @return Date object.
042 */
043 public static final Date getDate(int year, int month, int day, int hour, int minute, int second) {
044 Calendar calendar = Calendar.getInstance();
045 calendar.set(year, month, day, hour, minute, second);
046
047 return calendar.getTime();
048 }
049
050 /**
051 * Builds Date object from date/time components.
052 *
053 * @param year year.
054 * @param month month.
055 * @param day day.
056 * @param hour hour.
057 * @param minute minute.
058 * @return Date object.
059 */
060 public static final Date getDate(int year, int month, int day, int hour, int minute) {
061 return getDate(year, month, day, hour, minute, 0);
062 }
063
064 /**
065 * Builds Date object from date/time components.
066 *
067 * @param year year.
068 * @param month month.
069 * @param day day.
070 * @param hour hour.
071 * @return Date object.
072 */
073 public static final Date getDate(int year, int month, int day, int hour) {
074 return getDate(year, month, day, hour, 0, 0);
075 }
076
077 /**
078 * Builds Date object from date/time components.
079 *
080 * @param year year.
081 * @param month month.
082 * @param day day.
083 * @return Date object.
084 */
085 public static final Date getDate(int year, int month, int day) {
086 return getDate(year, month, day, 0, 0, 0);
087 }
088
089 /**
090 * Builds Date object from date/time components.
091 *
092 * @param year year.
093 * @param month month.
094 * @return Date object.
095 */
096 public static final Date getDate(int year, int month) {
097 return getDate(year, month, 0, 0, 0, 0);
098 }
099
100 /**
101 * Builds Date object from date/time components.
102 *
103 * @param year year.
104 * @return Date object.
105 */
106 public static final Date getDate(int year) {
107 return getDate(year, 0, 0, 0, 0, 0);
108 }
109 }