01: package vqwiki.db;
02:
03: import java.util.Calendar;
04: import java.util.Date;
05:
06: /**
07: Very Quick Wiki - WikiWikiWeb clone
08: Copyright (C) 2001-2002 Gareth Cronin
09:
10: This program is free software; you can redistribute it and/or modify
11: it under the terms of the latest version of the GNU Lesser General
12: Public License as published by the Free Software Foundation;
13:
14: This program is distributed in the hope that it will be useful,
15: but WITHOUT ANY WARRANTY; without even the implied warranty of
16: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: GNU Lesser General Public License for more details.
18:
19: You should have received a copy of the GNU Lesser General Public License
20: along with this program (gpl.txt); if not, write to the Free Software
21: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22: */
23:
24: public class DBDate extends java.util.Date {
25:
26: /**
27: *
28: */
29: public DBDate(java.sql.Timestamp stamp) {
30: super (stamp.getTime());
31: }
32:
33: /**
34: *
35: */
36: public DBDate(java.util.Date date) {
37: this .setTime(date.getTime());
38: }
39:
40: /**
41: *
42: */
43: public DBDate() {
44: super ();
45: }
46:
47: /**
48: *
49: */
50: public boolean equals(Object o) {
51: if (!(o instanceof java.util.Date))
52: return false;
53: Date other = (Date) o;
54: Calendar cal1 = Calendar.getInstance();
55: Calendar cal2 = Calendar.getInstance();
56: cal1.setTime(this );
57: cal2.setTime(other);
58: cal1.set(Calendar.MILLISECOND, 0);
59: cal2.set(Calendar.MILLISECOND, 0);
60: return cal1.equals(cal2);
61: }
62:
63: /**
64: *
65: */
66: public java.sql.Timestamp asTimestamp() {
67: return new java.sql.Timestamp(this .getTime());
68: }
69:
70: /**
71: *
72: */
73: public java.sql.Timestamp startOfDayStamp() {
74: Calendar cal = Calendar.getInstance();
75: cal.setTime(this );
76: cal.set(Calendar.HOUR_OF_DAY, 0);
77: cal.set(Calendar.MINUTE, 0);
78: cal.set(Calendar.MILLISECOND, 0);
79: return new java.sql.Timestamp(cal.getTime().getTime());
80: }
81:
82: /**
83: *
84: */
85: public java.sql.Timestamp endOfDayStamp() {
86: Calendar cal = Calendar.getInstance();
87: cal.setTime(this );
88: cal.set(Calendar.HOUR_OF_DAY, 23);
89: cal.set(Calendar.MINUTE, 59);
90: cal.set(Calendar.MILLISECOND, 0);
91: return new java.sql.Timestamp(cal.getTime().getTime());
92: }
93: }
|