You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by je...@apache.org on 2008/02/07 15:25:04 UTC
svn commit: r619423 - in /xmlgraphics/commons/trunk:
src/java/org/apache/xmlgraphics/xmp/XMPSchemaAdapter.java status.xml
test/java/org/apache/xmlgraphics/xmp/DateFormattingTest.java
Author: jeremias
Date: Thu Feb 7 06:25:00 2008
New Revision: 619423
URL: http://svn.apache.org/viewvc?rev=619423&view=rev
Log:
Bugfix for ISO 8601 date formatting with negative time zones in the XMP package.
Added:
xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/DateFormattingTest.java (with props)
Modified:
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPSchemaAdapter.java
xmlgraphics/commons/trunk/status.xml
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPSchemaAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPSchemaAdapter.java?rev=619423&r1=619422&r2=619423&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPSchemaAdapter.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/xmp/XMPSchemaAdapter.java Thu Feb 7 06:25:00 2008
@@ -119,8 +119,18 @@
* @return the formatted date
*/
public static String formatISO8601Date(Date dt) {
+ return formatISO8601Date(dt, TimeZone.getDefault());
+ }
+
+ /**
+ * Formats a Date using ISO 8601 format in the given time zone.
+ * @param dt the date
+ * @param tz the time zone
+ * @return the formatted date
+ */
+ public static String formatISO8601Date(Date dt, TimeZone tz) {
//ISO 8601 cannot be expressed directly using SimpleDateFormat
- Calendar cal = Calendar.getInstance();
+ Calendar cal = Calendar.getInstance(tz);
cal.setTime(dt);
int offset = cal.get(Calendar.ZONE_OFFSET);
offset += cal.get(Calendar.DST_OFFSET);
@@ -144,7 +154,7 @@
if (zoneOffsetHours < 10) {
sb.append('0');
}
- sb.append(zoneOffsetHours);
+ sb.append(Math.abs(zoneOffsetHours));
sb.append(':');
if (zoneOffsetMinutes < 10) {
sb.append('0');
Modified: xmlgraphics/commons/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/status.xml?rev=619423&r1=619422&r2=619423&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/status.xml (original)
+++ xmlgraphics/commons/trunk/status.xml Thu Feb 7 06:25:00 2008
@@ -25,6 +25,9 @@
</todo>
<changes>
<release version="Trunk" date="n/a">
+ <action context="Code" dev="JM" type="fix">
+ Bugfix for ISO 8601 date formatting with negative time zones in the XMP package.
+ </action>
<action context="Code" dev="JM" type="add">
The package org.apache.xmlgraphics.image.loader was added. It contains a general
image loading framework for various image formats (bitmap & vector).
Added: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/DateFormattingTest.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/DateFormattingTest.java?rev=619423&view=auto
==============================================================================
--- xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/DateFormattingTest.java (added)
+++ xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/DateFormattingTest.java Thu Feb 7 06:25:00 2008
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+/* $Id$ */
+
+package org.apache.xmlgraphics.xmp;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests date formatting for XMP.
+ */
+public class DateFormattingTest extends TestCase {
+
+ /**
+ * Checks date formatting for XMP.
+ * @throws Exception if an error occurs
+ */
+ public void testDateFormatting() throws Exception {
+ Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+ cal.set(2008, Calendar.FEBRUARY, 07, 15, 11, 07);
+ cal.set(Calendar.MILLISECOND, 0);
+ Date dt = cal.getTime();
+
+ String s = XMPSchemaAdapter.formatISO8601Date(dt, TimeZone.getTimeZone("GMT"));
+ assertEquals("2008-02-07T15:11:07Z", s);
+ assertEquals(dt, XMPSchemaAdapter.parseISO8601Date(s));
+
+ s = XMPSchemaAdapter.formatISO8601Date(dt, TimeZone.getTimeZone("GMT+02:00"));
+ assertEquals("2008-02-07T17:11:07+02:00", s);
+ assertEquals(dt, XMPSchemaAdapter.parseISO8601Date(s));
+
+ s = XMPSchemaAdapter.formatISO8601Date(dt, TimeZone.getTimeZone("GMT-08:00"));
+ assertEquals("2008-02-07T07:11:07-08:00", s);
+ assertEquals(dt, XMPSchemaAdapter.parseISO8601Date(s));
+ }
+
+}
Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/DateFormattingTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: xmlgraphics/commons/trunk/test/java/org/apache/xmlgraphics/xmp/DateFormattingTest.java
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
Apache XML Graphics Project URL: http://xmlgraphics.apache.org/
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org