KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > plankton > DateUtil


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: DateUtil.java,v 1.3 2004/02/01 05:16:28 christianc Exp $
19  */

20 package org.enhydra.barracuda.plankton;
21
22 // import java specifics
23
import java.util.Calendar JavaDoc;
24
25 /**
26  * class holding some useful date utilities
27  */

28 public class DateUtil {
29
30     //===========================================================================
31
// CONSTRUCTORS
32
//===========================================================================
33

34     //===========================================================================
35
// QUERY METHODS
36
//===========================================================================
37

38     //===========================================================================
39
// MUTATOR METHODS
40
//===========================================================================
41

42     //===========================================================================
43
// HELPER METHODS
44
//===========================================================================
45

46     public static Calendar JavaDoc getFirstDateToday() {
47         return DateUtil.getFirstDate(0);
48     }
49
50     public static Calendar JavaDoc getLastDateToday() {
51         return DateUtil.getLastDate(0);
52     }
53
54     public static Calendar JavaDoc getFirstDateTomorrow() {
55         return DateUtil.getFirstDate(1);
56     }
57
58     public static Calendar JavaDoc getLastDateTomorrow() {
59         return DateUtil.getLastDate(1);
60     }
61
62     public static Calendar JavaDoc getFirstDateYesterday() {
63         return DateUtil.getFirstDate(-1);
64     }
65
66     public static Calendar JavaDoc getLastDateYesterday() {
67         return DateUtil.getLastDate(-1);
68     }
69
70     public static Calendar JavaDoc getFirstDate(int theOffsetInDays) {
71         Calendar JavaDoc date = Calendar.getInstance();
72         date.set(Calendar.MILLISECOND, 0);
73         date.set(Calendar.SECOND, 0);
74         date.set(Calendar.MINUTE, 0);
75         date.set(Calendar.HOUR_OF_DAY, 0);
76         date.add(Calendar.DATE, theOffsetInDays);
77         return date;
78     }
79
80     public static Calendar JavaDoc getLastDate(int theOffsetInDays) {
81         Calendar JavaDoc date = DateUtil.getFirstDate(theOffsetInDays + 1);
82         date.add(Calendar.MILLISECOND, -1);
83         return date;
84     }
85
86     //===========================================================================
87
// DATA MEMBERS
88
//===========================================================================
89

90     //===========================================================================
91
// STATIC DATA MEMBERS
92
//===========================================================================
93

94     // setup the constant for number of seconds in a day
95
public static final long SECONDS_IN_DAY = 24*60*60;
96
97     // setup the constant for number of milliseconds in a day
98
public static final long MILLISECONDS_IN_DAY = SECONDS_IN_DAY*1000;
99
100 }
101
Popular Tags