X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=crawler%2Fkiss%2Fsrc%2Forg%2Fwamblee%2Fcrawler%2Fkiss%2Fguide%2FTime.java;h=2d05bac10928569be7063501337c2ff354af5c22;hb=2b4a157f578b02685d8f883436c38ac40133765f;hp=52695e109ec1acca802da69e4543a7a343db5fdd;hpb=6984ec9ac2199a2ff2c3370ad92ddafb00a16c77;p=utils diff --git a/crawler/kiss/src/org/wamblee/crawler/kiss/guide/Time.java b/crawler/kiss/src/org/wamblee/crawler/kiss/guide/Time.java index 52695e10..2d05bac1 100644 --- a/crawler/kiss/src/org/wamblee/crawler/kiss/guide/Time.java +++ b/crawler/kiss/src/org/wamblee/crawler/kiss/guide/Time.java @@ -24,6 +24,16 @@ import java.text.NumberFormat; */ public class Time implements Comparable { + /** + * + */ + private static final int HOURS_PER_DAY = 24; + + /** + * + */ + private static final int EARLY_HOUR = 3; + /** * Number of seconds per minute. */ @@ -87,7 +97,13 @@ public class Time implements Comparable { * @return Converted value. */ float asFloat() { - return (float) _hour + (float) _minute / (float) SECONDS_PER_MINUTE; + int hour = _hour; + // Hack to make sure that programs appearing shortly after midnight are sorted + // after those running during the day. + if ( hour <= EARLY_HOUR ) { + hour += HOURS_PER_DAY; + } + return (float) hour + (float) _minute / (float) SECONDS_PER_MINUTE; } /* @@ -110,7 +126,7 @@ public class Time implements Comparable { */ public int compareTo(Object aObject) { if (!(aObject instanceof Time)) { - throw new RuntimeException("object not an instance of Time"); + throw new IllegalArgumentException("object not an instance of Time"); } Time time = (Time) aObject; return new Float(asFloat()).compareTo(new Float(time.asFloat()));