0

I´m not asking how to calculate minutes to hh:mm in java. I´m asking the best way to do it in jaspersoft. Because it´s done and it works. i´m only interseted in the print part in the report in the format "hh:mm "h""

I'm working in a report that must print the time in hh:mm format. (I´m editing a current production report and I want to do the minnor changes posible).

In BD we have at DateTime (DateTimeOffset) the Start and the End of the event.

This is a summatory of all the events the worker had done in a period of time.

Nowadays the report works getting per row the minutes between end and start. And then make a variable (That is a Sum of all the minutes). I do this with several variables because at the end the time is calculate in base of some checks the user has.

I have one more variable to add this minutes to the total if are checked.

And at the end in the Text Field I print this with :

($V{Total_Time}/60)+ ":" 
+ (IF($V{Total_Time}%60 < 10,"0"+$V{Total_Time}%60,$V{Total_Time}%60))
+" h"

The type of Total_Time variable is Integer

I´m looking for a best way to do this

Willas
  • 63
  • 1
  • 10
  • What type of `$V{Total_Time}`? Integer? – Alex K Jan 15 '18 at 15:47
  • $V{Total_Time} is Integer – Willas Jan 15 '18 at 15:48
  • `I´m not asking how to calculate minutes to hh:mm in java. I´m asking the best way to do it in jaspersoft. Because it´s done and it works.` - The JasperReports expression supports Java language. This is why it is a duplicate – Alex K Jan 16 '18 at 07:59
  • It still does not help the good practices when it comes to implment – Willas Jan 16 '18 at 10:54
  • Really? ;) What options did you try (from this dupe post)? – Alex K Jan 16 '18 at 11:04
  • String.format("%d : %02d h",$V{Total_Time}/60,$V{Total_Time}%60 ) I used this form which is practically the one I was using. And the post has barely oriented me. Your reference to Java is vague and unintuitive when the question is. It is the best way? – Willas Jan 16 '18 at 11:53
  • `It is the best way?` - To use expression on Java? - Yes. – Alex K Jan 16 '18 at 11:58
  • I have to use this in quite a few different reports. And what I was looking for is whether so much reuse should not use a "user function" – Willas Jan 16 '18 at 12:02
  • There is no ready for use built-in function at JasperReports. You have to write something. I think that the best way is to this with Java. You can use *textField* expression or variable expression with pure Java expression. You can call scriptlet if you have already some custom code (library) – Alex K Jan 16 '18 at 12:11
  • So I will need a library to do a "minute to hh:mm h" formater. And looks like that in this case is to much code for this. Also looks like Patter or Pattern Expresion is not a good option for this case. So Thank You. But I don´t see intuitive what methods works in textfield – Willas Jan 16 '18 at 12:20

0 Answers0