You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Benedikt Ritter (JIRA)" <ji...@apache.org> on 2014/01/17 13:27:19 UTC

[jira] [Commented] (LANG-951) Fragments are wrong by 1 day when using fragment YEAR or MONTH

    [ https://issues.apache.org/jira/browse/LANG-951?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13874715#comment-13874715 ] 

Benedikt Ritter commented on LANG-951:
--------------------------------------

Hello Sebastian,

would it be possible that you create a patch file that contains a junit test that fails without the proposed fix and is successful after including it?

Also, if you plan to contribute on a regular basis (which I would appreciate ;-) ) you should file an [Individual Contributor Licence Agreement|http://www.apache.org/licenses/].

Thanks!
Benedikt

> Fragments are wrong by 1 day when using fragment YEAR or MONTH
> --------------------------------------------------------------
>
>                 Key: LANG-951
>                 URL: https://issues.apache.org/jira/browse/LANG-951
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.time.*
>    Affects Versions: 3.1
>            Reporter: Sebastian Götz
>             Fix For: 3.3, Review Patch
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> 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 
> {code}
> private static long getFragment(Calendar calendar, int fragment, int unit)
> {code}
> 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:
> {code}
> // 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;
>         }
> {code}



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)