Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: javatools/util/FormattedDate.java


1   /*
2    * FormattedDateTemp.java
3    *
4    * Created on 11 maggio 2002, 18.38
5       Javatools (modified version) - Some useful general classes.
6       Copyright (C) 2002-2003  Chris Bitmead (original) Antonio Petrelli (modified)
7   
8       This program is free software; you can redistribute it and/or modify
9       it under the terms of the GNU General Public License as published by
10      the Free Software Foundation; either version 2 of the License, or
11      (at your option) any later version.
12  
13      This program is distributed in the hope that it will be useful,
14      but WITHOUT ANY WARRANTY; without even the implied warranty of
15      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16      GNU General Public License for more details.
17  
18      You should have received a copy of the GNU General Public License
19      along with this program; if not, write to the Free Software
20      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  
22      Contact me at: brenmcguire@users.sourceforge.net
23   */
24  
25  package javatools.util;
26  
27  import java.util.Date;
28  import java.text.SimpleDateFormat;
29  
30  /**
31   * It's a java.util.Date, except in the fact it returns its "toString" value in
32   * a formatted way.
33   * @author Antonio Petrelli
34   * @version 0.0.1
35   */
36  public class FormattedDate {
37  
38      /** Creates new FormattedDateTemp */
39      public FormattedDate() {
40          date = new Date();
41          formatter = null;
42      }
43  
44      /** Creates a new FormattedDate.
45       * @param ldate The value in millis of the date.
46       */    
47      public FormattedDate(long ldate) {
48          date = new Date(ldate);
49          formatter = null;
50      }
51      
52      /** Creates a new FormattedDate.
53       * @param ddate The base date to refer to.
54       */    
55      public FormattedDate(Date ddate) {
56          date = ddate;
57          formatter = null;
58      }
59      
60      /** Returns a normal Date representing the same date.
61       * @return The Date.
62       */    
63      public Date getDate() {
64          return date;
65      }
66      
67      /** Checks if a given date is after this date.
68       * @param date The date to check.
69       * @return <CODE>true</CODE>: the passed date is after this date;
70       * <CODE>false</CODE>: otherwise.
71       */    
72      public boolean after(java.util.Date date) {
73          boolean retValue;
74          
75          retValue = date.after(date);
76          return retValue;
77      }
78      
79      /** Checks if a given date is after this date.
80       * @param date The date to check.
81       * @return <CODE>true</CODE>: the passed date is after this date;
82       * <CODE>false</CODE>: otherwise.
83       */    
84      public boolean before(java.util.Date date) {
85          boolean retValue;
86          
87          retValue = date.before(date);
88          return retValue;
89      }
90      
91      /** Clones this object.
92       * @return The cloned object.
93       */    
94      public java.lang.Object clone() {
95          java.lang.Object retValue;
96          
97          retValue = date.clone();
98          return retValue;
99      }
100     
101     /** Compares this object to another.
102      * @param obj The object to check.
103      * @return Zero if they are equal;
104      * positive if obj is after this Date;
105      * negative if obj is before this Date.
106      */    
107     public int compareTo(java.lang.Object obj) {
108         int retValue;
109         
110         retValue = date.compareTo(obj);
111         return retValue;
112     }
113     
114     /** Compares this date to a given date.
115      * @param date The date to check.
116      * @return Zero if they are equal;
117      * positive if date is after this Date;
118      * negative if date is before this Date.
119      */    
120     public int compareTo(java.util.Date date) {
121         int retValue;
122         
123         retValue = date.compareTo(date);
124         return retValue;
125     }
126     
127     /** Checks if an object equals this date.
128      * @param obj The object to check.
129      * @return <CODE>true</CODE>: the objects are equal;
130      * <CODE>false</CODE>: the objects are NOT equal;
131      */    
132     public boolean equals(java.lang.Object obj) {
133         boolean retValue;
134         
135         retValue = date.equals(obj);
136         return retValue;
137     }
138     
139     /** Returns the time of this date in millis.
140      * @return The value in millis for this date.
141      */    
142     public long getTime() {
143         long retValue;
144         
145         retValue = date.getTime();
146         return retValue;
147     }
148     
149     /** Returns a hash code for this object.
150      * @return The hash code for this object.
151      */    
152     public int hashCode() {
153         int retValue;
154         
155         retValue = date.hashCode();
156         return retValue;
157     }
158     
159     /** Sets the time in millis.
160      * @param param The time in millis.
161      */    
162     public void setTime(long param) {
163         date.setTime(param);
164     }
165     
166     /** Returns the date in a formatted way.
167      * @return A string representing this date in a formatted way.
168      */    
169     public java.lang.String toString() {
170         return formatter.format(date);
171     }
172     
173     /** Sets the formatter.
174      * @param pFormatter The date formatter to use.
175      */    
176     public void setFormatter(SimpleDateFormat pFormatter) {
177         formatter = pFormatter;
178     }
179     
180     /** Returns the current formatter to use.
181      * @return The currently using formatter.
182      */    
183     public SimpleDateFormat getFormatter() {
184         return formatter;
185     }
186     
187     private Date date;
188     private SimpleDateFormat formatter;
189 }