/* * Copyright 2003 Federal Chancellery Austria * MOA-ID has been developed in a cooperation between BRZ, the Federal * Chancellery Austria - ICT staff unit, and Graz University of Technology. * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by * the European Commission - subsequent versions of the EUPL (the "Licence"); * You may not use this work except in compliance with the Licence. * You may obtain a copy of the Licence at: * http://www.osor.eu/eupl/ * * Unless required by applicable law or agreed to in writing, software * distributed under the Licence is distributed on an "AS IS" basis, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the Licence for the specific language governing permissions and * limitations under the Licence. * * This product combines work with different licenses. See the "NOTICE" text * file for details on the various modules and licenses. * The "NOTICE" text file is part of the distribution. Any derivative works * that you distribute must include a readable copy of the "NOTICE" text file. */ package test.at.gv.egovernment.moa.util; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; import junit.framework.TestCase; import at.gv.egovernment.moa.util.DateTimeUtils; /** * @author Patrick Peck * @version $Id$ */ public class DateTimeUtilsTest extends TestCase { /** * Constructor for DateTimeUtilsTest. * @param arg0 */ public DateTimeUtilsTest(String arg0) { super(arg0); } public void testParseDateTimeValid() throws Exception { Date date; DateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); String dateStr; format.setTimeZone(TimeZone.getTimeZone("GMT")); date = DateTimeUtils.parseDateTime("+1971-12-12T06:30:15"); date.setTime(date.getTime() + TimeZone.getDefault().getRawOffset()); dateStr = format.format(date); assertEquals("12.12.1971 06:30:15", dateStr); date = DateTimeUtils.parseDateTime("2000-01-01T23:59:59.012Z"); dateStr = format.format(date); assertEquals("01.01.2000 23:59:59", dateStr); date = DateTimeUtils.parseDateTime("2003-05-20T12:17:30-05:00"); dateStr = format.format(date); assertEquals("20.05.2003 17:17:30", dateStr); date = DateTimeUtils.parseDateTime("2002-02-02T02:02:02.33+04:30"); dateStr = format.format(date); assertEquals("01.02.2002 21:32:02", dateStr); } public void testParseDateTimeInvalid() { try { DateTimeUtils.parseDateTime("+1971-12-12T6:30:15"); fail(); } catch (ParseException e) { } try { DateTimeUtils.parseDateTime("2000-01-0123:59:59.999999Z"); fail(); } catch (ParseException e) { } try { DateTimeUtils.parseDateTime("2003-05-20T12:17:3005:00"); fail(); } catch (ParseException e) { } try { DateTimeUtils.parseDateTime(" 2002-02-02T02:02:02.33+04:00"); fail(); } catch (ParseException e) { } } public void testBuildDateTimeGMTMinus3() { String should = "2002-01-01T01:01:01-03:00"; doTestBuildDateTime(2002, 1, 1, 1, 1, 1, "GMT-03:00", should); } public void testBuildDateTimeMEZSommerzeit() { String should = "2002-07-31T23:59:59+02:00"; doTestBuildDateTime(2002, 7, 31, 23, 59, 59, "GMT+01:00", should); } public void testBuildDateTimeGMT() { String should = "2002-01-01T01:01:01"; doTestBuildDateTime(2002, 1, 1, 1, 1, 1, "GMT+00:00", should); } private void doTestBuildDateTime( int year, int month, int day, int hour, int min, int sec, String timeZone, String dateTimeShould) { // Calendar cal = new GregorianCalendar(TimeZone.getTimeZone(timeZone)); // cal.set(year,month, day, hour, min, sec); // cal.set(Calendar.MILLISECOND, 0); // String dateTimeBuilt = DateTimeUtils.buildDateTime(cal, false); // assertEquals(dateTimeShould, dateTimeBuilt); } }