Jump to content

Problems trying to pass from Epoch to Date


GonzaLinares

Recommended Posts

Hi, just 1 week old with Jaspersoft Server

I have one requirement to get a date from an epoch time (seconds passed since 1970/01/01 ) parameter named "EpochParam" and show it in as a column in an ad hoc view

What i tried to do:

-First i created a field "EpochDate", using the Date() function given, and using as parameter '1970-01-01'.

-Then i created another calculated field "TimeSinceEpoch" where i calculate the days that passed since "EpochDate".  Round(ElapsedDays(Today(),"EpochDate")). This gives me a rounded double

-After this another calculated field "EpochToDays", in this one i pass from given epoch time to days.  Round(("EpochParam"/ 86400) - "TimeSinceEpoch").

=>The 86400 comes from 60sec in 1min, 60min in 1hour and 24hours in 1 day. Then 60x60x24=86400

=>The substract is in order to use function Today(), so i can substract total days since epoch time and then add my epoch param

-Last, what i do is an IF statement where i check if the "EpochParam" given is null or not. Here is where i have some problems

IF(IsNull("EpochParam"), Condition1, Condition2)

As condition1 i want to give a white space ''.

As condition2 i want to use function Today() substracting "EpochToDays".

 

The problems i get are:

1) Condition1 and condition2 must be same type. A workaround could be formating condition2 as a string, but i´m not sure how to do it

2) Condition2 gives an error because EpochToDays is double and Today only accept Integers.

I know it could be easier by modifying the applicationContext-semanticLayer config file and adding some new functions, but again, not sure how to do this, what syntax to use and how to formulate it.

Any help would be nice!

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

After some work, i could achieve to show the table just the way i want, like in this picture:

https://imgur.com/ObxWZOH

Anyway when i try to export it as PDF or any other format i get this message:

Error Message

java.lang.NumberFormatException: For input string: "5696.0"

I guess this is happening because i´m using Integer() function in order to cast "EpochToDays" as Integer and then be able to use it in Today() function.

And Integer() function receives as param just Strings, so first i had to cast "EpochToDays" to String by using Concatenate( 'string' , '' ) function.

After all this process, Integer() finds that dot in "5696.0" and crash because a dot is not a number..

What i can not understand is why it works and shows me the tables there, but then it crash when i try to export it as PDF.

 

Link to comment
Share on other sites

Hi Gonzalo,

You are right, please convert it into decimal rather than integer. Presumably it crashes because PDF export has a separate logic than report rendering and in your case the former is working while the latter does not. To cover both scenarios, please convert value to decimal and it should be okay. Also, please make sure the string value being converted has been trimmed already. Hope this helps.

Thanks.

Link to comment
Share on other sites

  • 5 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...