1 17 package org.apache.tools.ant.util; 18 19 import java.util.Date ; 20 import java.util.Calendar ; 21 import java.util.TimeZone ; 22 23 import junit.framework.TestCase; 24 25 29 public 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 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 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 cal.set(2002, 2, 27); 86 assertEquals(4, DateUtils.getPhaseOfMoon(cal)); 87 cal.set(2002, 2, 12); 89 assertEquals(0, DateUtils.getPhaseOfMoon(cal)); 90 } 91 } 92 | Popular Tags |