Uploaded image for project: 'PUBLIC - Liferay Alloy UI'
  1. PUBLIC - Liferay Alloy UI
  2. AUI-884

Scheduler/DateMath do not respect Daylight saving time

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Incomplete
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: DataType, Scheduler
    • Labels:
      None

      Description

      You can easily see the issue between March 30th and March 31st 2013, in the Month View with FIRST_DAY_OF_WEEK set to 6 (Saturday).

      The month will show the following calendar:

      ------------------------
      - Sa Su Mo Tu We Th Fr -
      ------------------------
      - 30 31 01 02 03 04 05 -
      - 06 07 08 09 10 11 12 -
                ....
      

      Record a new event from March 30th to April 2nd and save it. The rendered event will span 30th-31st-01st but NOT 02nd. That's because between 30th and 31st of March Day light changed and from +100 (here in Italy) it moved to +200. That means that an hour was lost.

      Every range math with a date before the change and a date after it will yield unexpected results. Eg:

      // In Italy
      var d1 = new Date(2013, 2, 30, 12,0,0,0); // Sat Mar 30 2013 12:00:00 GMT+0100 (CET)
      var d2 = new Date(2013, 2, 31, 12,0,0,0); // Sun Mar 31 2013 12:00:00 GMT+0200 (CEST)
      
      console.log(DateMath.getDayOffset(x1, x2)); // 0          <--- Oops
      console.log((x2 - x1) / (24*60*60*1000));   // 0.95833... <--- Argh!
      console.log((x2 - x1) / (60*60*1000));      // 23         <--- :(
      

      I found a solution using a different implementation of DateMath.clearDate as follows:

      DateMath.clearUTCDate = function (date) {
        date.setUTCHours(12, 0, 0, 0);
        return date;
      };
      
      DateMath.safeClearUTCDate = function (date) {
        return this.clearUTCDate(this.clone(date));
      };
      

      And I had to use it on getClearStartDate/getClearEndDate of SchedulerEvent and on _findCurrentIntervalEnd of SchedulerTableView. That really clears the date from Time information.

      PS: I also tried to overwrite the original DateMath.clearDate with the UTC version, but that broke a lot of things, so I believe the Scheduler's code is doing too many assumptions.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                5 years, 24 weeks, 1 day ago

                Packages

                Version Package