source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/testcases/org/apache/tools/ant/util/DateUtilsTest.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 3.1 KB
Line 
1/*
2 * Copyright 2002,2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17package org.apache.tools.ant.util;
18
19import java.util.Date;
20import java.util.Calendar;
21import java.util.TimeZone;
22
23import junit.framework.TestCase;
24
25/**
26 * TestCase for DateUtils.
27 *
28 */
29public class DateUtilsTest extends TestCase {
30 public DateUtilsTest(String s) {
31 super(s);
32 }
33
34 public void testElapsedTime(){
35 String text = DateUtils.formatElapsedTime(50*1000);
36 assertEquals("50 seconds", text);
37 text = DateUtils.formatElapsedTime(65*1000);
38 assertEquals("1 minute 5 seconds", text);
39 text = DateUtils.formatElapsedTime(120*1000);
40 assertEquals("2 minutes 0 seconds", text);
41 text = DateUtils.formatElapsedTime(121*1000);
42 assertEquals("2 minutes 1 second", text);
43 }
44
45 public void testDateTimeISO(){
46 TimeZone timeZone = TimeZone.getTimeZone("GMT+1");
47 Calendar cal = Calendar.getInstance(timeZone);
48 cal.set(2002,1,23,10,11,12);
49 String text = DateUtils.format(cal.getTime(),
50 DateUtils.ISO8601_DATETIME_PATTERN);
51 assertEquals("2002-02-23T09:11:12", text);
52 }
53
54 public void testDateISO(){
55 TimeZone timeZone = TimeZone.getTimeZone("GMT");
56 Calendar cal = Calendar.getInstance(timeZone);
57 cal.set(2002,1,23);
58 String text = DateUtils.format(cal.getTime(),
59 DateUtils.ISO8601_DATE_PATTERN);
60 assertEquals("2002-02-23", text);
61 }
62
63 public void testTimeISODate(){
64 // make sure that elapsed time in set via date works
65 TimeZone timeZone = TimeZone.getTimeZone("GMT+1");
66 Calendar cal = Calendar.getInstance(timeZone);
67 cal.set(2002,1,23, 21, 11, 12);
68 String text = DateUtils.format(cal.getTime(),
69 DateUtils.ISO8601_TIME_PATTERN);
70 assertEquals("20:11:12", text);
71 }
72
73 public void testTimeISO(){
74 // make sure that elapsed time in ms works
75 long ms = (20*3600 + 11*60 + 12)*1000;
76 String text = DateUtils.format(ms,
77 DateUtils.ISO8601_TIME_PATTERN);
78 assertEquals("20:11:12", text);
79 }
80
81 public void testPhaseOfMoon() {
82 TimeZone timeZone = TimeZone.getTimeZone("GMT");
83 Calendar cal = Calendar.getInstance(timeZone);
84 // should be full moon
85 cal.set(2002, 2, 27);
86 assertEquals(4, DateUtils.getPhaseOfMoon(cal));
87 // should be new moon
88 cal.set(2002, 2, 12);
89 assertEquals(0, DateUtils.getPhaseOfMoon(cal));
90 }
91}
Note: See TracBrowser for help on using the repository browser.