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:[EMAIL PROTECTED]">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 ==============================================================================
