Uploaded image for project: 'Derby'
  1. Derby
  2. DERBY-4752

CheapDateFormatter returns incorrect and invalid date strings

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

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 10.7.1.1
    • 10.7.1.1
    • Services
    • None

    Description

      CheapDateFormatter has multiple problems. These are the ones I'm aware of:

      1) On the boundary between non-leap years and leap years it will return first day of thirteenth month in previous year (for instance, 2011-13-01 instead of 2012-01-01)

      2) It treats all years divisible by four as leap years. Those divisible by 100 and not by 400 are not leap years. It attempts to adjust for that (see the snippet below) but it always ends up setting leapYear=true if (year%4)==0.

      // It's a leap year if divisible by 4, unless divisible by 100,
      // unless divisible by 400.
      if ((year % 4L) == 0) {
      if ((year % 100L) == 0) {
      if ((year % 400L) == 0)

      { leapYear = true; }

      }
      leapYear = true;
      }

      3) More leap year trouble. To find out which year it is, it calculates the number of four year periods that have elapsed since 1970-01-01. A four year period is considered 365*3+366 days. Although most four year periods are of that length, some are shorter, so we'll get one day off starting from year 2100, two days off from year 2200, and so on.

      Attachments

        1. CheapFormatterPerfTest.java
          0.9 kB
          Knut Anders Hatlen
        2. derby-4752-1a.diff
          11 kB
          Knut Anders Hatlen
        3. derby-4752-1b.diff
          11 kB
          Knut Anders Hatlen
        4. derby-4752-1c.diff
          11 kB
          Knut Anders Hatlen
        5. remove-cheap-formatter.diff
          20 kB
          Knut Anders Hatlen
        6. remove-cheap-formatter.stat
          0.8 kB
          Knut Anders Hatlen

        Issue Links

        Activity

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

          People

            knutanders Knut Anders Hatlen
            knutanders Knut Anders Hatlen
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment