• R/O
  • SSH
  • HTTPS

manjyucalendar: Commit


Commit MetaInfo

Revision7 (tree)
Time2012-12-01 08:12:36
Authoriga

Log Message

add methods.

Change Summary

Incremental Difference

--- manjyu-calendar/trunk/test/src/org/manjyu/calendar/ManjyuCalendarUtilTest.java (revision 6)
+++ manjyu-calendar/trunk/test/src/org/manjyu/calendar/ManjyuCalendarUtilTest.java (revision 7)
@@ -133,6 +133,48 @@
133133 }
134134
135135 @Test
136+ public void testSetHour() {
137+ final Calendar cal = ManjyuCalendarUtil.getCalendar();
138+ ManjyuCalendarUtil.setHour(cal, 23);
139+ assertEquals("check", 23, cal.get(Calendar.HOUR_OF_DAY));
140+ }
141+
142+ @Test
143+ public void testGetHour() {
144+ final Calendar cal = ManjyuCalendarUtil.getCalendar();
145+ ManjyuCalendarUtil.setHour(cal, 22);
146+ assertEquals("check", 22, ManjyuCalendarUtil.getHour(cal));
147+ }
148+
149+ @Test
150+ public void testSetMinute() {
151+ final Calendar cal = ManjyuCalendarUtil.getCalendar();
152+ ManjyuCalendarUtil.setMinute(cal, 59);
153+ assertEquals("check", 59, cal.get(Calendar.MINUTE));
154+ }
155+
156+ @Test
157+ public void testGetMinute() {
158+ final Calendar cal = ManjyuCalendarUtil.getCalendar();
159+ ManjyuCalendarUtil.setMinute(cal, 59);
160+ assertEquals("check", 59, ManjyuCalendarUtil.getMinute(cal));
161+ }
162+
163+ @Test
164+ public void testSetSecond() {
165+ final Calendar cal = ManjyuCalendarUtil.getCalendar();
166+ ManjyuCalendarUtil.setSecond(cal, 59);
167+ assertEquals("check", 59, cal.get(Calendar.SECOND));
168+ }
169+
170+ @Test
171+ public void testGetSecond() {
172+ final Calendar cal = ManjyuCalendarUtil.getCalendar();
173+ ManjyuCalendarUtil.setSecond(cal, 59);
174+ assertEquals("check", 59, ManjyuCalendarUtil.getSecond(cal));
175+ }
176+
177+ @Test
136178 public void testValidateYmd() {
137179 assertEquals("check", true, ManjyuCalendarUtil.validateYmd(2012, 1, 1));
138180 assertEquals("check", true, ManjyuCalendarUtil.validateYmd(2012, 1, 31));
--- manjyu-calendar/trunk/src/org/manjyu/calendar/ManjyuCalendarUtil.java (revision 6)
+++ manjyu-calendar/trunk/src/org/manjyu/calendar/ManjyuCalendarUtil.java (revision 7)
@@ -69,9 +69,9 @@
6969 /**
7070 * Create new calendar with specified condition.
7171 *
72- * @param Year value. 1 origin. ie: 2012.
73- * @param Month value. 1 origin. 1 to 12.
74- * @param Day value. 1 origin. 1 to 31.
72+ * @param year Year value. 1 origin. ie: 2012.
73+ * @param month Month value. 1 origin. 1 to 12.
74+ * @param day Day value. 1 origin. 1 to 31.
7575 * @return Specified day's calendar object. Hour, minute, second is 0.
7676 */
7777 public static Calendar getCalendar(final int year, final int month, final int day) {
@@ -103,9 +103,10 @@
103103 * @param cal Target calendar object to clear hour, minute, second part.
104104 */
105105 public static void clearHhmmss(final Calendar cal) {
106- cal.set(Calendar.HOUR_OF_DAY, 0);
107- cal.set(Calendar.MINUTE, 0);
108- cal.set(Calendar.SECOND, 0);
106+ setHour(cal, 0);
107+ setMinute(cal, 0);
108+ setSecond(cal, 0);
109+
109110 cal.set(Calendar.MILLISECOND, 0);
110111 }
111112
@@ -113,7 +114,7 @@
113114 * Set year value to Celendar.
114115 *
115116 * @param cal Target calendar object.
116- * @param Year value. 1 origin. ie: 2012.
117+ * @param year Year value. 1 origin. ie: 2012.
117118 */
118119 public static void setYear(final Calendar cal, final int year) {
119120 cal.set(Calendar.YEAR, year);
@@ -133,7 +134,7 @@
133134 * Set month value to Celendar.
134135 *
135136 * @param cal Target calendar object.
136- * @param Month value. 1 origin. 1 to 12.
137+ * @param month Month value. 1 origin. 1 to 12.
137138 */
138139 public static void setMonth(final Calendar cal, final int month) {
139140 // java.util.Calendar.MONTH is 0 origin.
@@ -155,7 +156,7 @@
155156 * Set day of month value to Celendar.
156157 *
157158 * @param cal Target calendar object.
158- * @param Day value. 1 origin. 1 to 31.
159+ * @param day Day value. 1 origin. 1 to 31.
159160 */
160161 public static void setDay(final Calendar cal, final int day) {
161162 cal.set(Calendar.DAY_OF_MONTH, day);
@@ -172,6 +173,66 @@
172173 }
173174
174175 /**
176+ * Set hour of day value to Celendar.
177+ *
178+ * @param cal Target calendar object.
179+ * @param hour Hour value. 0 origin. 0 to 23.
180+ */
181+ public static void setHour(final Calendar cal, final int hour) {
182+ cal.set(Calendar.HOUR_OF_DAY, hour);
183+ }
184+
185+ /**
186+ * Get day of month value from Celendar.
187+ *
188+ * @param cal Target calendar object.
189+ * @return Hour value. 0 origin. 0 to 23.
190+ */
191+ public static int getHour(final Calendar cal) {
192+ return cal.get(Calendar.HOUR_OF_DAY);
193+ }
194+
195+ /**
196+ * Set mninute value to Celendar.
197+ *
198+ * @param cal Target calendar object.
199+ * @param minute Minute value. 0 origin. 0 to 59.
200+ */
201+ public static void setMinute(final Calendar cal, final int minute) {
202+ cal.set(Calendar.MINUTE, minute);
203+ }
204+
205+ /**
206+ * Get day of month value from Celendar.
207+ *
208+ * @param cal Target calendar object.
209+ * @return Minute value. 0 origin. 0 to 59.
210+ */
211+ public static int getMinute(final Calendar cal) {
212+ return cal.get(Calendar.MINUTE);
213+ }
214+
215+ /**
216+ * Set mninute value to Celendar.
217+ *
218+ * @param cal Target calendar object.
219+ * @param second Second value. 0 origin. 0 to 59.
220+ */
221+ public static void setSecond(final Calendar cal, final int second) {
222+ cal.set(Calendar.SECOND, second);
223+ }
224+
225+ /**
226+ * Get day of month value from Celendar.
227+ *
228+ * @param cal Target calendar object.
229+ * @return Second value. 0 origin. 0 to 59.
230+ */
231+ public static int getSecond(final Calendar cal) {
232+ return cal.get(Calendar.SECOND);
233+ }
234+
235+ /**
175236 * Validate specified year, month, date combination.
176237 *
177238 * Validate is do with Calendar.setLenient(false);
Show on old repository browser