From: remillet Date: Mon, 9 Mar 2015 23:40:38 +0000 (-0700) Subject: CSPACE-6375: Dealing with Nuxeo 6 timestamp formatting issues. X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=e7d84db6af0c386baa466cfb3e85992ee38c1dcb;p=tmp%2Fjakarta-migration.git CSPACE-6375: Dealing with Nuxeo 6 timestamp formatting issues. --- diff --git a/services/common-api/src/main/java/org/collectionspace/services/common/api/DateUtils.java b/services/common-api/src/main/java/org/collectionspace/services/common/api/DateUtils.java index d76899ae3..f13ae8aca 100644 --- a/services/common-api/src/main/java/org/collectionspace/services/common/api/DateUtils.java +++ b/services/common-api/src/main/java/org/collectionspace/services/common/api/DateUtils.java @@ -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 isoLanguageCodes = new ArrayList(Arrays.asList(Locale.getISOLanguages())); diff --git a/services/common-api/src/main/java/org/collectionspace/services/common/api/GregorianCalendarDateTimeUtils.java b/services/common-api/src/main/java/org/collectionspace/services/common/api/GregorianCalendarDateTimeUtils.java index 1f0af8970..aa7979ed3 100644 --- a/services/common-api/src/main/java/org/collectionspace/services/common/api/GregorianCalendarDateTimeUtils.java +++ b/services/common-api/src/main/java/org/collectionspace/services/common/api/GregorianCalendarDateTimeUtils.java @@ -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.