]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6375: Dealing with Nuxeo 6 timestamp formatting issues.
authorremillet <remillet@yahoo.com>
Mon, 9 Mar 2015 23:40:38 +0000 (16:40 -0700)
committerremillet <remillet@yahoo.com>
Mon, 9 Mar 2015 23:40:38 +0000 (16:40 -0700)
services/common-api/src/main/java/org/collectionspace/services/common/api/DateUtils.java
services/common-api/src/main/java/org/collectionspace/services/common/api/GregorianCalendarDateTimeUtils.java

index d76899ae3ce721fb68becf184ee42c12d92e72d1..f13ae8acaa365dd07d6976ab588f2bb4e080e25b 100644 (file)
@@ -19,7 +19,7 @@ public class DateUtils {
 
     final static String ISO_8601_DATE_PATTERN = "yyyy-MM-dd";
     final static String UTC_TIMEZONE_IDENTIFIER = "UTC";
-    final static String ISO_8601_UTC_TIMESTAMP_PATTERN = "yyyy-MM-dd'T'HH:mm:ss'Z'";
+    final static String ISO_8601_UTC_TIMESTAMP_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SS'Z'";
     final static Locale NULL_LOCALE = null;
     public final static List<String> isoLanguageCodes = new ArrayList(Arrays.asList(Locale.getISOLanguages()));    
 
index 1f0af89702051c72e35cac038b3bfc3890bc0dce..aa7979ed358b397c20d70e27d1560e98744eeaf6 100644 (file)
@@ -20,6 +20,7 @@ package org.collectionspace.services.common.api;
 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.Locale;
@@ -50,6 +51,31 @@ public class GregorianCalendarDateTimeUtils {
          return formatAsISO8601Timestamp(currentDateAndTime(DateUtils.UTCTimeZone()));
      }
      
+     //
+     // This is code take from the Nuxeo 6 code base.  It is stripping off the thousandths place of the milliseconds value.  I'm
+     // not sure why they are doing this.
+     //
+     public static String formatW3CDateTime(Date date) {
+         if (date == null) {
+             return null;
+         }
+         Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
+         cal.setTime(date);
+         StringBuilder buf = new StringBuilder(32);
+         return buf.append(cal.get(Calendar.YEAR)).append('-').append(
+                 pad(cal.get(Calendar.MONTH) + 1)).append('-').append(
+                 pad(cal.get(Calendar.DATE))).append('T').append(
+                 pad(cal.get(Calendar.HOUR_OF_DAY))).append(':').append(
+                 pad(cal.get(Calendar.MINUTE))).append(':').append(
+                 pad(cal.get(Calendar.SECOND))).append('.').append(
+                 pad(cal.get(Calendar.MILLISECOND) / 10)).append('Z').toString();
+     }
+     
+     private final static String pad(int i) {
+         return i < 10 ? "0".concat(String.valueOf(i)) : String.valueOf(i);
+     }
+     
+     
     /**
      * Returns a String representing the current date and time instance.
      * in the UTC time zone, formatted as an ISO 8601 date.