Author: nick
Date: Thu Oct 24 15:27:28 2013
New Revision: 1535414

URL: http://svn.apache.org/r1535414
Log:
Pull the Date -> ISO8601 logic out of Metadata to a common utils class, so that 
other bits of Tika (eg TIKA-1188) can use it

Added:
    tika/trunk/tika-core/src/main/java/org/apache/tika/utils/DateUtils.java
Modified:
    tika/trunk/tika-core/src/main/java/org/apache/tika/metadata/Metadata.java

Modified: 
tika/trunk/tika-core/src/main/java/org/apache/tika/metadata/Metadata.java
URL: 
http://svn.apache.org/viewvc/tika/trunk/tika-core/src/main/java/org/apache/tika/metadata/Metadata.java?rev=1535414&r1=1535413&r2=1535414&view=diff
==============================================================================
--- tika/trunk/tika-core/src/main/java/org/apache/tika/metadata/Metadata.java 
(original)
+++ tika/trunk/tika-core/src/main/java/org/apache/tika/metadata/Metadata.java 
Thu Oct 24 15:27:28 2013
@@ -16,15 +16,17 @@
  */
 package org.apache.tika.metadata;
 
+import static org.apache.tika.utils.DateUtils.MIDDAY;
+import static org.apache.tika.utils.DateUtils.UTC;
+import static org.apache.tika.utils.DateUtils.formatDate;
+
 import java.io.Serializable;
 import java.text.DateFormat;
 import java.text.DateFormatSymbols;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Calendar;
 import java.util.Date;
 import java.util.Enumeration;
-import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
@@ -87,24 +89,6 @@ public class Metadata implements Creativ
     public static final String TYPE = "type";
 
     /**
-     * The UTC time zone. Not sure if {@link TimeZone#getTimeZone(String)}
-     * understands "UTC" in all environments, but it'll fall back to GMT
-     * in such cases, which is in practice equivalent to UTC.
-     */
-    private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
-
-    /**
-     * Custom time zone used to interpret date values without a time
-     * component in a way that most likely falls within the same day
-     * regardless of in which time zone it is later interpreted. For
-     * example, the "2012-02-17" date would map to "2012-02-17T12:00:00Z"
-     * (instead of the default "2012-02-17T00:00:00Z"), which would still
-     * map to "2012-02-17" if interpreted in say Pacific time (while the
-     * default mapping would result in "2012-02-16" for UTC-8).
-     */
-    private static final TimeZone MIDDAY = TimeZone.getTimeZone("GMT-12:00");
-
-    /**
      * Some parsers will have the date as a ISO-8601 string
      *  already, and will set that into the Metadata object.
      * So we can return Date objects for these, this is the
@@ -163,27 +147,6 @@ public class Metadata implements Creativ
     }
 
     /**
-     * Returns a ISO 8601 representation of the given date. This method 
-     * is thread safe and non-blocking.
-     *
-     * @see <a 
href="https://issues.apache.org/jira/browse/TIKA-495";>TIKA-495</a>
-     * @param date given date
-     * @return ISO 8601 date string
-     */
-    private static String formatDate(Date date) {
-        Calendar calendar = GregorianCalendar.getInstance(UTC, Locale.US);
-        calendar.setTime(date);
-        return String.format(
-                "%04d-%02d-%02dT%02d:%02d:%02dZ",
-                calendar.get(Calendar.YEAR),
-                calendar.get(Calendar.MONTH) + 1,
-                calendar.get(Calendar.DAY_OF_MONTH),
-                calendar.get(Calendar.HOUR_OF_DAY),
-                calendar.get(Calendar.MINUTE),
-                calendar.get(Calendar.SECOND));
-    }
-
-    /**
      * Constructs a new, empty metadata.
      */
     public Metadata() {

Added: tika/trunk/tika-core/src/main/java/org/apache/tika/utils/DateUtils.java
URL: 
http://svn.apache.org/viewvc/tika/trunk/tika-core/src/main/java/org/apache/tika/utils/DateUtils.java?rev=1535414&view=auto
==============================================================================
--- tika/trunk/tika-core/src/main/java/org/apache/tika/utils/DateUtils.java 
(added)
+++ tika/trunk/tika-core/src/main/java/org/apache/tika/utils/DateUtils.java Thu 
Oct 24 15:27:28 2013
@@ -0,0 +1,67 @@
+/**
+ * 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.
+ */
+package org.apache.tika.utils;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * Date related utility methods and constants
+ */
+public class DateUtils {
+    /**
+     * The UTC time zone. Not sure if {@link TimeZone#getTimeZone(String)}
+     * understands "UTC" in all environments, but it'll fall back to GMT
+     * in such cases, which is in practice equivalent to UTC.
+     */
+    public static final TimeZone UTC = TimeZone.getTimeZone("UTC");
+
+    /**
+     * Custom time zone used to interpret date values without a time
+     * component in a way that most likely falls within the same day
+     * regardless of in which time zone it is later interpreted. For
+     * example, the "2012-02-17" date would map to "2012-02-17T12:00:00Z"
+     * (instead of the default "2012-02-17T00:00:00Z"), which would still
+     * map to "2012-02-17" if interpreted in say Pacific time (while the
+     * default mapping would result in "2012-02-16" for UTC-8).
+     */
+    public static final TimeZone MIDDAY = TimeZone.getTimeZone("GMT-12:00");
+
+    /**
+     * Returns a ISO 8601 representation of the given date. This method 
+     * is thread safe and non-blocking.
+     *
+     * @see <a 
href="https://issues.apache.org/jira/browse/TIKA-495";>TIKA-495</a>
+     * @param date given date
+     * @return ISO 8601 date string
+     */
+    public static String formatDate(Date date) {
+        Calendar calendar = GregorianCalendar.getInstance(UTC, Locale.US);
+        calendar.setTime(date);
+        return String.format(
+                "%04d-%02d-%02dT%02d:%02d:%02dZ",
+                calendar.get(Calendar.YEAR),
+                calendar.get(Calendar.MONTH) + 1,
+                calendar.get(Calendar.DAY_OF_MONTH),
+                calendar.get(Calendar.HOUR_OF_DAY),
+                calendar.get(Calendar.MINUTE),
+                calendar.get(Calendar.SECOND));
+    }
+}


Reply via email to