Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-16949

AddTime change error example: AddTime("PT39M15S","PT39M15S")

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • 1.9
    • SCORM
    • None
    • MOODLE_19_STABLE

      in scorm_13.js.php

      AddTime("PT39M15S","PT39M15S") returns PT7H18M30S the correct value is PT1H18M30S.

      this is my correction:

      function AddTime (first, second) {
      var timestring = 'P';
      var matchexpr = /^P((\d+)Y)?((\d+)M)?((\d+)D)?(T((\d+)H)?((\d+)M)?((\d+(\.\d

      {1,2}

      )?)S)?)?$/;
      var firstarray = first.match(matchexpr);
      var secondarray = second.match(matchexpr);
      if ((firstarray != null) && (secondarray != null)) {

      var firstsecs=0;
      if(parseFloat(firstarray[13],10)>0)

      { firstsecs=parseFloat(firstarray[13],10); }

      var secondsecs=0;
      if(parseFloat(secondarray[13],10)>0)

      { secondsecs=parseFloat(secondarray[13],10); }

      var secs = firstsecs+secondsecs; //Seconds
      var change = Math.floor(secs/60);
      secs = Math.round((secs-(change*60))*100)/100;

      var firstmins=0;
      if(parseInt(firstarray[11],10)>0)

      { firstmins=parseInt(firstarray[11],10); }

      var secondmins=0;
      if(parseInt(secondarray[11],10)>0)

      { secondmins=parseInt(secondarray[11],10); }

      var mins = firstmins+secondmins+change; //Minutes
      change = Math.floor(mins / 60);
      mins = Math.round(mins-(change*60));

      var firsthours=0;
      if(parseInt(firstarray[9],10)>0)

      { firsthours=parseInt(firstarray[9],10); }

      var secondhours=0;
      if(parseInt(secondarray[9],10)>0)

      { secondhours=parseInt(secondarray[9],10); }

      var hours = firsthours+secondhours+change; //Hours

      change = Math.floor(hours/24);
      hours = Math.round(hours-(change*24));

      var firstdays=0;
      if(parseInt(firstarray[6],10)>0)

      { firstdays=parseInt(firstarray[6],10); }

      var seconddays=0;
      if(parseInt(secondarray[6],10)>0)

      { firstdays=parseInt(secondarray[6],10); }

      var days = Math.round(firstdays+seconddays+change); // Days

      var firstmonths=0;
      if(parseInt(firstarray[4],10)>0)

      { firstmonths=parseInt(firstarray[4],10); }

      var secondmonths=0;
      if(parseInt(secondarray[4],10)>0)

      { secondmonths=parseInt(secondarray[4],10); }

      var months = Math.round(firstmonths+secondmonths);

      var firstyears=0;
      if(parseInt(firstarray[2],10)>0)

      { firstyears=parseInt(firstarray[2],10); }

      var secondyears=0;
      if(parseInt(secondarray[2],10)>0)

      { secondyears=parseInt(secondarray[2],10); }

      var years = Math.round(firstyears+secondyears);
      }
      if (years > 0)

      { timestring += years + 'Y'; }

      if (months > 0)

      { timestring += months + 'M'; }

      if (days > 0)

      { timestring += days + 'D'; }

      if ((hours > 0) || (mins > 0) || (secs > 0)) {
      timestring += 'T';
      if (hours > 0)

      { timestring += hours + 'H'; }

      if (mins > 0)

      { timestring += mins + 'M'; }

      if (secs > 0)

      { timestring += secs + 'S'; }

      }
      return timestring;
      }

            piers Piers Harding
            xabim Xabi Martín
            Nobody Nobody
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.