commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Benedikt Ritter (JIRA)" <j...@apache.org>
Subject [jira] [Closed] (LANG-987) DateUtils.getFragmentInDays(Date, Calendar.MONTH) returns wrong days
Date Tue, 18 Mar 2014 18:19:47 GMT

     [ https://issues.apache.org/jira/browse/LANG-987?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Benedikt Ritter closed LANG-987.
--------------------------------


> DateUtils.getFragmentInDays(Date, Calendar.MONTH) returns wrong days
> --------------------------------------------------------------------
>
>                 Key: LANG-987
>                 URL: https://issues.apache.org/jira/browse/LANG-987
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.time.*
>    Affects Versions: 3.3
>            Reporter: Jay Xu
>            Assignee: Duncan Jones
>            Priority: Blocker
>             Fix For: 3.3.1
>
>
> Commons lang3 screwed up my system after upgraded to 3.3 last night!
> We use DateUtils.getFragmentInDays(Date, Calendar.MONTH) to extract days for later use.
Basically (in 3.2), 'today' (Mar. 13) returns 13, but, it returns 12 in 3.3!
> I compared the underlying method org.apache.commons.lang3.time.DateUtils.getFragment(Calendar,
int, int) between 3.2 and 3.3:
> 3.2
> {code:java}
>         // Fragments bigger than a day require a breakdown to days
>         switch (fragment) {
>             case Calendar.YEAR:
>                 result += (calendar.get(Calendar.DAY_OF_YEAR) * MILLIS_PER_DAY) / millisPerUnit;
>                 break;
>             case Calendar.MONTH:
>                 result += (calendar.get(Calendar.DAY_OF_MONTH) * MILLIS_PER_DAY) / millisPerUnit;
>                 break;
>         }
> {code}
> 3.3
> {code:java}
>         // 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;
>             default:
>                 break;
>         }
> {code}
> Is there ANY ANY reason for adding '-1' in 3.3?! Plus, do you have any unit test for
this method?



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Mime
View raw message