Uploaded image for project: 'Jira Data Center'
  1. Jira Data Center
  2. JRASERVER-14952

javascript popup calendar day of year calculation is incorrect in daylight savings time

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Handled by Support
    • Icon: Low Low
    • None
    • 3.12
    • None
    • standalone, jdk 1.5, redhat linux

      Using the Javascript calendar popup to return year/dayofyear (%Y/%j), the day of year is incorrect by one day for any day of the year after March 9. Both March 9 and March 10, 2008 produce DOY 069.

      This is because the doy is calculated as (milliseconds(today) - milliseconds(Jan 1))/86400000; after March 9, milliseconds(today) includes an extra hour due to daylight savings time. This throws off the calculation enough to cause a roundoff error.

      I modified two files in directory atlassian-jira/includes/js/calendar: calendar.js and calendar-min.js, changing the getDayOfYear function to use UTC in its calculation, rather than local machine time. Here is a diff of calendar.js showing the changes:

      1. diff calendar.js calendar.js~
        1833,1834c1833,1834
        < var now = Date.UTC(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
        < var then = Date.UTC(this.getFullYear(), 0, 1, 0, 0, 0);
          • > var now = new Date(this.getFullYear(), this.getMonth(), this.getDate(), 0, 0, 0);
            > var then = new Date(this.getFullYear(), 0, 0, 0, 0, 0);
            1836c1836
            < return Math.floor(time / Date.DAY) + 1;

          • > return Math.floor(time / Date.DAY);

      A corresponding change is required in calendar-min.js.

      This probably affects every version of Jira that uses the calendar popup. However it only affects the day of year calculation, and should not be a problem for other date formats.

              tchin Timothy Chin [Atlassian]
              162f0e4fada7 Steve Roughton
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved: