views:

42

answers:

2

I posted this on the JasperServer forums, but I've had better luck on StackOverflow generally. Please help if you can.

My biggest single gripe about JasperServer is that it flat out behaves differently than JasperReport (specifically, jasperreports developed in iReport).

The problem I'm seeing now is that dates are displayed as one day prior (in fact, exactly 4 hours prior) to the date put into the parameter.

this is what I put into the default value expression of the JRXML:

((new Date().getMonth() / 3) + 1 == 1)? new Date(new Date().getYear(), 0, 1) :

((new Date().getMonth() / 3) + 1 == 2)? new Date(new Date().getYear(), 3, 1) :

((new Date().getMonth() / 3) + 1 == 3)? new Date(new Date().getYear(), 6, 1) :

new Date(new Date().getYear(), 9, 1)

This code works to correctly calculate the beginning of the quarter from within the default value expression of JasperReports. When i run this through iReport, i see no problem whatsoever. For any reports I've run in this quarter, i'm seeing July 1, 2010 as the start date.

When I modify the JRXML to account for the "repo:subreport_name" format of jasperserver and run this report and have jasperserver email the output to me I get a different result:

6/30/10 8:00 PM

This seems like a bug to me.

A: 

It looks like a time zone problem.

It seems to be printing your date 4 hours in the past.

Where is the server you are running from?

Can you check it's time zone?

For example take a look at this code. It will print a different day and month depending on the time zone.

Date date = ((new Date().getMonth() / 3) + 1 == 1) ? new Date(new Date().getYear(), 0, 1)
    :((new Date().getMonth() / 3) + 1 == 2) ? new Date(new Date().getYear(), 3, 1) 
    :((new Date().getMonth() / 3) + 1 == 3) ? new Date(new Date().getYear(), 6, 1) 
    :new Date(new Date().getYear(), 9, 1);
System.out.println(date);

Outputs: Thu Jul 01 00:00:00 BST 2010

TimeZone.setDefault(TimeZone.getTimeZone("PST"));
System.out.println(date);

Outputs Wed Jun 30 16:00:00 PDT 2010 with the same date.

Bit of hack but you could set the hour to later in the day to guarantee it gets the right day for example:

new Date(new Date().getYear(), 3, 1,23,59); 

Edit:

The correct way to set the time zone your jasper report is through the datasource.

Just call the setTimeZone() method on your data source before passing to your report for example

mydatasource.setTimeZone(TimeZone.getTimeZone("BST"));

The problem is the server see no time zone is set so just uses the default causing your date error.

Gordon
That's almost certainly the problem. I can't, however, set the TimeZone as you would in a Java application.
Ramy
Ramy
which effectively says this:Resolved the problem by blanking the time zone setting for the data sources used in JasperServer. Apparently if this is left blank on the data source config, it will use the local time zone (since I am 7-8 hours from GMT, the time difference calc's were resulting in dates being one-day off).how do I go about "blanking the time zone setting for the data sources used in JasperServer."?
Ramy
Yeah, that's a bit of a hack. I could definitely do that, the only problem is if I ever do figure out how to "blank the timezone setting for the data sources..." i'll have to go back and chance all these back....If I don't find an answer by EOD, I'll have to use this.
Ramy
Gordon, I really appreciate your help with this.Where would I create the mydatasource object you describe??All I'm doing now is uploading the jrxml to jasperserver. I'm not calling jasperserver programmatically or anything like that.
Ramy
What is the datasource on the jasper server your report is using? You are meant to set the time-zone within that.
Gordon
You're right, Gordon. So, I logged in and went to the datasource for the report in the repository. I selected the checkbox for that datasource and clicked on Edit.THERE I found a drop down box (similar to the one at the login screen) but with the option to leave it blank. Why it doesn't use EST when EST is selected both on the login screen and under the datasource configuration is utterly beyond me....
Ramy
+1  A: 

Straight from the horse's mouth:

http://jasperforge.org/plugins/espforum/view.php?group_id=112&forumid=107&topicid=77176

Ramy