01: package com.technoetic.xplanner.util;
02:
03: import java.util.Calendar;
04: import java.util.Date;
05:
06: /**
07: * User: Mateusz Prokopowicz Date: Aug 24, 2004 Time: 4:47:22 PM
08: */
09: public class TimeGenerator {
10:
11: int daysOffset = 0;
12:
13: public int moveCurrentDay(int days) {
14: return daysOffset += days;
15: }
16:
17: public void reset() {
18: daysOffset = 0;
19: }
20:
21: public Date getCurrentTime() {
22: Date now = new Date();
23: if (daysOffset != 0) {
24: return shiftDate(now, Calendar.DATE, daysOffset);
25: }
26: return now;
27: }
28:
29: public Date getTodaysMidnight() {
30: return getMidnight(getCurrentTime());
31: }
32:
33: public static Date getMidnight(Date date) {
34: Calendar calendar = Calendar.getInstance();
35: calendar.setTime(date);
36: calendar.set(Calendar.HOUR_OF_DAY, 0);
37: calendar.set(Calendar.MINUTE, 0);
38: calendar.set(Calendar.SECOND, 0);
39: calendar.set(Calendar.MILLISECOND, 0);
40: return calendar.getTime();
41: }
42:
43: public static Date shiftDate(Date date, int code, int value) {
44: Calendar cal = Calendar.getInstance();
45: cal.setTime((Date) date.clone());
46: cal.add(code, value);
47: return cal.getTime();
48: }
49: }
|