expression or duration is wrong), we simply return empty value
541683
@SuppressWarnings("squid:S1166")
    public static Optional<ZonedDateTime> getNextMaintenanceWindow(final String cronSchedule, final String duration,
            final String timezone) {
        try {
            final ExecutionTime scheduleExecutor = ExecutionTime.forCron(getCronFromExpression(cronSchedule));
            final ZonedDateTime now = ZonedDateTime.now(ZoneOffset.of(timezone));
            final ZonedDateTime after = now.minus(convertToISODuration(duration));
            final ZonedDateTime next = scheduleExecutor.nextExecution(after);
            return Optional.of(next);
        } catch (final RuntimeException ignored) {
            return Optional.empty();
        }
    }
1135786
def get_value(self, expression):
        """"""
        self._check_valid()
        return super(Result, self).get_value(expression)
244906
def duration(self):
        
        duration = 0.0
        if len(self.events) > 0:
            first = datetime.fromtimestamp(self.events[0]['timestamp'])
            last = datetime.fromtimestamp(self.events[-1]['timestamp'])
            duration = (last - first).total_seconds()
        return duration
939708
def _calculate_duration(start_time, finish_time):
    """"""
    if not (start_time and finish_time):
        return 0
    start = datetime.datetime.fromtimestamp(start_time)
    finish = datetime.datetime.fromtimestamp(finish_time)
    duration = finish - start

    decimals = float(("0." + str(duration.microseconds)))
    return duration.seconds + decimals
343609
def valueFromString(self, value, context=None):
        
        if value == 'now':
            return datetime.datetime.now().time()
        elif dateutil_parser:
            return dateutil_parser.parse(value).time()
        else:
            time_struct = time.strptime(value, self.defaultFormat())
            return datetime.time(time_struct.tm_hour,
                                 time_struct.tm_min,
                                 time_struct.tm_sec)
1206925
private void checkAndUpdate(DurationFieldType type, int[] values, int newValue) {
        int index = indexOf(type);
        if (index == -1) {
            if (newValue != 0) {
                throw new IllegalArgumentException(
                    "Period does not support field '" + type.getName() + "'");
            }
        } else {
            values[index] = newValue;
        }
    }
1062752
def valueFromString(self, value, context=None):
        
        if value in ('today', 'now'):
            return datetime.date.utcnow()

        try:
            return datetime.datetime.fromtimestamp(float(value))
        except StandardError:
            if dateutil_parser:
                return dateutil_parser.parse(value)
            else:
                return datetime.datetime.min()
1147791
def get_duration(timestr1, timestr2, units='s'):
    
    valid_units = ['s', 'min', 'h']
    assert units in valid_units,\
      "Units must be one of {!s}".format(valid_units)

    duration = (
        gt.timestr_to_seconds(timestr2) - gt.timestr_to_seconds(timestr1)
    )

    if units == 's':
        return duration
    elif units == 'min':
        return duration/60
    else:
        return duration/3600
1019441
function duration (time) {
  var number = parseFloat(time)
  switch (unit(time)) {
    case null:
    case 'ms': return number
    case 's': return number * 1000
    case 'm': return number * 60000
    case 'h': return number * 3600000
    case 'd': return number * 86400000
    case 'w': return number * 604800000
    default: return null
  }
}
298475
def format_duration(minutes, human = True):
    """"""

    if isinstance(minutes, dt.timedelta):
        minutes = duration_minutes(minutes)

    if not minutes:
        if human:
            return ""
        else:
            return "00:00"

    if minutes < 0:
        # format_duration did not work for negative values anyway
        # return a warning
        return "NEGATIVE"

    hours = minutes / 60
    minutes = minutes % 60
    formatted_duration = ""

    if human:
        if minutes % 60 == 0:
            # duration in round hours
            formatted_duration += ("%dh") % (hours)
        elif hours == 0:
            # duration less than hour
            formatted_duration += ("%dmin") % (minutes % 60.0)
        else:
            # x hours, y minutes
            formatted_duration += ("%dh %dmin") % (hours, minutes % 60)
    else:
        formatted_duration += "%02d:%02d" % (hours, minutes)


    return formatted_duration
57716
function(value) {
        switch (values.typeOf(value)) {
            case 'Null':
                return { type: 'NullLiteral' };

            case 'Boolean':
                return { type: 'BooleanLiteral', value: value };

            case 'Number':
                if (value !== value) {
                    return { type: 'NaNLiteral' };
                } else if (value === Infinity) {
                    return { type: 'InfinityLiteral', negative: false };
                } else if (value === -Infinity) {
                    return { type: 'InfinityLiteral', negative: true };
                } else {
                    return { type: 'NumberLiteral', value: value };
                }
                break;   // silence ESLint

            case 'String':
                return { type: 'StringLiteral', value: value };

            case 'RegExp':
                return {
                    type: 'RegExpLiteral',
                    pattern: value.source,
                    flags: value.toString().match(/\/(\w*)$/)[1]
                };

            case 'Date':
                return { type: 'MomentLiteral', value: value.valueOf() };

            case 'Duration':
                return { type: 'DurationLiteral', value: value.valueOf() };

            case 'Filter':
                return { type: 'FilterLiteral', ast: value.ast, source: value.source };

            case 'Array':
                return { type: 'ArrayLiteral', elements: _.map(value, values.toAST) };

            case 'Object':
                return {
                    type: 'ObjectLiteral',
                    properties: _.map(value, function(value, key) {
                        return {
                            type: 'ObjectProperty',
                            key: values.toAST(key),
                            value: values.toAST(value)
                        };
                    })
                };
        }
    }
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))
470602
function checkDuration(val, name) {
  if (typeof val !== "number") {
    warn(
      `<transition> explicit ${name} duration is not a valid number - ` +
        `got ${JSON.stringify(val)}.`
    );
  } else if (isNaN(val)) {
    warn(
      `<transition> explicit ${name} duration is NaN - ` +
        "the duration expression might be incorrect."
    );
  }
}
335019
def _parse(value, strict=True):
    
    pattern = r'(?:(?P<hours>\d+):)?(?P<minutes>\d+):(?P<seconds>\d+)'
    match = re.match(pattern, value)
    if not match:
        raise ValueError('Invalid duration value: %s' % value)
    hours = safe_int(match.group('hours'))
    minutes = safe_int(match.group('minutes'))
    seconds = safe_int(match.group('seconds'))

    check_tuple((hours, minutes, seconds,), strict)

    return (hours, minutes, seconds,)
535799
def open_timeout=(value)
      fail ArgumentError, "must be an integer or float" unless value && (value.is_a?(Integer) || value.is_a?(Float))
      @open_timeout = value
    end
742975
def value(self):
        
        try:
            if isinstance(self.__value, Expression):
                return self.__value.value
            return self.__value
        except AttributeError:
            return 0
884496
def _string2Duration(text):
    
    if text == "" or text == "zero":
        return ZERO

    amount, interval = re.match(r"([\d\.]*)(.*)", text).groups()
    amount = int(amount) if amount else 1

    if MILLI_VALUES[interval] == None:
        from mo_logs import Log
        Log.error(
            "{{interval|quote}} in {{text|quote}} is not a recognized duration type (did you use the pural form by mistake?",
            interval=interval,
            text=text
        )

    output = Duration(0)
    if MONTH_VALUES[interval] == 0:
        output.milli = amount * MILLI_VALUES[interval]
    else:
        output.milli = amount * MONTH_VALUES[interval] * MILLI_VALUES.month
        output.month = amount * MONTH_VALUES[interval]

    return output