aboutsummaryrefslogtreecommitdiff
path: root/common/src/test/java/test/at/gv/egovernment/moa/util/DateTimeUtilsTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'common/src/test/java/test/at/gv/egovernment/moa/util/DateTimeUtilsTest.java')
-rw-r--r--common/src/test/java/test/at/gv/egovernment/moa/util/DateTimeUtilsTest.java119
1 files changed, 119 insertions, 0 deletions
diff --git a/common/src/test/java/test/at/gv/egovernment/moa/util/DateTimeUtilsTest.java b/common/src/test/java/test/at/gv/egovernment/moa/util/DateTimeUtilsTest.java
new file mode 100644
index 000000000..0b0f3fcf8
--- /dev/null
+++ b/common/src/test/java/test/at/gv/egovernment/moa/util/DateTimeUtilsTest.java
@@ -0,0 +1,119 @@
+/*
+* Copyright 2003 Federal Chancellery Austria
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+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 = SimpleDateFormat.getDateTimeInstance();
+ 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);
+ assertEquals(dateTimeShould, dateTimeBuilt);
+ }
+
+}