01: package vicazh.hyperpool.stream;
02:
03: import java.io.*;
04: import java.util.*;
05:
06: /**
07: * The period control
08: *
09: * @author Victor Zhigunov
10: * @version 0.4.0
11: */
12: public class PeriodControl implements Serializable {
13:
14: public long period;
15:
16: public boolean type;
17:
18: public Date start;
19:
20: public Date end;
21:
22: public boolean check(Date date) {
23: return type ? (date.after(start) || date.equals(start))
24: && (date.before(end) || date.equals(end)) : System
25: .currentTimeMillis()
26: - date.getTime() < period;
27: }
28:
29: static public Date firstTime(Date d) {
30: Calendar c = Calendar.getInstance();
31: c.setTime(d);
32: c.set(Calendar.AM_PM, Calendar.AM);
33: c.set(Calendar.HOUR, 0);
34: c.set(Calendar.MINUTE, 0);
35: c.set(Calendar.SECOND, 0);
36: c.set(Calendar.MILLISECOND, 0);
37: return c.getTime();
38: }
39:
40: static public Date lastTime(Date d) {
41: Calendar c = Calendar.getInstance();
42: c.setTime(d);
43: c.set(Calendar.AM_PM, Calendar.PM);
44: c.set(Calendar.HOUR, 11);
45: c.set(Calendar.MINUTE, 59);
46: c.set(Calendar.SECOND, 59);
47: c.set(Calendar.MILLISECOND, 999);
48: return c.getTime();
49: }
50: }
|