1 package club.wpia.gigi.util;
6 * This Class consists of a millisecond timestamp that is only interesting up to
11 private static final int MILLI_HOUR = 60 * 60 * 1000;
13 public static final long MILLI_DAY = 24 * MILLI_HOUR;
18 * Creates a new {@link DayDate} from the SQL Day-exact variant {@link Date}
23 public DayDate(Date date) {
28 * Creates a new {@link DayDate} based on the given millisecond timestamp.
31 * the timestamp to create the Date from.
32 * @throws IllegalArgumentException
33 * if the parameter contains more precision than needed.
35 public DayDate(long millis) {
37 if (millis % MILLI_DAY != 0) {
38 throw new IllegalArgumentException();
43 * Gets the enclosed timestamp.
45 * @return the enclosed timestamp.
47 public long getTime() {
52 * Converts this DayDate to an {@link Date}.
54 * @return the corresponding {@link Date}
57 public Date toSQLDate() {
58 return new Date(time);
62 public boolean equals(Object obj) {
66 if ( !(obj instanceof DayDate)) {
67 throw new Error("You may not compare this date somthing other than a DayDate");
69 return ((DayDate) obj).time == time;
73 public int hashCode() {
74 return Long.hashCode(time);
77 public java.util.Date toDate() {
78 return new java.util.Date(time);
81 // Timezones currently reach from UTC-12 to UTC+14 that allows us to define
82 // the "earliest start" and "latest end" of a Date.
84 * Gets this date's starting point.
86 * @return The earliest point in time where this date was in any timezone
88 public java.util.Date start() {
89 return new java.util.Date(time - 12 * MILLI_HOUR);
93 * Gets this date's ending point.
95 * @return The latest point in time where this Date was any timezone
97 public java.util.Date end() {
98 return new java.util.Date(time + 14 * MILLI_HOUR + 24 * MILLI_HOUR);