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 * @author Erik Brakkee
27 public class Time implements Comparable {
32 private static final int HOURS_PER_DAY = 24;
37 private static final int EARLY_HOUR = 3;
40 * Number of seconds per minute.
42 private static final double SECONDS_PER_MINUTE = 60.0;
55 * Constructs the time.
62 public Time(int aHour, int aMinute) {
72 public int getHour() {
81 public int getMinute() {
88 * @see java.lang.Object#toString()
91 public String toString() {
92 NumberFormat format = new DecimalFormat("00");
93 return format.format(_hour) + ":" + format.format(_minute);
97 * Convert time to floating point value. Useful for comparing two times.
99 * @return Converted value.
103 // Hack to make sure that programs appearing shortly after midnight are
105 // after those running during the day.
106 if (hour <= EARLY_HOUR) {
107 hour += HOURS_PER_DAY;
109 return (float) hour + (float) _minute / (float) SECONDS_PER_MINUTE;
115 * @see java.lang.Object#equals(java.lang.Object)
118 public boolean equals(Object aObject) {
119 if (!(aObject instanceof Time)) {
122 return toString().equals(aObject.toString());
126 * Compares based on time.
129 * Time object to compare to.
130 * @return See {@link Comparable#compareTo(T)}.
132 public int compareTo(Object aObject) {
133 if (!(aObject instanceof Time)) {
134 throw new IllegalArgumentException("object not an instance of Time");
136 Time time = (Time) aObject;
137 return new Float(asFloat()).compareTo(new Float(time.asFloat()));
143 * @see java.lang.Object#hashCode()
146 public int hashCode() {
147 return toString().hashCode();