GeeCON Prague 2014*
The moose likes Other Open Source Projects and the fly likes Dynamic jasper reports:  how to tell FastReportBuilder to respect timezone Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Dynamic jasper reports:  how to tell FastReportBuilder to respect timezone" Watch "Dynamic jasper reports:  how to tell FastReportBuilder to respect timezone" New topic
Author

Dynamic jasper reports: how to tell FastReportBuilder to respect timezone

Joe Simone
Greenhorn

Joined: Feb 16, 2005
Posts: 25
I am using this class

ar.com.fdvs.dj.domain.builders.FastReportBuilder

it is part of the the dynamic jasper package and allows creating jasper reports on-the-fly. The issue I have is that when I add a Timestamp column to my report, the time zone it uses for formatting is always EST.

Does anyone know how to accomplish this? Here is a snippet of code ...



I get this in the output: ... 12/06/2012 02:47:51 PM EST ...

Thanks in advance.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

What would "respecting a timezone" mean? I'm assuming that EST is the default time zone when the application runs, so what should cause the application to choose some other time zone?
Joe Simone
Greenhorn

Joined: Feb 16, 2005
Posts: 25
Paul Clapham wrote:What would "respecting a timezone" mean? I'm assuming that EST is the default time zone when the application runs, so what should cause the application to choose some other time zone?


Sorry if I was not clear. The code does make use of the timezone defaulted to EST. I just want to be able to pass in and change the timezone accordingly. For example if someone from the west coast runs the report I would like the date to be formatted for PST (his local zone) instead of the default EST.

I've spent most of the day trying to google an example of how this would be done.

Thanks in advance.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

That would involve knowing how the report was run. If the person from the west coast ran the report on their own computer, then the default time zone would be their time zone and you wouldn't be asking the question. So I have to conclude that somehow the person from the west coast is running the report somehow on some other computer.
Joe Simone
Greenhorn

Joined: Feb 16, 2005
Posts: 25
True.

The reports are all run on our east coast servers, hence the default JVM timezone of EST. However, the customer's data maybe from another timezone - the one they are located in. The code that gets called for the jasper csv export has as one of its invocation parameter the timezone, but we have no place to set it so dynamic jasper FastReportBuilder can make use of it.

Therefore, I am stuck.

Thanks in advance.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Joe Simone wrote:The code that gets called for the jasper csv export has as one of its invocation parameter the timezone, but we have no place to set it so dynamic jasper FastReportBuilder can make use of it.


So there are two problems (I think).

(1) You need to fix that code so that you do have a place to set the time zone.

(2) You need some way of deciding which time zone to set, once (1) is fixed.
Joe Simone
Greenhorn

Joined: Feb 16, 2005
Posts: 25

I tried setting timezone in the jasperPrint object thusly



and I still get the following in the CSV export ...

TIME ZONE SET TO ...US/Pacific
... ,12/06/2012 05:55:44 PM EST, ...

Not much progress today!

Thanks in advance.
Joe Simone
Greenhorn

Joined: Feb 16, 2005
Posts: 25
This jasper forum comments seems to indicate this was recently addressed and fixed:

jasper community issue 4616
Joe Simone
Greenhorn

Joined: Feb 16, 2005
Posts: 25
public static final String PROPERTY_TIME_ZONE = "net.sf.jasperreports.jdbc.time.zone"

How to set this property and where is now the question
Joe Simone
Greenhorn

Joined: Feb 16, 2005
Posts: 25
I updated both DynamicJasper to 4.0.3 and jasper reports to 4.7.1 and tried to set the time zone 4 places in the code below. Still fails to set the timezone correctly.



Results we get are still wrong. Note the EST in the formatted date.

Joe Simone
Greenhorn

Joined: Feb 16, 2005
Posts: 25
Here is the solution to the problem. We must get the jasper print object to respect timezone and setting the timezone id was not having the expected results.



Now, by passing in a parameter map indicating the new timezone to override the default JVM timezone, we are able to get the JasperPrint object to respect the timezone.

This was tested with Dynamic Jasper 4.0.3 and Jasper reports version 5.0.0. I don't know if this functionality is broken in older versions of these jars so your results may vary.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Thanks for the follow-up, Joe!

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamic jasper reports: how to tell FastReportBuilder to respect timezone