You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ofbiz.apache.org by Adrian Crum <ad...@hlmksw.com> on 2007/12/10 16:35:48 UTC

Re: svn commit: r602650 - /ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java

Hans,

Since both of these methods are single-line calculations, why can't you replace the method calls 
with the single line calculations?

If you want to adjust a date/time, use the UtilDateTime.adjustTimestamp(Timestamp stamp, int 
adjType, int adjQuantity, TimeZone timeZone, Locale locale) method.

If you want to calculate elapsed time, the method you provided will not work - it will return 
unpredictable results. There was a "calculate elapsed time" Jira issue created, maybe you could take 
a look at it - https://issues.apache.org/jira/browse/OFBIZ-715.

-Adrian

hansbak@apache.org wrote:

> Author: hansbak
> Date: Sat Dec  8 23:58:41 2007
> New Revision: 602650
> 
> URL: http://svn.apache.org/viewvc?rev=602650&view=rev
> Log:
> show number of days between timestamps and add a day to a timestamp. I realize this is perhaps not the best method, but it works. If somebody has suggestions to do it better, pleae let me now, i will change it....
> 
> Modified:
>     ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java
> 
> Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java
> URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java?rev=602650&r1=602649&r2=602650&view=diff
> ==============================================================================
> --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java (original)
> +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilDateTime.java Sat Dec  8 23:58:41 2007
> @@ -75,6 +75,14 @@
>          return thru != null ? thru.getTime() - from.getTime() : 0;
>      }
>  
> +    public static int getIntervalInDays(Timestamp from, Timestamp thru) {
> +        return thru != null ? (int) (thru.getTime() - from.getTime()) / (24*60*60*1000) : 0;
> +    }
> +
> +    public static Timestamp addDaysToTimestamp(Timestamp start, int days) {
> +        return new Timestamp(start.getTime() + (24*60*60*1000*days));
> +    }
> +
>      public static double getInterval(Timestamp from, Timestamp thru) {
>          return thru != null ? thru.getTime() - from.getTime() + (thru.getNanos() - from.getNanos()) / 1000000 : 0;
>      }
> 
> 
>