001: /*
002: * $Id: AbstractTime.java 458489 2006-01-04 09:28:14Z ivaynberg $
003: * $Revision: 458489 $ $Date: 2006-01-04 10:28:14 +0100 (Wed, 04 Jan 2006) $
004: *
005: * ==============================================================================
006: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
007: * use this file except in compliance with the License. You may obtain a copy of
008: * the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
014: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
015: * License for the specific language governing permissions and limitations under
016: * the License.
017: */
018: package wicket.util.time;
019:
020: import java.text.SimpleDateFormat;
021: import java.util.Calendar;
022: import java.util.Date;
023:
024: /**
025: * Abstract base class for subclasses that represent a point in time (as opposed
026: * to a duration of time).
027: *
028: * @author Jonathan Locke
029: */
030: abstract class AbstractTime extends AbstractTimeValue {
031: /** Calendar for the local timezone */
032: static final Calendar localtime = Calendar.getInstance();
033:
034: /** Time format */
035: static final SimpleDateFormat timeFormat = new SimpleDateFormat(
036: "h.mma");
037:
038: /**
039: * Package local constructor for package subclasses only
040: *
041: * @param milliseconds
042: * The number of milliseconds in this time value
043: */
044: AbstractTime(final long milliseconds) {
045: super (milliseconds);
046: }
047:
048: /**
049: * @param that
050: * The time to compare with
051: * @return True if this time value is after that time value
052: */
053: public final boolean after(final AbstractTimeValue that) {
054: return greaterThan(that);
055: }
056:
057: /**
058: * @param that
059: * The time to compare with
060: * @return True if this time value is before that time value
061: */
062: public final boolean before(final AbstractTimeValue that) {
063: return lessThan(that);
064: }
065:
066: /**
067: * Converts this time to a time string using the formatter h.mma
068: *
069: * @return The date string
070: */
071: public final String toTimeString() {
072: return toTimeString(localtime);
073: }
074:
075: /**
076: * Converts this time to a date string using the date formatter h.mma
077: *
078: * @param calendar
079: * The calendar to use in the conversion
080: * @return The date string
081: */
082: public final String toTimeString(final Calendar calendar) {
083: synchronized (timeFormat) {
084: synchronized (calendar) {
085: timeFormat.setCalendar(calendar);
086: return timeFormat.format(new Date(getMilliseconds()))
087: .toLowerCase();
088: }
089: }
090: }
091:
092: /**
093: * Converts this time to a string suitable for use in a filesystem name
094: *
095: * @return This time as a formatted string
096: */
097: public String toString() {
098: return toTimeString();
099: }
100: }
|