java - Joda Period not converting all minutes to hours "8h, 132m" -


i storing 2 datetimes (joda) in object , period object new period(datetime1, datetime2). want add periods different objects together. both adding periods in variable , summing periods in smaller periods stored in hashmap<long, period>.

the result , issue this. first period gets "2 hours , 30 minutes" periodformat.getdefault().print(p) (the values same if concatenate gethours , getminutes). second value "5 hours , 52 minutes". far good. when 3rd , 4th, minutes stop converting hours.

"5 hours , 103 minutes"

"8 hours , 132 minutes"

it should 10h , 12m, can see. that's not getting. issue? how can period forget conversion? don't have problems selected sums, yet.

code: (with variable names changed)

mainsum= new period(); taskssum= new hashmap<long, period>(); for(entry entry: entries){         long main_id= entry.getmain_id();         long task_id = entry.gettask_id();         period entryperiod = entry.getperiod();          if(main_id == mainstuff.getid()){             mainsum = entryperiod.plus(mainsum);             timber.d("mainsum: " + periodformat.getdefault().print(mainsum));             timber.d("sum of workplace: " + mainsum.gethours() + " : " + mainsum.getminutes());             period taskperiod = tasksperiodsums.remove(task_id);             if(taskperiod == null){                 tasksperiodsums.put(task_id, entryperiod);             } else {                 tasksperiodsums.put(task_id, taskperiod.plus(entryperiod));             }         }     } 

please help, thank :)

this documented behaviour, check out javadoc plus(period) function:

/**  * returns new period specified period added.  * <p>  * each field of period added separately. period of  * 2 hours 30 minutes plus 3 hours 40 minutes produce result  * of 5 hours 70 minutes - see {@link #normalizedstandard()}.  * <p> ... 

drilling down javadoc of normalizedstandard(..) function itself, see what's tradeoff:

/**  * normalizes period using standard rules, assuming 12 month year,  * 7 day week, 24 hour day, 60 minute hour , 60 second minute,  *  ...  * achieve makes assumption years  * 12 months, weeks 7 days, days 24 hours,  * hours 60 minutes , minutes 60 seconds. not  * true when daylight savings time considered, , may not true  * chronologies. ... 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -