Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.1
-
None
Description
When one trys to get the fragments of a calendar object and uses the fragment YEAR or MONTH, the returned value is wrong by 1 day in the targeted timeunit. The bug resides in the class DateUtils in function
private static long getFragment(Calendar calendar, int fragment, int unit)
There is an initial recalculation if the fragment is YEAR or MONTH. So if one would like to have the minutes for the fragment YEAR for the date 2000-01-01 00:00:00 this would return 1440 which is actually wrong. The error can be found on lines 1635 - 1643.
Suggested fix:
// Fragments bigger than a day require a breakdown to days switch (fragment) { case Calendar.YEAR: result += ((calendar.get(Calendar.DAY_OF_YEAR)-1) * MILLIS_PER_DAY) / millisPerUnit; break; case Calendar.MONTH: result += ((calendar.get(Calendar.DAY_OF_MONTH)-1) * MILLIS_PER_DAY) / millisPerUnit; break; }
Attachments
Attachments
Issue Links
- is related to
-
LANG-987 DateUtils.getFragmentInDays(Date, Calendar.MONTH) returns wrong days
- Closed