I am using java and I have the following scenario.
The season entity one of the attributes is duration and a season can have many chapters, for each chapter that is added to a season, the duration of all the chapters is added and added to the season.
I am doing the following:
res.getTemporada().setDuracion(res.getTemporada().getDuracion() + res.getDuracion());
At the length of the season:
res.getTemporada().getDuracion()
I add the duration that I bring from the view of the new chapter, but the sum does not work in this conventional way
res.getDuracion()
Duration are of type Time
The truth is that the class
Time
is not suitable for the use you are giving it. Although time means time, the correct translation for its use would be time.For example, a class
Time
cannot reflect a duration that exceeds 24 hours.To save the duration of the chapters of a series, a convenient measure can be the minutes that they last, and that can be easily accumulated in a
int
. For example 80 hours would be80*60 = 4800 minutos
.You can then use a function that returns the time as a String by doing the reverse step. For example
4826 minutos
they are:And you can show it as:
String.format("%02d:%02d", hh, mm);