View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2001-2004 Open World Ltd
4   //
5   // This file is part of MillScript.
6   //
7   // MillScript is free software; you can redistribute it and/or modify it under
8   // the terms of the GNU General Public License as published by the Free
9   // Software Foundation; either version 2 of the License, or (at your option)
10  // any later version.
11  //
12  // MillScript is distributed in the hope that it will be useful, but WITHOUT
13  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  // more details.
16  //
17  // You should have received a copy of the GNU General Public License along with
18  // MillScript; if not, write to the Free Software Foundation, Inc., 59 Temple
19  // Place, Suite 330, Boston, MA  02111-1307  USA
20  ////////////////////////////////////////////////////////////////////////////////
21  import java.util.*;
22  
23  public class DateTools {
24  
25  	// Return a GregorianCalendar Object representing the current date
26  	public static GregorianCalendar now() {
27  
28  		return ( GregorianCalendar ) Calendar.getInstance();
29  
30  	}
31  
32  	// Return the given date, offset by a given number of days, months and years
33  	public static GregorianCalendar getRelativeDate( Calendar when, Integer days, Integer months, Integer years ) {
34  
35  		GregorianCalendar now = ( GregorianCalendar ) when.clone();
36  
37  		now.add( Calendar.DATE, days.intValue() );
38  		now.add( Calendar.MONTH, months.intValue() );
39  		now.add( Calendar.YEAR, years.intValue() );
40  
41  		return now;
42  
43  	}
44  
45  	// Return the day of the week associated with a given date
46  	public static Integer getDay( Calendar when ) {
47  
48  		return new Integer( when.get( Calendar.DAY_OF_WEEK ) );
49  
50  	}
51  
52  	// Return the month associated with a given date
53  	public static Integer getMonth( Calendar when ) {
54  
55  		// Compensate for the zero-indexing of months in Java
56  		return new Integer( when.get( Calendar.MONTH ) + 1 );
57  
58  	}
59  
60  	// Return the year associated with a given date
61  	public static Integer getYear( Calendar when ) {
62  
63  		return new Integer( when.get( Calendar.YEAR ) );
64  
65  	}
66  
67  	// Return the day of the month associated with a given date
68  	public static Integer getDate( Calendar when ) {
69  
70  		return new Integer( when.get( Calendar.DATE ) );
71  
72  	}
73  
74  }