converts duration value to integer seconds

    strict=True (by default) raises StrictnessError if either hours,
    minutes or seconds in duration value exceed allowed values
767883
def to_seconds(value, strict=True, force_int=True):
    
    if isinstance(value, int):
        return value  # assuming it's seconds
    elif isinstance(value, timedelta):
        seconds = value.total_seconds()
        if force_int:
            seconds = int(round(seconds))
        return seconds
    elif isinstance(value, str):
        hours, minutes, seconds = _parse(value, strict)
    elif isinstance(value, tuple):
        check_tuple(value, strict)
        hours, minutes, seconds = value
    else:
        raise TypeError(
            'Value %s (type %s) not supported' % (
                value, type(value).__name__
            )
        )

    if not (hours or minutes or seconds):
        raise ValueError('No hours, minutes or seconds found')

    result = hours*3600 + minutes*60 + seconds
    return result
1133334
def duration(self, value):
        
        if value == self._defaults['duration'] and 'duration' in self._values:
            del self._values['duration']
        else:
            self._values['duration'] = value
21197
def parse_seconds(value):
        '''
        
        '''
        svalue = str(value)
        colons = svalue.count(':')
        if colons == 2:
            hours, minutes, seconds = [int(v) for v in svalue.split(':')]
        elif colons == 1:
            hours, minutes = [int(v) for v in svalue.split(':')]
            seconds = 0
        elif colons == 0:
            hours = 0
            minutes = 0
            seconds = int(svalue)
        else:
            raise ValueError('Must be in seconds or HH:MM:SS format')
        return Seconds.from_hms(hours, minutes, seconds)
1154196
def timedelta_to_duration(obj):
    
    minutes, hours, days = 0, 0, 0
    seconds = int(obj.total_seconds())
    if seconds > 59:
        minutes = seconds // 60
        seconds = seconds % 60
    if minutes > 59:
        hours = minutes // 60
        minutes = minutes % 60
    if hours > 23:
        days = hours // 24
        hours = hours % 24
    response = []
    if days:
        response.append('%sd' % days)
    if hours:
        response.append('%sh' % hours)
    if minutes:
        response.append('%sm' % minutes)
    if seconds or not response:
        response.append('%ss' % seconds)
    return "".join(response)
552858
def seconds_to_time(seconds):
    
    minutes, seconds = divmod(int(seconds), 60)
    hours, m = divmod(minutes, 60)
    if hours:
        return _HOURS_OF_ELAPSED % (hours, m, seconds)
    else:
        return _MINUTES_OF_ELAPSED % (m, seconds)
242389
function parseDuration(durationString) {
  if (durationString === null || typeof durationString === 'undefined') {
    return -1;
  }
  // Some VAST doesn't have an HH:MM:SS duration format but instead jus the number of seconds
  if (util.isNumeric(durationString)) {
    return parseInt(durationString);
  }

  const durationComponents = durationString.split(':');
  if (durationComponents.length !== 3) {
    return -1;
  }

  const secondsAndMS = durationComponents[2].split('.');
  let seconds = parseInt(secondsAndMS[0]);
  if (secondsAndMS.length === 2) {
    seconds += parseFloat(`0.${secondsAndMS[1]}`);
  }

  const minutes = parseInt(durationComponents[1] * 60);
  const hours = parseInt(durationComponents[0] * 60 * 60);

  if (
    isNaN(hours) ||
    isNaN(minutes) ||
    isNaN(seconds) ||
    minutes > 60 * 60 ||
    seconds > 60
  ) {
    return -1;
  }
  return hours + minutes + seconds;
}
666589
def get_prep_value(self, value):
        ''''''
        if isinstance(value, Seconds):
            return value.seconds
        elif value:
            return self.parse_seconds(value).seconds
        else:
            return None
743728
function(mod) {
			var seconds = this.time;
			
			if(mod) {
				if(seconds == 60) {
					seconds = 0;
				}
				else {
					seconds = seconds % 60;
				}
			}
			
			return Math.ceil(seconds);
		}
150441
def calculated_intervals(self, value):
        
        if not value:
            self._calculated_intervals = TimeIntervals()
            return

        if isinstance(value, TimeInterval):
            value = TimeIntervals([value])
        elif isinstance(value, TimeIntervals):
            pass
        elif isinstance(value, list):
            value = TimeIntervals(value)
        else:
            raise TypeError("Expected list/TimeInterval/TimeIntervals, got {}".format(type(value)))

        for interval in value:
            if interval.end > utcnow():
                raise ValueError("Calculated intervals should not be in the future")

        self._calculated_intervals = value
119775
def validate_timeout_or_zero(option, value):
    
    if value is None:
        raise ConfigurationError("%s cannot be None" % (option, ))
    if value == 0 or value == "0":
        return 0
    return validate_positive_float(option, value) / 1000.0
1325347
private long parseDuration(String value) {
	        long periodMS = 0L;
	        if (value!=null) {
	            String[] parts = value.split(":");
	            for (int i = 0; i < parts.length; i++) {
	                switch (i) {
	                    case 0: // hours
	                        periodMS += (Integer.parseInt(parts[i])) * 3600000L;
	                        break;
	                    case 1: // minutes
	                        periodMS += (Integer.parseInt(parts[i])) * 60000L;
	                        break;
	                    case 2: // seconds
	                        periodMS += (Integer.parseInt(parts[i])) * 1000L;
	                        break;
	                    case 3: // ms
	                        periodMS += (Integer.parseInt(parts[i]));
	                        break;
	                    default:
	                        break;
	                }
	            }
	        }
	        return periodMS;
	    }
276795
def timedelta_total_minutes(td, strict=False):
    
    minutes, seconds = divmod(td.days * 24 * 3600 + td.seconds, 60)
    if seconds or td.microseconds:
        if strict:
            raise ValueError(
                "%r is not an integral multiple of 60 seconds", td)
        if seconds > 30 or (seconds == 30 and td.microseconds > 0):
            minutes += 1
    return minutes
1093862
def parse_duration(duration):
    
    duration_dict = re.search(DURATION_REGEX, duration).groupdict()
    converted_dict = {}
    # convert all values to ints, remove nones
    for a, x in duration_dict.iteritems():
        if x is not None:
            converted_dict[a] = int(NON_DECIMAL.sub('', x))
    return str(timedelta(**converted_dict))
76718
def _parse_limit(self, element):
        
        # Is this a Global or User limit?
        limit_type = attribute(element, 'type', 'user')

        # Time unit conversions
        unit_conversions = {
            'seconds': 1,
            'minutes': 60,
            'hours':   3600,
            'days':    86400,
            'weeks':   604800,
            'months':  2592000,
            'years':   31536000
        }
        units = attribute(element, 'unit', 'seconds')
        if units not in unit_conversions:
            self._log.warn('Unrecognized time unit: {unit}'.format(unit=units))
            return

        try:
            limit = float(element.text)
        except (ValueError, TypeError):
            self._log.warn('Limit must contain a valid integer or float (Invalid limit: "{limit}")'
                           .format(limit=element.text))
            return

        if limit_type == 'global':
            self.global_limit = limit * unit_conversions[units]
            self.glimit_blocking = bool_attribute(element, 'blocking', self.glimit_blocking)
        elif limit_type == 'user':
            self.user_limit = limit * unit_conversions[units]
            self.ulimit_blocking = bool_attribute(element, 'blocking', self.ulimit_blocking)

        return
1080586
def jsonify_timedelta(value):
    

    assert isinstance(value, datetime.timedelta)

    # split seconds to larger units
    seconds = value.total_seconds()
    minutes, seconds = divmod(seconds, 60)
    hours, minutes = divmod(minutes, 60)
    days, hours = divmod(hours, 24)

    days, hours, minutes = map(int, (days, hours, minutes))
    seconds = round(seconds, 6)

    # build date
    date = ''
    if days:
        date = '%sD' % days

    # build time
    time = u'T'

    # hours
    bigger_exists = date or hours
    if bigger_exists:
        time += '{:02}H'.format(hours)

    # minutes
    bigger_exists = bigger_exists or minutes
    if bigger_exists:
        time += '{:02}M'.format(minutes)

    # seconds
    if seconds.is_integer():
        seconds = '{:02}'.format(int(seconds))
    else:
        # 9 chars long w/leading 0, 6 digits after decimal
        seconds = '%09.6f' % seconds
        # remove trailing zeros
        seconds = seconds.rstrip('0')

    time += '{}S'.format(seconds)

    return u'P' + date + time
47711
def apply_limit(kind, seconds = nil)
      @apply_limit ||= {}
      if seconds
        @apply_limit[kind.to_sym] = seconds.to_i
      end
      @apply_limit[kind.to_sym].to_i
    end
1038321
def parse_duration(value):
    
    if isinstance(value, (int, float)):
        return value
    elif not pattern_valid.fullmatch(value):
        raise ValueError(value)

    result = 0
    for m in pattern.finditer(value):
        v = m.groupdict()
        n = int(v['n'])
        unit = v['unit']
        if not unit:
            result += n
        elif unit in durations:
            result += n * durations[unit]
        else:
            raise ValueError(value)
    return result