[Pljava-dev] Function taking timestamp argument.

Peter Henderson peter.henderson at starjar.com
Thu Sep 13 10:11:03 UTC 2007


Hi folks

I think there is a bug converting from Postgres timestamps to java time 
stamps.

I have a java function,

     public static BigDecimal calculateTotal(int accountId,
             java.sql.Timestamp startDate, java.sql.Timestamp endDate,
             boolean includeChildren)
     {
         BigDecimal result = BigDecimal.ZERO;

         java.util.Date now = new java.util.Date();

Logger.getAnonymousLogger().log(Level.WARNING,
         String.format("calculateTotal " +
         "accountId=%d startDate=%tD endDate=%tD includeChildren=%b " +
         "startDate.getTime()=%d now=%tD now.getTime()=%d",
         accountId, startDate, endDate, includeChildren,
         startDate.getTime(), now, now.getTime() )
         );



Which prints out

2007-09-13 11:09:22 BST WARNING:  13 Sep 07 11:09:22 
com.starjar.starjarenterprise.postgres.AccountTotal calculateTotal 
accountId=10026
startDate=10/04/77
endDate=01/21/78
includeChildren=false
startDate.getTime()=244785357000
now=09/13/07
now.getTime()=1189678162445


when called from SQL via

SELECT accounttotal(10026,
   CURRENT_TIMESTAMP,
   timestamp '2008-01-01 00:00', FALSE );



Notice the java log message.
It thinks the current time as passed in from SQL is 10/04/77 with a long 
of 244784200000
where as java thinks the current time long is 1189677005798


Is this a bug in my code (most likely)? a bug in pljava, or a bug in the 
way i am calling the function?



Regards


Peter Henderson.









More information about the Pljava-dev mailing list