Reputation: 2527
I have a very odd problem. I'm using joda time to return the difference between two time periods that contain full minutes. That is, seconds are always zero. For some reason, joda time will sometimes return 59 seconds for a time difference of 1 minute. Anyone have an idea why?
Calculation of time difference:
Period rowTime = new Period ( mTask.getTimestamps ().get ( i - 2 ), mTask.getTimestamps ().get ( i - 1 ) );
Getting time:
String hour = Integer.toString ( rowTime.getHours () );
String minute = Integer.toString ( rowTime.getMinutes () );
String second = Integer.toString ( rowTime.getSeconds () );
Test code:
LocalDateTime start = mTask.getTimestamps ().get ( i - 2 );
LocalDateTime end = mTask.getTimestamps ().get ( i - 1 );
int startMinute = start.getMinuteOfHour ();
int startSecond = start.getSecondOfMinute ();
int endMinute = end.getMinuteOfHour ();
int endSecond = end.getSecondOfMinute ();
tvRowTime.setText ( startMinute + ":" + startSecond + " > " + endMinute + ":" + endSecond + " > " + hour + ":" + minute + ":"
+ second );
Indeed, the test code clearly shows that the start / end times (m:s) 1:0 / 2:0 can give 0:0:59. I.e., the difference is clearly exactly 1 minute, but joda time sometimes returns 59 seconds.
Upvotes: 1
Views: 94
Reputation: 2527
Solution:
I'm an idiot. I forgot joda time uses milliseconds. Time for a break...
Upvotes: 1