You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Daniel Rall <dl...@finemaltcoding.com> on 2005/04/28 00:11:43 UTC

javahl date/time conversions in Status.java

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

Re: javahl date/time conversions in Status.java

Posted by Daniel Rall <dl...@finemaltcoding.com>.
Thanks Patrick!  Adjusted the refactoring accordingly, and doc'd that
fact.


On Thu, 2005-04-28 at 09:13 +0200, Patrick Mayweg wrote:
>Hi Daniel,
>the date/time in subversion are microseconds and java works with millis. 
>That why I divide by 1000.
>Regards.
>Patrick
>
>Daniel Rall wrote:
>
>>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

Re: javahl date/time conversions in Status.java

Posted by Patrick Mayweg <ma...@qint.de>.
Hi Daniel,
the date/time in subversion are microseconds and java works with millis. 
That why I divide by 1000.
Regards.
Patrick

Daniel Rall wrote:

>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