function getDuration(startDate, endDate) {
  
  if(!(startDate instanceof Simple && endDate instanceof Simple)){
    throw new Error('Start and end dates must be simple dates');
  }
  
  var start = getObjFromDate(startDate, true),
      end = getObjFromDate(endDate, true),
      hasTime = false,
      duration = '';

  zipDates(start, end);

  if(end.seconds != undefined) {
    while(end.seconds-start.seconds < 0) {
      end.minutes -= 1;
      end.seconds += 60;
    }
    if(end.seconds-start.seconds > 0) {
      hasTime = true;
      duration = ('00'+(end.seconds-start.seconds)).substr(-2,2)+'S'+duration;
    }
  }

  if(end.minutes != undefined) {
    while(end.minutes-start.minutes < 0) {
      end.hours -= 1;
      end.minutes += 60;
    }
    if(end.minutes-start.minutes > 0) {
      hasTime = true;
      duration = ('00'+(end.minutes-start.minutes)).substr(-2,2)+'M'+duration;
    }
  }

  if(end.hours != undefined) {
    while(end.hours-start.hours < 0) {
      end.day -= 1;
      end.hours += 24;
    }
    if(end.hours-start.hours > 0) {
      hasTime = true;
      duration = ('00'+(end.hours-start.hours)).substr(-2,2)+'H'+duration;
    }
  }

  if(hasTime) {
    duration = 'T'+duration;
  }

  if(end.day != undefined) {
    while(end.day-start.day < 0) {
      end.day += GlobalUtil.daysInMonth(end.month,end.year);
      end.month -= 1;
      if(end.month < 1) {
        end.year -= 1;
        end.month += 12;
      }
    }
    if(end.day-start.day > 0) {
      duration = ('00'+(end.day-start.day)).substr(-2,2)+'D'+duration;
    }
  }

  if(end.month != undefined) {
    while(end.month-start.month < 0) {
      end.year -= 1;
      end.month += 12;
    }
    if(end.month-start.month > 0) {
      duration = ('00'+(end.month-start.month)).substr(-2,2)+'M'+duration;
    }
  }

  if(end.year-start.year > 0) {
    duration = ('0000'+(end.year-start.year)).substr(-4,4)+'Y'+duration;
  }

  if(end.year-start.year < 0 || duration == '') {
    throw new Error('Start Date must be less than End Date');
  }

  return new Duration('P'+duration);
}
function getDuration(startDate, endDate) {
  
  if(!(startDate instanceof Simple && endDate instanceof Simple)){
    throw new Error('Start and end dates must be simple dates');
  }
  
  var start = getObjFromDate(startDate, true),
      end = getObjFromDate(endDate, true),
      hasTime = false,
      duration = '';

  zipDates(start, end);

  if(end.seconds != undefined) {
    while(end.seconds-start.seconds < 0) {
      end.minutes -= 1;
      end.seconds += 60;
    }
    if(end.seconds-start.seconds > 0) {
      hasTime = true;
      duration = ('00'+(end.seconds-start.seconds)).substr(-2,2)+'S'+duration;
    }
  }

  if(end.minutes != undefined) {
    while(end.minutes-start.minutes < 0) {
      end.hours -= 1;
      end.minutes += 60;
    }
    if(end.minutes-start.minutes > 0) {
      hasTime = true;
      duration = ('00'+(end.minutes-start.minutes)).substr(-2,2)+'M'+duration;
    }
  }

  if(end.hours != undefined) {
    while(end.hours-start.hours < 0) {
      end.day -= 1;
      end.hours += 24;
    }
    if(end.hours-start.hours > 0) {
      hasTime = true;
      duration = ('00'+(end.hours-start.hours)).substr(-2,2)+'H'+duration;
    }
  }

  if(hasTime) {
    duration = 'T'+duration;
  }

  if(end.day != undefined) {
    while(end.day-start.day < 0) {
      end.day += GlobalUtil.daysInMonth(end.month,end.year);
      end.month -= 1;
      if(end.month < 1) {
        end.year -= 1;
        end.month += 12;
      }
    }
    if(end.day-start.day > 0) {
      duration = ('00'+(end.day-start.day)).substr(-2,2)+'D'+duration;
    }
  }

  if(end.month != undefined) {
    while(end.month-start.month < 0) {
      end.year -= 1;
      end.month += 12;
    }
    if(end.month-start.month > 0) {
      duration = ('00'+(end.month-start.month)).substr(-2,2)+'M'+duration;
    }
  }

  if(end.year-start.year > 0) {
    duration = ('0000'+(end.year-start.year)).substr(-4,4)+'Y'+duration;
  }

  if(end.year-start.year < 0 || duration == '') {
    throw new Error('Start Date must be less than End Date');
  }

  return new Duration('P'+duration);
}
function getDuration ( startDate , endDate ) { if ( ! ( startDate instanceof Simple && endDate instanceof Simple ) ) { throw new Error ( 'Start and end dates must be simple dates' ) ; } var start = getObjFromDate ( startDate , true ) , end = getObjFromDate ( endDate , true ) , hasTime = false , duration = '' ; zipDates ( start , end ) ; if ( end . seconds != undefined ) { while ( end . seconds - start . seconds < 0 ) { end . minutes -= 1 ; end . seconds += 60 ; } if ( end . seconds - start . seconds > 0 ) { hasTime = true ; duration = ( '00' + ( end . seconds - start . seconds ) ) . substr ( - 2 , 2 ) + 'S' + duration ; } } if ( end . minutes != undefined ) { while ( end . minutes - start . minutes < 0 ) { end . hours -= 1 ; end . minutes += 60 ; } if ( end . minutes - start . minutes > 0 ) { hasTime = true ; duration = ( '00' + ( end . minutes - start . minutes ) ) . substr ( - 2 , 2 ) + 'M' + duration ; } } if ( end . hours != undefined ) { while ( end . hours - start . hours < 0 ) { end . day -= 1 ; end . hours += 24 ; } if ( end . hours - start . hours > 0 ) { hasTime = true ; duration = ( '00' + ( end . hours - start . hours ) ) . substr ( - 2 , 2 ) + 'H' + duration ; } } if ( hasTime ) { duration = 'T' + duration ; } if ( end . day != undefined ) { while ( end . day - start . day < 0 ) { end . day += GlobalUtil . daysInMonth ( end . month , end . year ) ; end . month -= 1 ; if ( end . month < 1 ) { end . year -= 1 ; end . month += 12 ; } } if ( end . day - start . day > 0 ) { duration = ( '00' + ( end . day - start . day ) ) . substr ( - 2 , 2 ) + 'D' + duration ; } } if ( end . month != undefined ) { while ( end . month - start . month < 0 ) { end . year -= 1 ; end . month += 12 ; } if ( end . month - start . month > 0 ) { duration = ( '00' + ( end . month - start . month ) ) . substr ( - 2 , 2 ) + 'M' + duration ; } } if ( end . year - start . year > 0 ) { duration = ( '0000' + ( end . year - start . year ) ) . substr ( - 4 , 4 ) + 'Y' + duration ; } if ( end . year - start . year < 0 || duration == '' ) { throw new Error ( 'Start Date must be less than End Date' ) ; } return new Duration ( 'P' + duration ) ; }
Returns the duration between the starting and ending date.
Returns the duration between the starting and ending date .