directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1758248 - in /directory/shared/branches/shared-value/util/src: main/java/org/apache/directory/api/util/GeneralizedTime.java test/java/org/apache/directory/api/util/DateUtilTest.java
Date Mon, 29 Aug 2016 15:33:17 GMT
Author: elecharny
Date: Mon Aug 29 15:33:17 2016
New Revision: 1758248

URL: http://svn.apache.org/viewvc?rev=1758248&view=rev
Log:
Fix for DIRAPI-284

Added:
    directory/shared/branches/shared-value/util/src/test/java/org/apache/directory/api/util/DateUtilTest.java
Modified:
    directory/shared/branches/shared-value/util/src/main/java/org/apache/directory/api/util/GeneralizedTime.java

Modified: directory/shared/branches/shared-value/util/src/main/java/org/apache/directory/api/util/GeneralizedTime.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/util/src/main/java/org/apache/directory/api/util/GeneralizedTime.java?rev=1758248&r1=1758247&r2=1758248&view=diff
==============================================================================
--- directory/shared/branches/shared-value/util/src/main/java/org/apache/directory/api/util/GeneralizedTime.java
(original)
+++ directory/shared/branches/shared-value/util/src/main/java/org/apache/directory/api/util/GeneralizedTime.java
Mon Aug 29 15:33:17 2016
@@ -111,6 +111,9 @@ import org.apache.directory.api.i18n.I18
  */
 public class GeneralizedTime implements Comparable<GeneralizedTime>
 {
+    /** A Date far in the future, when Micro$oft would have vanished for a long time... */
+    private static final Date INFINITE = new Date( 0x7FFFFFFFFFFFFFFFL );
+
     /**
      * The format of the generalized time.
      */
@@ -1066,6 +1069,22 @@ public class GeneralizedTime implements
      */
     public static Date getDate( String zuluTime ) throws ParseException
     {
-        return new GeneralizedTime( zuluTime ).calendar.getTime();
+        try
+        {
+            return new GeneralizedTime( zuluTime ).calendar.getTime();
+        }
+        catch ( ParseException pe )
+        {
+            // Maybe one of the multiple Micro$oft ineptness to cope with Standards ?
+            if ( "9223372036854775807".equals( zuluTime) )
+            {
+                // This 0x7FFFFFFFFFFFFFFF, never ending date
+                return INFINITE;
+            }
+            else
+            {
+                throw pe;
+            }
+        }
     }
 }

Added: directory/shared/branches/shared-value/util/src/test/java/org/apache/directory/api/util/DateUtilTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-value/util/src/test/java/org/apache/directory/api/util/DateUtilTest.java?rev=1758248&view=auto
==============================================================================
--- directory/shared/branches/shared-value/util/src/test/java/org/apache/directory/api/util/DateUtilTest.java
(added)
+++ directory/shared/branches/shared-value/util/src/test/java/org/apache/directory/api/util/DateUtilTest.java
Mon Aug 29 15:33:17 2016
@@ -0,0 +1,47 @@
+/*
+ *   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.directory.api.util;
+
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+
+/**
+ * A class to test DateUtils
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DateUtilTest
+{
+
+    @Test
+    public void testInfinite()
+    {
+        try
+        {
+            DateUtils.getDate( "9223372036854775807" );
+        }
+        catch ( RuntimeException pe )
+        {
+            fail();
+        }
+    }
+}



Mime
View raw message