You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2021/07/17 19:12:55 UTC

svn commit: r1891629 - /pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java

Author: tilman
Date: Sat Jul 17 19:12:55 2021
New Revision: 1891629

URL: http://svn.apache.org/viewvc?rev=1891629&view=rev
Log:
PDFBOX-4892: optimize, as suggested by valerybokov

Modified:
    pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java

Modified: pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java?rev=1891629&r1=1891628&r2=1891629&view=diff
==============================================================================
--- pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java (original)
+++ pdfbox/branches/2.0/xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java Sat Jul 17 19:12:55 2021
@@ -85,6 +85,8 @@ public final class DateConverter
         Calendar retval = null;
         if ((date != null) && (date.trim().length() > 0))
         {
+            date = date.trim();
+
             // these are the default values
             int month = 1;
             int day = 1;
@@ -103,7 +105,7 @@ public final class DateConverter
                 }
                 else if (date.startsWith("D:"))
                 {
-                    date = date.substring(2, date.length());
+                    date = date.substring(2);
                 }
 
                 date = date.replaceAll("[-:T]", "");
@@ -193,11 +195,9 @@ public final class DateConverter
             catch (NumberFormatException e)
             {
 
-                // remove the arbitrary : in the timezone. SimpleDateFormat
-                // can't handle it
-                if (date.substring(date.length() - 3, date.length() - 2).equals(":")
-                        && (date.substring(date.length() - 6, date.length() - 5).equals("+") || date.substring(
-                                date.length() - 6, date.length() - 5).equals("-")))
+                // remove the arbitrary : in the timezone. SimpleDateFormat can't handle it
+                if (date.charAt(date.length() - 3) == ':' && 
+                    (date.charAt(date.length() - 6) == '+' || date.charAt(date.length() - 6) == '-'))
                 {
                     // that's a timezone string, remove the :
                     date = date.substring(0, date.length() - 3) + date.substring(date.length() - 2);
@@ -349,9 +349,10 @@ public final class DateConverter
         {
             for (int i = 1; i <= timeZoneMatcher.groupCount(); i++)
             {
-                if (timeZoneMatcher.group(i) != null)
+                String group = timeZoneMatcher.group(i);
+                if (group != null)
                 {
-                    timeZoneString = timeZoneMatcher.group(i);
+                    timeZoneString = group;
                 }
             }
         }