Issue Description
In certain circumstances Relative Dates seem to have incorrect values. For example in an Ad hoc from topic, relative date input control values seem flip-flipped or reversed.
Resolution
The DateRange class uses a few methods to determine the exact timestamp it should use, these are getStart() and getEnd() . So "DAY" theoretically could be the beginning of the day, or the end of the day when using day ranges. There is a bug open for investigation in which it seems the $X syntax uses the wrong order for calling getStart and getEnd on the begin and end inputs.
For example using "DAY" for both START_DATETIME and END_DATETIME in a $X{Between yields:
select * from employee where ( hire_date > ? AND hire_date < ? )
Parameter #1 (of type java.util.Date): Wed Jul 09 23:59:59 EDT 2014
Parameter #2 (of type java.util.Date): Wed Jul 09 00:00:00 EDT 2014
Using "WEEK" for both yields:
select * from employee where ( hire_date > ? AND hire_date < ? )
Parameter #1 (of type java.util.Date): Sat Jul 12 23:59:59 EDT 2014
Parameter #2 (of type java.util.Date): Sun Jul 06 00:00:00 EDT 2014
To help understand your case, In Manage -> Server Settings -> Log Settings, you can toggle the input control logging to DEBUG to see what times are getting resolved.
You can workaround this issue within your JRXML by casting/forcing the Input Control that the user gives into a specific range. For example take:
<parameter name="USER_START_DATETIME" class="net.sf.jasperreports.types.date.DateRange"/>
Then derive the begin_date like:
<parameter name="begin_date" class="java.util.Date" nestedType="java.util.Date"> <defaultValueExpression> <![CDATA[$P{USER_START_DATETIME}.getStart()]]> </defaultValueExpression> </parameter>
With the above technique you'll always get the beginning most value... so the start of the week when WEEK is chosen, or the start of the day when DAY is chosen, etc. Depending on your needs, maybe you want to do this for the End as well.
Ref. Case 00055476
Recommended Comments