/Users/lyon/j4p/src/net/server/cal/JspCalendar.java
|
1 /*
2 * Copyright (c) 1999 Sun Microsystems, Inc. All Rights Reserved.
3 *
4 * This software is the confidential and proprietary information of Sun
5 * Microsystems, Inc. ("Confidential Information"). You shall not
6 * disclose such Confidential Information and shall use it only in
7 * accordance with the terms of the license agreement you entered into
8 * with Sun.
9 *
10 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
11 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
13 * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
14 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
15 * THIS SOFTWARE OR ITS DERIVATIVES.
16 *
17 */
18
19 package net.server.cal;
20
21 import java.util.Calendar;
22 import java.util.Date;
23
24 public class JspCalendar {
25 private Calendar calendar = null;
26
27 public JspCalendar() {
28 calendar = Calendar.getInstance();
29 Date trialTime = new Date();
30 calendar.setTime(trialTime);
31 }
32
33
34 public int getYear() {
35 return calendar.get(Calendar.YEAR);
36 }
37
38 public String getMonth() {
39 int m = getMonthInt();
40 String[] months = new String[]{"January", "February", "March",
41 "April", "May", "June",
42 "July", "August", "September",
43 "October", "November", "December"};
44 if (m > 12)
45 return "Unknown to Man";
46
47 return months[m - 1];
48
49 }
50
51 public String getDay() {
52 int x = getDayOfWeek();
53 String[] days = new String[]{"Sunday", "Monday", "Tuesday", "Wednesday",
54 "Thursday", "Friday", "Saturday"};
55
56 if (x > 7)
57 return "Unknown to Man";
58
59 return days[x - 1];
60
61 }
62
63 public int getMonthInt() {
64 return 1 + calendar.get(Calendar.MONTH);
65 }
66
67 public String getDate() {
68 return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
69 }
70
71 public String getCurrentDate() {
72 Date dt = new Date();
73 calendar.setTime(dt);
74 return getMonthInt() + "/" + getDayOfMonth() + "/" + getYear();
75
76 }
77
78 public String getNextDate() {
79 calendar.set(Calendar.DAY_OF_MONTH, getDayOfMonth() + 1);
80 return getDate();
81 }
82
83 public String getPrevDate() {
84 calendar.set(Calendar.DAY_OF_MONTH, getDayOfMonth() - 1);
85 return getDate();
86 }
87
88 public String getTime() {
89 return getHour() + ":" + getMinute() + ":" + getSecond();
90 }
91
92 public int getDayOfMonth() {
93 return calendar.get(Calendar.DAY_OF_MONTH);
94 }
95
96 public int getDayOfYear() {
97 return calendar.get(Calendar.DAY_OF_YEAR);
98 }
99
100 public int getWeekOfYear() {
101 return calendar.get(Calendar.WEEK_OF_YEAR);
102 }
103
104 public int getWeekOfMonth() {
105 return calendar.get(Calendar.WEEK_OF_MONTH);
106 }
107
108 public int getDayOfWeek() {
109 return calendar.get(Calendar.DAY_OF_WEEK);
110 }
111
112 public int getHour() {
113 return calendar.get(Calendar.HOUR_OF_DAY);
114 }
115
116 public int getMinute() {
117 return calendar.get(Calendar.MINUTE);
118 }
119
120
121 public int getSecond() {
122 return calendar.get(Calendar.SECOND);
123 }
124
125
126 public int getEra() {
127 return calendar.get(Calendar.ERA);
128 }
129
130 public String getUSTimeZone() {
131 String[] zones = new String[]{"Hawaii", "Alaskan", "Pacific",
132 "Mountain", "Central", "Eastern"};
133
134 int index = 10 + getZoneOffset();
135
136 if (index <= 5) {
137 return zones[10 + getZoneOffset()];
138 } else
139 return "Only US Time Zones are supported";
140 }
141
142 public int getZoneOffset() {
143 return calendar.get(Calendar.ZONE_OFFSET) / (60 * 60 * 1000);
144 }
145
146
147 public int getDSTOffset() {
148 return calendar.get(Calendar.DST_OFFSET) / (60 * 60 * 1000);
149 }
150
151
152 public int getAMPM() {
153 return calendar.get(Calendar.AM_PM);
154 }
155 }
156
157
158
159
160
161