2 * Copyright 2005 the original author or authors.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.wamblee.crawler.kiss.guide;
19 import java.text.DecimalFormat;
20 import java.text.NumberFormat;
23 * TIme at which a program starts or ends.
25 public class Time implements Comparable {
30 private static final int HOURS_PER_DAY = 24;
35 private static final int EARLY_HOUR = 3;
38 * Number of seconds per minute.
40 private static final double SECONDS_PER_MINUTE = 60.0;
53 * Constructs the time.
60 public Time(int aHour, int aMinute) {
70 public int getHour() {
79 public int getMinute() {
86 * @see java.lang.Object#toString()
89 public String toString() {
90 NumberFormat format = new DecimalFormat("00");
91 return format.format(_hour) + ":" + format.format(_minute);
95 * Convert time to floating point value. Useful for comparing two times.
97 * @return Converted value.
101 // Hack to make sure that programs appearing shortly after midnight are
103 // after those running during the day.
104 if (hour <= EARLY_HOUR) {
105 hour += HOURS_PER_DAY;
107 return (float) hour + (float) _minute / (float) SECONDS_PER_MINUTE;
113 * @see java.lang.Object#equals(java.lang.Object)
116 public boolean equals(Object aObject) {
117 if (!(aObject instanceof Time)) {
120 return toString().equals(aObject.toString());
124 * Compares based on time.
127 * Time object to compare to.
128 * @return See {@link Comparable#compareTo(T)}.
130 public int compareTo(Object aObject) {
131 if (!(aObject instanceof Time)) {
132 throw new IllegalArgumentException("object not an instance of Time");
134 Time time = (Time) aObject;
135 return new Float(asFloat()).compareTo(new Float(time.asFloat()));
141 * @see java.lang.Object#hashCode()
144 public int hashCode() {
145 return toString().hashCode();