Returns a description of the given duration in the most appropriate
    units (e.g. seconds, ms, us, or ns).
506515
def toStringDuration (duration):
    

    table = (
        ('%dms'      , 1e-3, 1e3),
        (u'%d\u03BCs', 1e-6, 1e6),
        ('%dns'      , 1e-9, 1e9)
    )

    if duration > 1:
        return '%fs' % duration

    for format, threshold, factor in table:
        if duration > threshold:
            return format % int(duration * factor)

    return '%fs' % duration
1125013
def _get_imr_duration(m1, m2, s1z, s2z, f_low, approximant="SEOBNRv4"):
    """"""
    m1, m2, s1z, s2z, f_low = float(m1), float(m2), float(s1z), float(s2z),\
                              float(f_low)
    if approximant == "SEOBNRv2":
        chi = lalsimulation.SimIMRPhenomBComputeChi(m1, m2, s1z, s2z)
        time_length = lalsimulation.SimIMRSEOBNRv2ChirpTimeSingleSpin(
                                m1 * lal.MSUN_SI, m2 * lal.MSUN_SI, chi, f_low)
    elif approximant == "IMRPhenomD":
        time_length = lalsimulation.SimIMRPhenomDChirpTime(
                           m1 * lal.MSUN_SI, m2 * lal.MSUN_SI, s1z, s2z, f_low)
    elif approximant == "SEOBNRv4":
        # NB for no clear reason this function has f_low as first argument
        time_length = lalsimulation.SimIMRSEOBNRv4ROMTimeOfFrequency(
                           f_low, m1 * lal.MSUN_SI, m2 * lal.MSUN_SI, s1z, s2z)
    else:
        raise RuntimeError("I can't calculate a duration for %s" % approximant)
    # FIXME Add an extra factor of 1.1 for 'safety' since the duration
    # functions are approximate
    return time_length * 1.1
169140
def ToDatetime(self):
    """"""
    return datetime.utcfromtimestamp(
        self.seconds + self.nanos / float(_NANOS_PER_SECOND))
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
  }
}
862547
private static String time2Str(long elapsedTime) {
    String unit;
    double time = elapsedTime;
    if (elapsedTime < 1000) {
      unit = "milliseconds";
    } else if (elapsedTime < 60*1000) {
      unit = "seconds";
      time = time/1000;
    } else if (elapsedTime < 3600*1000) {
      unit = "minutes";
      time = time/(60*1000);
    } else {
      unit = "hours";
      time = time/(3600*1000);
    }

    return time+" "+unit;
  }
63242
def formatDuration(self, duration):
        
        days = duration.days
        hours, remainder = divmod(duration.seconds, 3600)
        minutes, seconds = divmod(remainder, 60)
        if days:
            return '{} day{} {}h {}m {}s'.format(days, "s" if days > 1 else "",
                                                 hours, minutes, seconds)
        elif hours:
            return '{}h {}m {}s'.format(hours, minutes, seconds)
        return '{}m {}s'.format(minutes, seconds)
575357
def _duration(self):
        """"""
        duration = 0
        if self.state != STATE_IDLE:
            resp = self._player.query_duration(_FORMAT_TIME)
            duration = resp[1] // _NANOSEC_MULT
        return duration
175325
def duration(self):
        """"""

        if self.filetype not in ("video", "audio"):
            raise RuntimeError("Only videos and audio have durations")
        return self.info.get("length") or self.info.get("duration")
910
private Duration getDuration(TimeUnit units, Double duration)
   {
      Duration result = null;
      if (duration != null)
      {
         double durationValue = duration.doubleValue() * 100.0;

         switch (units)
         {
            case MINUTES:
            {
               durationValue *= MINUTES_PER_DAY;
               break;
            }

            case HOURS:
            {
               durationValue *= HOURS_PER_DAY;
               break;
            }

            case DAYS:
            {
               durationValue *= 3.0;
               break;
            }

            case WEEKS:
            {
               durationValue *= 0.6;
               break;
            }

            case MONTHS:
            {
               durationValue *= 0.15;
               break;
            }

            default:
            {
               throw new IllegalArgumentException("Unsupported time units " + units);
            }
         }

         durationValue = Math.round(durationValue) / 100.0;

         result = Duration.getInstance(durationValue, units);
      }

      return result;
   }
529520
def time_description(self):
        """"""

        tc = [t for t in self._p.time_coverage if t]

        if not tc:
            return ''

        mn = min(tc)
        mx = max(tc)

        if not mn and not mx:
            return ''
        elif mn == mx:
            return mn
        else:
            return "{} to {}".format(mn, mx)
693266
public static Duration of(String duration) {
    Matcher matcher = PATTERN.matcher(duration);
    Assert.arg(matcher.matches(), "Invalid duration: %s", duration);

    if (matcher.group(1) != null) {
      return Duration.ofSeconds(Long.MAX_VALUE);
    } else {
      String unit = matcher.group(4);
      String value = matcher.group(3);
      return Duration.ofNanos(TimeUnit.NANOSECONDS.convert(Long.parseLong(value),
          unit == null ? TimeUnit.MILLISECONDS : SUFFIXES.get(unit)));
    }
  }
997565
protected static function get_duration_text($seconds) {
        if (empty($seconds)) {
            return get_string('none');
        }
        $data = self::parse_seconds($seconds);
        switch ($data['u']) {
            case (60*60*24*7):
                return get_string('numweeks', '', $data['v']);
            case (60*60*24):
                return get_string('numdays', '', $data['v']);
            case (60*60):
                return get_string('numhours', '', $data['v']);
            case (60):
                return get_string('numminutes', '', $data['v']);
            default:
                return get_string('numseconds', '', $data['v']*$data['u']);
        }
    }
801444
def format_time_small(seconds):
    

    if not isinstance(seconds, (int, float)):
        return str(seconds)

    if math.isnan(seconds):
        return "-"

    if abs(seconds)<1:
        milliseconds = 1000*seconds
        if abs(milliseconds)<1:
            microseconds = 1000*milliseconds
            if abs(microseconds)<1:
                nanoseconds = 1000*microseconds
                if abs(nanoseconds)<0.5:
                    return "0"
                else:
                    return "{:.0f}ns".format(nanoseconds)
            elif abs(microseconds)<10:
                return "{:.2f}us".format(microseconds)
            elif abs(microseconds)<100:
                return "{:.1f}us".format(microseconds)
            else:
                return "{:.0f}us".format(microseconds)
        elif abs(milliseconds)<10:
            return "{:.2f}ms".format(milliseconds)
        elif abs(milliseconds)<100:
            return "{:.1f}ms".format(milliseconds)
        else:
            return "{:.0f}ms".format(milliseconds)
    elif abs(seconds)<10:
            return "{:.2f}s".format(seconds)
    elif abs(seconds)<100:
        return "{:.1f}s".format(seconds)
    else:
        return "{:.0f}s".format(seconds)
1343856
def time_to_text(time):
    """"""
    
    if time < 0.001:
        return str(round(time * 1000000)) + " µs"
    elif time < 1:
        return str(round(time * 1000)) + " ms"
    elif time < 60:
        return str(round(time, 1)) + " s"
    else:
        return str(round(time / 60, 1)) + " min"
929268
static public String convertStringFromDuration(
            Duration duration, DurationConverterSettings settings) {
        if ((duration == null) || (duration.isNegative())) {
            return "";
        }
        long seconds = duration.getSeconds();

        HashSet<DurationUnit> usedUnits
                = getUsedDurationUnitSet(settings.smallestUsedUnit, settings.largestUsedUnit);
        if (usedUnits.isEmpty()) {
            throw new RuntimeException("convertStringFromDuration(), The \"used duration unit\" "
                    + "variables do not allow any units to be used.");
        }
        boolean hasNoNanos = (duration.getNano() == 0);

        DurationUnit smallestUnit = settings.smallestUsedUnit;
        HashMap<DurationUnit, String> unitsSingular = settings.translationsUnitsSingular;
        HashMap<DurationUnit, String> unitsPlural = settings.translationsUnitsPlural;
        HashMap<DurationUnit, Boolean> pluralRules = settings.pluralUnitsMap;
        int oneYear = DurationUnit.Year.inSeconds;
        int oneMonth = DurationUnit.Month.inSeconds;
        int oneWeek = DurationUnit.Week.inSeconds;
        int oneDay = DurationUnit.Day.inSeconds;
        int oneHour = DurationUnit.Hour.inSeconds;
        int oneMinute = DurationUnit.Minute.inSeconds;
        int thirtyMinutes = DurationUnit.Second.thirtyMinutesInSeconds;

        String result = "";
        long value;
        boolean yearIsBestChoice = usedUnits.contains(DurationUnit.Year) && hasNoNanos
                && (seconds >= oneYear) && (seconds % oneYear == 0);
        if (yearIsBestChoice || (DurationUnit.Year == smallestUnit)) {
            value = seconds / oneYear;
            result += value + " ";
            result += ((pluralRules.get(DurationUnit.Year) && (value != 1))
                    ? unitsPlural.get(DurationUnit.Year) : unitsSingular.get(DurationUnit.Year));
            return result;
        }
        boolean monthIsBestChoice = usedUnits.contains(DurationUnit.Month) && hasNoNanos
                && (seconds >= oneMonth) && (seconds % oneMonth == 0);
        if (monthIsBestChoice || (DurationUnit.Month == smallestUnit)) {
            value = seconds / oneMonth;
            result += value + " ";
            result += ((pluralRules.get(DurationUnit.Month) && (value != 1))
                    ? unitsPlural.get(DurationUnit.Month) : unitsSingular.get(DurationUnit.Month));
            return result;
        }
        boolean weekIsBestChoice = usedUnits.contains(DurationUnit.Week) && hasNoNanos
                && (seconds >= oneWeek) && (seconds % oneWeek == 0);
        if (weekIsBestChoice || (DurationUnit.Week == smallestUnit)) {
            value = seconds / oneWeek;
            result += value + " ";
            result += ((pluralRules.get(DurationUnit.Week) && (value != 1))
                    ? unitsPlural.get(DurationUnit.Week) : unitsSingular.get(DurationUnit.Week));
            return result;
        }
        boolean dayIsBestChoice = usedUnits.contains(DurationUnit.Day) && hasNoNanos
                && (seconds >= oneDay) && (seconds % oneDay == 0);
        if (dayIsBestChoice || (DurationUnit.Day == smallestUnit)) {
            value = seconds / oneDay;
            result += value + " ";
            result += ((pluralRules.get(DurationUnit.Day) && (value != 1))
                    ? unitsPlural.get(DurationUnit.Day) : unitsSingular.get(DurationUnit.Day));
            return result;
        }

        boolean hourDecimalIsBestChoice = settings.hoursCanUseThirtyMinuteDecimals
                && usedUnits.contains(DurationUnit.Hour) && hasNoNanos
                && (seconds >= oneHour) && (seconds <= settings.hoursMaximumValueForDecimalsInSeconds)
                && (seconds % thirtyMinutes == 0) && (seconds % oneHour != 0);
        // Note, hourDecimal is never forced to be used as the "smallest used unit".
        if (hourDecimalIsBestChoice) {
            value = seconds / oneHour;
            // The full value is always "X.5" hour(s), due to the hourDecimalIsBestChoice criteria. 
            String decimalString = ".5";
            result += value + decimalString + " ";
            result += ((pluralRules.get(DurationUnit.Hour))
                    ? unitsPlural.get(DurationUnit.Hour) : unitsSingular.get(DurationUnit.Hour));
            return result;
        }

        boolean hourIntegerIsBestChoice = usedUnits.contains(DurationUnit.Hour) && hasNoNanos
                && (seconds >= oneHour) && (seconds % oneHour == 0);
        if (hourIntegerIsBestChoice || (DurationUnit.Hour == smallestUnit)) {
            value = seconds / oneHour;
            result += value + " ";
            result += ((pluralRules.get(DurationUnit.Hour) && (value != 1))
                    ? unitsPlural.get(DurationUnit.Hour) : unitsSingular.get(DurationUnit.Hour));
            return result;
        }

        boolean minuteIsBestChoice = usedUnits.contains(DurationUnit.Minute) && hasNoNanos
                && (seconds >= oneMinute) && (seconds % oneMinute == 0);
        if (minuteIsBestChoice || (DurationUnit.Minute == smallestUnit)) {
            value = seconds / oneMinute;
            result += value + " ";
            result += ((pluralRules.get(DurationUnit.Minute) && (value != 1))
                    ? unitsPlural.get(DurationUnit.Minute) : unitsSingular.get(DurationUnit.Minute));
            return result;
        }

        boolean secondIsBestChoice = usedUnits.contains(DurationUnit.Second);
        if (secondIsBestChoice || (DurationUnit.Second == smallestUnit)) {
            value = seconds;
            int nanosecondsFromDuration = duration.getNano();
            boolean includeNanoseconds = (nanosecondsFromDuration != 0);
            BigDecimal nanosecondsInSeconds = BigDecimal.valueOf(nanosecondsFromDuration, 9);
            BigDecimal secondsWithNanosAdded = nanosecondsInSeconds.add(new BigDecimal(value));
            secondsWithNanosAdded = secondsWithNanosAdded.stripTrailingZeros();
            result += ((includeNanoseconds) ? secondsWithNanosAdded.toPlainString() : value);
            result += " ";
            result += (pluralRules.get(DurationUnit.Second) && ((value != 1) || (includeNanoseconds)))
                    ? unitsPlural.get(DurationUnit.Second) : unitsSingular.get(DurationUnit.Second);
            return result;
        }
        throw new RuntimeException("convertStringFromDuration(), "
                + "The duration unit could not be chosen. (This should not happen.)");
    }
44040
def get_duration(self):
        
        mins, secs = divmod(self.duration_sec, 60)
        hours, mins = divmod(mins, 60)
        return "%02dh %02dm %02ds" % (hours, mins, secs)
221029
public static String toDuration(long time) {
        String duration = null;
        if (time >= 86400000) {
            duration = TimeUnit.MILLISECONDS.toMinutes(time) + " d";
        } else if (time >= 3600000) {
            duration = TimeUnit.MILLISECONDS.toMinutes(time) + " h";
        } else if (time >= 60000) {
            duration = TimeUnit.MILLISECONDS.toMinutes(time) + " min";
        } else if (time < 1000) {
            duration = time + " ms";
        } else {
            duration = TimeUnit.MILLISECONDS.toSeconds(time) + " s";
        }
        return duration;
    }