001    /*
002    * Copyright 2004 The Apache Software Foundation
003    *
004    * Licensed under the Apache License, Version 2.0 (the "License");
005    * you may not use this file except in compliance with the License.
006    * You may obtain a copy of the License at
007    *
008    *     http://www.apache.org/licenses/LICENSE-2.0
009    *
010    * Unless required by applicable law or agreed to in writing, software
011    * distributed under the License is distributed on an "AS IS" BASIS,
012    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013    * See the License for the specific language governing permissions and
014    * limitations under the License.
015    */
016    
017    package cal;
018    
019    import java.text.DateFormat;
020    import java.util.*;
021    
022    public class JspCalendar {
023        Calendar  calendar = null;
024        Date currentDate;
025    
026        public JspCalendar() {
027            calendar = Calendar.getInstance();
028            Date trialTime = new Date();
029            calendar.setTime(trialTime);
030        }
031    
032    
033        public int getYear() {
034            return calendar.get(Calendar.YEAR);
035        }
036        
037        public String getMonth() {
038            int m = getMonthInt();
039            String[] months = new String [] { "January", "February", "March",
040                                            "April", "May", "June",
041                                            "July", "August", "September",
042                                            "October", "November", "December" };
043            if (m > 12)
044                return "Unknown to Man";
045            
046            return months[m - 1];
047    
048        }
049    
050        public String getDay() {
051            int x = getDayOfWeek();
052            String[] days = new String[] {"Sunday", "Monday", "Tuesday", "Wednesday", 
053                                          "Thursday", "Friday", "Saturday"};
054    
055            if (x > 7)
056                return "Unknown to Man";
057    
058            return days[x - 1];
059    
060        }
061        
062        public int getMonthInt() {
063            return 1 + calendar.get(Calendar.MONTH);
064        }
065    
066        public String getDate() {
067            return getMonthInt() + "/" + getDayOfMonth() + "/" +  getYear();        
068        }
069    
070        public String getCurrentDate() {
071            Date dt = new Date ();
072            calendar.setTime (dt);
073            return getMonthInt() + "/" + getDayOfMonth() + "/" +  getYear();
074    
075        }
076    
077        public String getNextDate() {
078            calendar.set (Calendar.DAY_OF_MONTH, getDayOfMonth() + 1);
079            return getDate ();
080        }
081    
082        public String getPrevDate() {
083            calendar.set (Calendar.DAY_OF_MONTH, getDayOfMonth() - 1);
084            return getDate ();
085        }
086    
087        public String getTime() {
088            return getHour() + ":" + getMinute() + ":" + getSecond();
089        }
090    
091        public int getDayOfMonth() {
092            return calendar.get(Calendar.DAY_OF_MONTH);
093        }
094    
095        public int getDayOfYear() {
096            return calendar.get(Calendar.DAY_OF_YEAR);
097        }
098    
099        public int getWeekOfYear() {
100            return calendar.get(Calendar.WEEK_OF_YEAR);
101        }
102    
103        public int getWeekOfMonth() {
104            return calendar.get(Calendar.WEEK_OF_MONTH);
105        }
106    
107        public int getDayOfWeek() {
108            return calendar.get(Calendar.DAY_OF_WEEK);
109        }
110         
111        public int getHour() {
112            return calendar.get(Calendar.HOUR_OF_DAY);
113        }
114        
115        public int getMinute() {
116            return calendar.get(Calendar.MINUTE);
117        }
118    
119    
120        public int getSecond() {
121            return calendar.get(Calendar.SECOND);
122        }
123    
124      
125        public int getEra() {
126            return calendar.get(Calendar.ERA);
127        }
128    
129        public String getUSTimeZone() {
130            String[] zones = new String[] {"Hawaii", "Alaskan", "Pacific",
131                                           "Mountain", "Central", "Eastern"};
132            
133            return zones[10 + getZoneOffset()];
134        }
135    
136        public int getZoneOffset() {
137            return calendar.get(Calendar.ZONE_OFFSET)/(60*60*1000);
138        }
139    
140    
141        public int getDSTOffset() {
142            return calendar.get(Calendar.DST_OFFSET)/(60*60*1000);
143        }
144    
145        
146        public int getAMPM() {
147            return calendar.get(Calendar.AM_PM);
148        }
149    }
150    
151    
152    
153    
154