001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.core.service;
017:
018: import java.sql.Timestamp;
019: import java.text.ParseException;
020: import java.util.Calendar;
021: import java.util.Date;
022:
023: /**
024: * This interface defines methods that a DateTime service must provide
025: */
026: public interface DateTimeService {
027: /**
028: * Translates the specified date into a string without a time component, formatted according to "stringDateFormat" that the
029: * service is configured with
030: *
031: * @param date
032: * @return formatted string version of the specified date
033: */
034: public String toDateString(Date date);
035:
036: /**
037: * Translates the specified date into a string with a time component, formatted according to the "stringDateTimeFormat" that the
038: * service is configured with
039: *
040: * @param date
041: * @return formatted string version of the specified date
042: */
043: public String toDateTimeString(Date date);
044:
045: /**
046: * Translates the specified date into a string without a time component, formatted according to the specified pattern
047: *
048: * @param date
049: * @return formatted string version of the specified date
050: */
051: public String toString(Date date, String pattern);
052:
053: /**
054: * Returns the current date/time as a java.util.Date
055: *
056: * @return current date/time
057: */
058: public Date getCurrentDate();
059:
060: /**
061: * Returns the current date/time as a java.sql.Timestamp
062: *
063: * @return current date/time
064: */
065: public Timestamp getCurrentTimestamp();
066:
067: /**
068: * Returns the current date/time as a java.sql.Date
069: *
070: * @return current date/time
071: */
072: public java.sql.Date getCurrentSqlDate();
073:
074: /**
075: * Returns the current date as a java.sql.Date rounded back to midnight. This is what the JDBC driver is supposed to do with
076: * dates on their way to the database, so it can be convenient for comparing to dates from the database or input from the UI.
077: *
078: * @return current date at the most recent midnight in the JVM's timezone
079: */
080: public java.sql.Date getCurrentSqlDateMidnight();
081:
082: /**
083: * Returns a Calendar initialized with the current Date
084: *
085: * @return currennt Calendar
086: */
087: public Calendar getCurrentCalendar();
088:
089: /**
090: * Returns a Calendar initialized to the given Date
091: *
092: * @return date-specific Calendar
093: * @throws IllegalArgumentException if the given Date is null
094: */
095: public Calendar getCalendar(Date date);
096:
097: /**
098: * Translates the specified string into a date without a time component, formatted according to "stringDateFormat" that the
099: * service is configured with
100: *
101: * @param dateString
102: * @return the date representation of the specified dateString
103: * @throws ParseException
104: */
105: public Date convertToDate(String dateString) throws ParseException;
106:
107: /**
108: * Translates the specified string into a date with a time component, formatted according to "stringDateTimeFormat" that the
109: * service is configured with
110: *
111: * @param dateTimeString
112: * @return the date representation of the specified dateTimeString
113: * @throws ParseException
114: */
115: public Date convertToDateTime(String dateTimeString)
116: throws ParseException;
117:
118: /**
119: * Converts the given String into a java.sql.Timestamp instance according to the "stringDateTimeFormat" that the service is
120: * configured with
121: *
122: * @param timeString
123: * @return java.sql.Timestamp
124: * @throws IllegalArgumentException if the given string is null or blank
125: * @throws ParseException if the string cannot be converted
126: */
127: public java.sql.Timestamp convertToSqlTimestamp(String timeString)
128: throws ParseException;
129:
130: /**
131: * Converts the given String into a java.sql.Date instance
132: *
133: * @param dateString
134: * @return java.sql.Date
135: * @throws IllegalArgumentException if the given string is null or blank
136: * @throws ParseException if the string cannot be converted
137: */
138: public java.sql.Date convertToSqlDate(String dateString)
139: throws ParseException;
140:
141: /**
142: * Converts a Timestamp into a sql Date.
143: *
144: * @param timestamp
145: * @return
146: */
147: public java.sql.Date convertToSqlDate(Timestamp timestamp)
148: throws ParseException;
149:
150: /**
151: * Returns the number of days between two days - start and end date of some arbitrary period.
152: *
153: * @param date1 The first date in the period
154: * @param date2 The second date in the period
155: * @param inclusive Whether the result should include both the start and the end date. Otherwise it only includes one.
156: * @return int The number of days in the period
157: */
158: public int dateDiff(Date date1, Date date2, boolean inclusive);
159:
160: }
|