Moodle
  1. Moodle
  2. MDL-16949

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

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.9
    • Fix Version/s: None
    • Component/s: SCORM
    • Labels:
      None
    • Affected Branches:
      MOODLE_19_STABLE
    • Rank:
      12733

      Description

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

        Activity

        Hide
        Dan Marsden added a comment -

        Hi There,

        thanks for the info - could you please provide attach a patch to this tracker item instead of the text of the full function? - it's hard to see what your changes are.

        for information on creating a patch see:
        http://docs.moodle.org/en/Development:How_to_create_a_patch

        Show
        Dan Marsden added a comment - Hi There, thanks for the info - could you please provide attach a patch to this tracker item instead of the text of the full function? - it's hard to see what your changes are. for information on creating a patch see: http://docs.moodle.org/en/Development:How_to_create_a_patch
        Hide
        Xabi Martín added a comment -

        patch.

        the problem is:

        when cahnge has value and sums width no vanue (NaN).

        Sory for my bad english.

        Show
        Xabi Martín added a comment - patch. the problem is: when cahnge has value and sums width no vanue (NaN). Sory for my bad english.
        Hide
        Piers Harding added a comment -

        Have applied this patch (thanks Xabi), and tested in HEAD. Will apply to 1.9, and 1.8 also, when "testing Tuesday" is done.

        Show
        Piers Harding added a comment - Have applied this patch (thanks Xabi), and tested in HEAD. Will apply to 1.9, and 1.8 also, when "testing Tuesday" is done.
        Hide
        Piers Harding added a comment -

        This has now been backported to 1.9, and 1.8 - thanks.

        Show
        Piers Harding added a comment - This has now been backported to 1.9, and 1.8 - thanks.
        Hide
        Piers Harding added a comment -

        tested - only applies to scorm 2004

        Show
        Piers Harding added a comment - tested - only applies to scorm 2004

          People

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

            Dates

            • Created:
              Updated:
              Resolved: