You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by er...@apache.org on 2004/12/22 16:57:01 UTC

svn commit: r123114 - in incubator/directory: eve/trunk/core/src/java/org/apache/eve/jndi/ibs ldap/trunk/common/src/java/org/apache/ldap/common/util ldap/trunk/common/src/test/org/apache/ldap/common/util

Author: erodriguez
Date: Wed Dec 22 07:57:00 2004
New Revision: 123114

URL: http://svn.apache.org/viewcvs?view=rev&rev=123114
Log:
Replaced DateUtils g-differential with g-time-zone using JDK SimpleDateFormat.
Removed:
   incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/util/DateUtilsTest.java
Modified:
   incubator/directory/eve/trunk/core/src/java/org/apache/eve/jndi/ibs/OperationalAttributeService.java
   incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/DateUtils.java

Modified: incubator/directory/eve/trunk/core/src/java/org/apache/eve/jndi/ibs/OperationalAttributeService.java
Url: http://svn.apache.org/viewcvs/incubator/directory/eve/trunk/core/src/java/org/apache/eve/jndi/ibs/OperationalAttributeService.java?view=diff&rev=123114&p1=incubator/directory/eve/trunk/core/src/java/org/apache/eve/jndi/ibs/OperationalAttributeService.java&r1=123113&p2=incubator/directory/eve/trunk/core/src/java/org/apache/eve/jndi/ibs/OperationalAttributeService.java&r2=123114
==============================================================================
--- incubator/directory/eve/trunk/core/src/java/org/apache/eve/jndi/ibs/OperationalAttributeService.java	(original)
+++ incubator/directory/eve/trunk/core/src/java/org/apache/eve/jndi/ibs/OperationalAttributeService.java	Wed Dec 22 07:57:00 2004
@@ -24,7 +24,6 @@
 import javax.naming.directory.*;
 
 import org.apache.eve.RootNexus;
-import org.apache.eve.db.DbSearchResult;
 import org.apache.eve.db.SearchResultFilter;
 import org.apache.eve.jndi.Invocation;
 import org.apache.eve.jndi.BaseInterceptor;
@@ -162,7 +161,7 @@
             attributes.put( attribute );
 
             attribute = new BasicAttribute( "modifyTimestamp" );
-            attribute.add( DateUtils.getGeneralizedTime( System.currentTimeMillis() ) );
+            attribute.add( DateUtils.getGeneralizedTime() );
             attributes.put( attribute );
 
             nexus.modify( dn, DirContext.REPLACE_ATTRIBUTE, attributes );
@@ -185,7 +184,7 @@
             attributes.put( attribute );
 
             attribute = new BasicAttribute( "modifyTimestamp" );
-            attribute.add( DateUtils.getGeneralizedTime( System.currentTimeMillis() ) );
+            attribute.add( DateUtils.getGeneralizedTime() );
             attributes.put( attribute );
 
             nexus.modify( dn, DirContext.REPLACE_ATTRIBUTE, attributes );
@@ -206,7 +205,7 @@
             attributes.put( attribute );
 
             attribute = new BasicAttribute( "modifyTimestamp" );
-            attribute.add( DateUtils.getGeneralizedTime( System.currentTimeMillis() ) );
+            attribute.add( DateUtils.getGeneralizedTime() );
             attributes.put( attribute );
 
             Name newDn = dn.getSuffix( 1 ).add( newRdn );
@@ -228,7 +227,7 @@
             attributes.put( attribute );
 
             attribute = new BasicAttribute( "modifyTimestamp" );
-            attribute.add( DateUtils.getGeneralizedTime( System.currentTimeMillis() ) );
+            attribute.add( DateUtils.getGeneralizedTime() );
             attributes.put( attribute );
 
             nexus.modify( newParentName, DirContext.REPLACE_ATTRIBUTE, attributes );
@@ -250,7 +249,7 @@
             attributes.put( attribute );
 
             attribute = new BasicAttribute( "modifyTimestamp" );
-            attribute.add( DateUtils.getGeneralizedTime( System.currentTimeMillis() ) );
+            attribute.add( DateUtils.getGeneralizedTime() );
             attributes.put( attribute );
 
             nexus.modify( newParentName, DirContext.REPLACE_ATTRIBUTE, attributes );

Modified: incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/DateUtils.java
Url: http://svn.apache.org/viewcvs/incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/DateUtils.java?view=diff&rev=123114&p1=incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/DateUtils.java&r1=123113&p2=incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/DateUtils.java&r2=123114
==============================================================================
--- incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/DateUtils.java	(original)
+++ incubator/directory/ldap/trunk/common/src/java/org/apache/ldap/common/util/DateUtils.java	Wed Dec 22 07:57:00 2004
@@ -16,12 +16,12 @@
  */
 package org.apache.ldap.common.util;
 
-
-import java.util.Calendar;
-
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.SimpleTimeZone;
 
 /**
- * Document this class.
+ * Gets the generalized time using the "Z" form of the g-time-zone.
  *
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
@@ -29,10 +29,10 @@
 public class DateUtils
 {
     /**
-     * Gets the generalized time using the g-differential option rather than
-     * zulu time described by [<a href=
+     * Gets the generalized time using the "Z" form of the g-time-zone
+     * described by [<a href=
      * "http://ietf.org/internet-drafts/draft-ietf-ldapbis-syntaxes-09.txt">
-     * SYNTAXES</a>] section 3.3.13.  We include this section below:
+     * SYNTAXES</a>] section 3.3.13, included below:
      * <pre>
      *
      * 3.3.13.  Generalized Time
@@ -90,113 +90,15 @@
      * SHALL NOT be used.
      * </pre>
      *
-     * @param millis time in milliseconds to calculate the generalized time
-     * @return the generalized time using the g-differential option for
-     * the default timezone
-     */
-    public static String getGeneralizedTime( long millis )
-    {
-        StringBuffer buf = new StringBuffer();
-        Calendar cal = Calendar.getInstance();
-        cal.setTimeInMillis( millis );
-
-        // append the century and year in one shot
-        buf.append( cal.get( Calendar.YEAR ) );
-
-        /*
-         * we add one because cal uses 0 based and LDAP uses 1 based month
-         * indexing - also we need to make sure we left pad the value w/ a 0
-         */
-        int month = cal.get( Calendar.MONTH ) + 1;
-        if ( month < 10 )
-        {
-            buf.append( '0' ).append( month );
-        }
-        else
-        {
-            buf.append( month );
-        }
-
-        // we need to make sure we left pad the value w/ a 0
-        int dayOfMonth = cal.get( Calendar.DAY_OF_MONTH );
-        if ( dayOfMonth < 10 )
-        {
-            buf.append( '0' ).append( dayOfMonth );
-        }
-        else
-        {
-            buf.append( dayOfMonth );
-        }
-
-        int hourOfDay = cal.get( Calendar.HOUR_OF_DAY );
-        if ( hourOfDay < 10 )
-        {
-            buf.append( '0' ).append( hourOfDay );
-        }
-        else
-        {
-            buf.append( hourOfDay );
-        }
-
-        int minute = cal.get( Calendar.MINUTE );
-        if ( minute < 10 )
-        {
-            buf.append( '0' ).append( minute );
-        }
-        else
-        {
-            buf.append( minute );
-        }
-
-        int second = cal.get( Calendar.SECOND );
-        if ( second < 10 )
-        {
-            buf.append( '0' ).append( second );
-        }
-        else
-        {
-            buf.append( second );
-        }
-
-        // calculate the offset, the -/+ value for g-differential, and take abs
-        int offset = cal.getTimeZone().getRawOffset();
-        buf.append( offset > 0 ? '+' : '-' );
-        offset = Math.abs( offset );
-
-        // calculate the offset hours
-        int offsetHours = ( offset / 3600000 );
-        if ( offsetHours < 10 )
-        {
-            buf.append( '0' ).append( offsetHours );
-        }
-        else
-        {
-            buf.append( offsetHours );
-        }
-
-        // calculate the offset minutes
-        int offsetMinutes = ( offset / 1000 ) % 3600;
-        if ( offsetMinutes < 10 )
-        {
-            buf.append( '0' ).append( offsetMinutes );
-        }
-        else
-        {
-            buf.append( offsetMinutes );
-        }
-
-        return buf.toString();
-    }
-
-
-    /**
      * Gets the generalized time right now.
      *
-     * @see DateUtils#getGeneralizedTime(long)
      * @return the generalizedTime right now
      */ 
     public static String getGeneralizedTime()
     {
-        return getGeneralizedTime( System.currentTimeMillis() );
-    }
+      SimpleDateFormat date = new SimpleDateFormat( "yyyyMMddHHmmss'Z'" );
+      date.setTimeZone( new SimpleTimeZone(0,"Z") );
+      return date.format( new Date() );
+    } 
 }
+

Deleted: /incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/util/DateUtilsTest.java
Url: http://svn.apache.org/viewcvs/incubator/directory/ldap/trunk/common/src/test/org/apache/ldap/common/util/DateUtilsTest.java?view=auto&rev=123113
==============================================================================

Re: svn commit: r123114 - in incubator/directory: eve/trunk/core/src/java/org/apache/eve/jndi/ibs ldap/trunk/common/src/java/org/apache/ldap/common/util ldap/trunk/common/src/test/org/apache/ldap/common/util

Posted by Enrique Rodriguez <er...@apache.org>.
They are identical.  GMT is the "civilian" name, UTC is the 
international name defined by the UN as the initials would appear in French.

Z-time format is used in the RFC's and drafts.  The "Z" will appear in 
the timestamp and LDIF exports and since it's common in LDAP and 
Kerberos to view dates like that, I don't find it less clear.  Less 
readable for most Java developers, maybe ... normal if you view Ethereal 
captures or these RFCs.  I would rather not change it.

Defining it once is a good point though, as a constant like Z_TIME, 
which I would find even clearer and, as you noted, it is creating 
objects unnecessarily.

-enrique


Brett Porter wrote:
> I've always used UTC. It is slightly different from GMT isn't it?
> 
> Quoting Berin Loritsch <bl...@d-haven.org>:
> 
> 
>>Brett Porter wrote:
>>
>>
>>>erodriguez@apache.org wrote:
>>>
>>>
>>>>+      date.setTimeZone( new SimpleTimeZone(0,"Z") );
>>>> 
>>>>
>>>
>>>Is this just getting GMT? I would speculate (though have never tested 
>>>whether it performs any differently), that TimeZone.getTimeZone("GMT") 
>>>would be better, and is at least more readable.
>>>I also believe it to be immutable, so you can use it a static instance 
>>>rather than recreate it each time.
>>
>>
>>I agree.  Either "GMT" or "UTC".
>>
>>-- 
>>
>>"Programming today is a race between software engineers striving to build
>>bigger and better idiot-proof programs, and the Universe trying to produce
>>bigger and better idiots. So far, the Universe is winning."
>>                - Rich Cook
>>
> 
> 
> 

Re: svn commit: r123114 - in incubator/directory: eve/trunk/core/src/java/org/apache/eve/jndi/ibs ldap/trunk/common/src/java/org/apache/ldap/common/util ldap/trunk/common/src/test/org/apache/ldap/common/util

Posted by Brett Porter <br...@apache.org>.
I've always used UTC. It is slightly different from GMT isn't it?

Quoting Berin Loritsch <bl...@d-haven.org>:

> Brett Porter wrote:
> 
> > erodriguez@apache.org wrote:
> >
> >> +      date.setTimeZone( new SimpleTimeZone(0,"Z") );
> >>  
> >>
> > Is this just getting GMT? I would speculate (though have never tested 
> > whether it performs any differently), that TimeZone.getTimeZone("GMT") 
> > would be better, and is at least more readable.
> > I also believe it to be immutable, so you can use it a static instance 
> > rather than recreate it each time.
> 
> 
> I agree.  Either "GMT" or "UTC".
> 
> -- 
> 
> "Programming today is a race between software engineers striving to build
> bigger and better idiot-proof programs, and the Universe trying to produce
> bigger and better idiots. So far, the Universe is winning."
>                 - Rich Cook
> 




Re: svn commit: r123114 - in incubator/directory: eve/trunk/core/src/java/org/apache/eve/jndi/ibs ldap/trunk/common/src/java/org/apache/ldap/common/util ldap/trunk/common/src/test/org/apache/ldap/common/util

Posted by Berin Loritsch <bl...@d-haven.org>.
Brett Porter wrote:

> erodriguez@apache.org wrote:
>
>> +      date.setTimeZone( new SimpleTimeZone(0,"Z") );
>>  
>>
> Is this just getting GMT? I would speculate (though have never tested 
> whether it performs any differently), that TimeZone.getTimeZone("GMT") 
> would be better, and is at least more readable.
> I also believe it to be immutable, so you can use it a static instance 
> rather than recreate it each time.


I agree.  Either "GMT" or "UTC".

-- 

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
                - Rich Cook


Re: svn commit: r123114 - in incubator/directory: eve/trunk/core/src/java/org/apache/eve/jndi/ibs ldap/trunk/common/src/java/org/apache/ldap/common/util ldap/trunk/common/src/test/org/apache/ldap/common/util

Posted by Brett Porter <br...@apache.org>.
erodriguez@apache.org wrote:

>+      date.setTimeZone( new SimpleTimeZone(0,"Z") );
>  
>
Is this just getting GMT? I would speculate (though have never tested 
whether it performs any differently), that TimeZone.getTimeZone("GMT") 
would be better, and is at least more readable.
I also believe it to be immutable, so you can use it a static instance 
rather than recreate it each time.

Cheers,
Brett