PageRenderTime 283ms CodeModel.GetById 131ms app.highlight 4ms RepoModel.GetById 147ms app.codeStats 0ms

/src/mpv5/utils/date/vTimeframe.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 78 lines | 33 code | 10 blank | 35 comment | 3 complexity | c1af4085456108a0e7a0767a5c8e35b5 MD5 | raw file
 1/*
 2 * 
 3 * 
 4 */
 5
 6package mpv5.utils.date;
 7
 8import java.util.Date;
 9
10/**
11 *
12 * This class implements a timeframe between two dates
13 */
14public class vTimeframe {
15    private Date start;
16    private Date end;
17    private long time;
18
19    /**
20     * Create a new timeframe
21     * @param start
22     * @param ende
23     */
24    public vTimeframe(Date start, Date ende) {
25        this.start = start; 
26        this.end = ende;   
27        this.time = end.getTime() - start.getTime();   
28    }
29
30    /**
31     * Create a new timeframe
32     * @param von
33     * @param bis
34     */
35    public vTimeframe(vDate von, vDate bis){
36        this.start = von.getDate();
37        this.end = bis.getDate();
38        this.time = end.getTime() - start.getTime();   
39    }
40
41    /**
42     * Checks whether the given date is within this timeframe
43     * @param day
44     * @return True if the date is within or at the timeframe`s start or end date
45     */
46    public boolean contains(Date day) {
47        return this.getEnd().equals(day) || this.getStart().equals(day) || (day.after(this.getStart()) && day.before(this.getEnd()));
48    }
49
50    /**
51     * The start
52     * @return
53     */
54    public Date getStart() {
55        return start;
56    }
57
58    /**
59     * The end date
60     * @return
61     */
62    public Date getEnd() {
63        return end;
64    }
65
66    /**
67     *
68     * @return The difference of start and end in millis
69     */
70    public long getTime() {
71        return time;
72    }
73    
74    @Override
75    public String toString(){
76     return start + " - " + end; 
77    }
78}