How to set Date variable for "Tomorrow + 3 hours"

Stimulsoft Reports.JAVA discussion
Post Reply
denis.awfm
Posts: 23
Joined: Wed Sep 25, 2019 7:19 pm

How to set Date variable for "Tomorrow + 3 hours"

Post by denis.awfm »

Problem:
I have a variable in report, which is of DateTime type.
If I use .AddDays(1.125) it renders fine in Designer.
However, when I publish report as Java, it defaults to current timestamp.

If I try to set up the value via Java code, like this (previously set init by Value in Designer, otherwise it has no effect):

Date dateWithoutTime = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(dateWithoutTime);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.add(Calendar.HOUR_OF_DAY, 3);
dateWithoutTime = cal.getTime();
report1.setRequestParameters(true);
report1.getDictionary().getVariables().get("vScheduledEnd").setValue(dateWithoutTime);

I get exception inside StimulSoft Java application:
java.text.ParseException: Unparseable date "Thu Jan 09 03:00:00 EET 2020"

Please advice how can I set the value of that variable either in Designer (as expression) or programmatically (via Java code).

I searched for an example, but it was for a String variable, which is not my case (DateTime).
If I try to use .setValueObject method I get same error
Vadim
Posts: 363
Joined: Tue Apr 23, 2013 11:23 am

Re: How to set Date variable for "Tomorrow + 3 hours"

Post by Vadim »

Hello.
We tried Java with 2020.1 version and AddDays() works fine
Attachments
var2.PNG
var2.PNG (18.6 KiB) Viewed 6628 times
var1.PNG
var1.PNG (78.1 KiB) Viewed 6628 times
denis.awfm
Posts: 23
Joined: Wed Sep 25, 2019 7:19 pm

Re: How to set Date variable for "Tomorrow + 3 hours"

Post by denis.awfm »

Hi Vadim.
Indeed in 2020.1 AddDays() does work.
Now, I am still receiving current timestamp for a variable if it is initialized by expression Today.AddDays(1.125), where I would expect next day + 03:00. (like Variable2 in your example from the above).
I mean when it is requested from user (parameter sub window).
Also, how can I achieve correct date and time format in Java (in Designer it is fine) for that variable when asked in a parameter window, it always defaults to US (MM/DD/YYYY HH:MI:SS AM/PM)? I would like to enforce by default the European DD/MM/YYYY HH24:MI:SS format.
Screenshot is attached.
Regards,
Denis.
Attachments
No_AddDays_in_parameter_window.PNG
No_AddDays_in_parameter_window.PNG (23.66 KiB) Viewed 6626 times
denis.awfm
Posts: 23
Joined: Wed Sep 25, 2019 7:19 pm

Re: How to set Date variable for "Tomorrow + 3 hours"

Post by denis.awfm »

Followup:
If I use a "buffer" variable (which is initialized by expression Today.AddDays(1.125)), which is not requested from user, stays on top in Variables section of the Dictionary, and the requested variable is initialized by value of that "buffer" variable, it still displaying current timestamp in Parameters subwindow, therefore this trick does not work.
Attachments
Variable_vScheduledStart.PNG
Variable_vScheduledStart.PNG (29.31 KiB) Viewed 6622 times
Variable_v03.PNG
Variable_v03.PNG (20.98 KiB) Viewed 6622 times
Vadim
Posts: 363
Joined: Tue Apr 23, 2013 11:23 am

Re: How to set Date variable for "Tomorrow + 3 hours"

Post by Vadim »

Hello.

We fixed variables in variables panel - will available from next version.

DateTime format in parameters control takes from browser settings, also you can define your own format by StiWebViewerOptions object:
options.getAppearance().setParametersPanelDateFormat()
denis.awfm
Posts: 23
Joined: Wed Sep 25, 2019 7:19 pm

Re: How to set Date variable for "Tomorrow + 3 hours"

Post by denis.awfm »

Hi Vadim.
Thanks for the answer, I was able to set up date and time format in parameters panel, using:

options.getAppearance().setParametersPanelDateFormat("dd/MM/yyyy HH:mm:ss");

for something like 16/01/2020 22:40:00
Andrew
Posts: 4104
Joined: Fri Jun 09, 2006 3:58 am

Re: How to set Date variable for "Tomorrow + 3 hours"

Post by Andrew »

Hello,

Thank you for sharing your knowledge.

Have a nice day!
denis.awfm
Posts: 23
Joined: Wed Sep 25, 2019 7:19 pm

Re: How to set Date variable for "Tomorrow + 3 hours"

Post by denis.awfm »

Hi Andrew.
In version 2020.2 if I do publish report in Java, stimulsoft*.jar's are not put in the .zip file.
Therefore I cannot test if that has been fixed (I mean the issue where time parameters in Java are defaulting to current timestamp).
Can you please advice how can I test it?
Regards,
Denis.
denis.awfm
Posts: 23
Joined: Wed Sep 25, 2019 7:19 pm

Re: How to set Date variable for "Tomorrow + 3 hours"

Post by denis.awfm »

Hi Andrew.
I was able to download the latest stimulsoft libraries (*.jar). Just forgot to take off the checkbox in Publish screen.
And now Java window where date parameters are set works as planned (.AddDays() instead of current timestamp).
Thanks,
Denis.
Lech Kulikowski
Posts: 6240
Joined: Tue Mar 20, 2018 5:34 am

Re: How to set Date variable for "Tomorrow + 3 hours"

Post by Lech Kulikowski »

Hello

We are always glad to help you!
Please let us know if you need any additional help.

Thank you.
Post Reply