Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-987

DateUtils.getFragmentInDays(Date, Calendar.MONTH) returns wrong days

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 3.3
    • 3.3.1
    • lang.time.*
    • None

    Description

      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

              // 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;
              }
      

      3.3

              // 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;
              }
      

      Is there ANY ANY reason for adding '-1' in 3.3?! Plus, do you have any unit test for this method?

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            dmjones500 Duncan Jones
            mustangxu@gmail.com Jay Xu
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment