[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

javahl date/time conversions in Status.java

From: Daniel Rall <dlr_at_finemaltcoding.com>
Date: 2005-04-28 02:11:43 CEST

Patrick, I'm curious why Status's getLastChangedDate() and
getLockCreationDate() date accessor methods divide their respective
longs by 1000? I'd assume those longs to represent either millis or
seconds, in which case they'd be used with no conversion, or multiplied
by 1000 before handing off to java.util.Date's constructor (which takes
time-since-epoch in milliseconds as an argument).

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Date.html#Date(long)

Do I misunderstand, or should I make the following change?

Thanks, Dan

---
subversion/bindings/java/javahl/src/org/tigris/subversion/javahl/Status.java	(revision 14486)
+++
subversion/bindings/java/javahl/src/org/tigris/subversion/javahl/Status.java	(working copy)
@@ -240,10 +240,7 @@
      */
     public Date getLastChangedDate()
     {
-        if (lastChangedDate == 0)
-            return null;
-        else
-            return new Date(lastChangedDate / 1000);
+        return millisToDate(lastChangedDate);
     }
 
     /**
@@ -535,10 +532,7 @@
      */
     public Date getLockCreationDate()
     {
-        if (lockCreationDate == 0)
-            return null;
-        else
-            return new Date(lockCreationDate / 1000);
+        return millisToDate(lockCreationDate);
     }
 
     /**
@@ -596,4 +590,15 @@
             }
         }
     }
+
+    /**
+     * Converts a milliseconds since the epoch to a Date object.
+     *
+     * @return A Date object, or <code>null</code> if
+     * <code>millis</code> was zero.
+     */
+    private static Date millisToDate(long millis)
+    {
+        return (millis == 0 ? null : new Date(millis));
+    }
 }
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Thu Apr 28 02:48:36 2005

This is an archived mail posted to the Subversion Dev mailing list.