Format seconds in a more human readable way. It supports units down to
    nanoseconds.

    :param s: Float of seconds to format
    :return: String second representation, like 12.4 us
181281
def format_sec(s):
    

    prefixes = ["", "m", "u", "n"]
    unit = 0

    while s < 1 and unit + 1 < len(prefixes):
        s *= 1000
        unit += 1

    return "{:.1f} {}s".format(s, prefixes[unit])
369491
function secondsToTime(secs) {
  var days = Math.floor(secs / (60 * 60 * 24))
    , divisor_for_hours = secs % (60 * 60 * 24)
    , hours = Math.floor(divisor_for_hours / (60 * 60))
    , divisor_for_minutes = secs % (60 * 60)
    , minutes = Math.floor(divisor_for_minutes / 60)
    , divisor_for_seconds = divisor_for_minutes % 60
    , seconds = Math.ceil(divisor_for_seconds);
  return {"d": days, "h": hours, "m": minutes, "s": seconds};
}
582818
function( time ) {
		var h, m, s;

		if ( time > TIME_MINUTE ) {
			m = parseInt( time / TIME_MINUTE, 10 );
			s = ( time % TIME_MINUTE ) / TIME_SECOND;
			return m + 'mins, ' + s + 's';
		}
		else if ( time > TIME_SECOND ) {
			return ( time / TIME_SECOND ) + 's';
		}
		else {
			return time + 'ms';
		}
	}
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"
1342838
def seconds_to_hms_verbose(t):
    
    hours = int((t / 3600))
    mins = int((t / 60) % 60)
    secs = int(t % 60)
    return ' '.join([
        (hours + ' hour' + ('s' if hours > 1 else '')) if hours > 0 else '',
        (mins + ' minute' + ('s' if mins > 1 else '')) if mins > 0 else '',
        (secs + ' second' + ('s' if secs > 1 else '')) if secs > 0 else ''
    ])
430375
def _to_seconds(timestr):
    '''
    
    '''
    timestr = timestr.upper()
    if 'H' in timestr:
        seconds = int(timestr.replace('H', '')) * 3600
    elif 'D' in timestr:
        seconds = int(timestr.replace('D', '')) * 86400
    elif 'W' in timestr:
        seconds = 604800
    else:
        try:
            seconds = int(timestr)
        except ValueError:
            seconds = 604800
    if seconds > 604800:
        seconds = 604800
    return seconds
226419
def format_time( sec ):
    ''' 
    '''
    import time
    if sec < 864000:
       # Idea from:   http://stackoverflow.com/a/1384565
       return time.strftime('%H:%M:%S', time.gmtime(sec))
    else:
       days = int(sec / 864000)
       secs = sec % 864000
       return str(days)+'d, '+time.strftime('%H:%M:%S', time.gmtime(secs))
457365
def get_readable_time_string(seconds):
    """"""
    seconds = int(seconds)
    minutes = seconds // 60
    seconds = seconds % 60
    hours = minutes // 60
    minutes = minutes % 60
    days = hours // 24
    hours = hours % 24

    result = ""
    if days > 0:
        result += "%d %s " % (days, "Day" if (days == 1) else "Days")
    if hours > 0:
        result += "%d %s " % (hours, "Hour" if (hours == 1) else "Hours")
    if minutes > 0:
        result += "%d %s " % (minutes, "Minute" if (minutes == 1) else "Minutes")
    if seconds > 0:
        result += "%d %s " % (seconds, "Second" if (seconds == 1) else "Seconds")

    return result.strip()
392156
def format_time_large(seconds):
    

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

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

    seconds = int(round(seconds))
    if abs(seconds)<60:
        return "{:d}".format(seconds)
    else:
        minutes = int(seconds/60)
        seconds %= 60
        if abs(minutes)<60:
            return "{:d}:{:02d}".format(minutes,seconds)
        else:
            hours = int(minutes/60)
            minutes %= 60
            if abs(hours)<24:
                return "{:d}:{:02d}:{:02d}".format(hours,minutes,seconds)
            else:
                days = int(hours/24)
                hours %= 24
                return "{:d}:{:02d}:{:02d}:{:02d}".format(
                    days,hours,minutes,seconds)
1203858
def human_duration(duration_seconds: float) -> str:
    """"""
    if duration_seconds < 0.001:
        return '0 ms'
    if duration_seconds < 1:
        return '{} ms'.format(int(duration_seconds * 1000))
    return '{} s'.format(int(duration_seconds))
307112
def CopyToDateTimeString(self):
    
    if self._number_of_seconds is None:
      return None

    return '{0:04d}-{1:02d}-{2:02d} {3:02d}:{4:02d}:{5:02d}'.format(
        self._time_elements_tuple[0], self._time_elements_tuple[1],
        self._time_elements_tuple[2], self._time_elements_tuple[3],
        self._time_elements_tuple[4], self._time_elements_tuple[5])
924760
public function formatsSeconds($seconds)
    {
        $h = ($seconds >= 3600) ? (int) round($seconds / 3600) : 0;
        $time = ($seconds >= 3600) ? $seconds % 3600 : $seconds;
        $m = (int) $time / 60;
        $s = (int) $time % 60;

        return (int) $h.':'.(int) $m.':'.(int) $s;
    }
810364
def to_short_time_string(self) -> str:
        
        hour = self.time.hour
        minute = self.time.minute
        return f"{hour:02}:{minute:02}"
887430
def get_seconds(self):
        
        parsed = self.parse_hh_mm_ss()  # get times
        total_seconds = parsed.second
        total_seconds += parsed.minute * 60.0
        total_seconds += parsed.hour * 60.0 * 60.0
        return total_seconds
1306179
def get_seconds(value, scale):
  
  scales = {
    'seconds': lambda x: x,
    'minutes': lambda x: x * 60,
    'hours': lambda x: x * 60 * 60,
    'days': lambda x: x * 60 * 60 * 24,
    'weeks': lambda x: x * 60 * 60 * 24 * 7,
    'months': lambda x: x * 60 * 60 * 24 * 30,
    'years': lambda x: x * 60 * 60 * 24 * 365,
  }
  return scales[scale](value)
431047
def time2string(tstamp, micro=True):
    """"""
    tformat = TIME_FORMAT if micro else TIME_FORMAT[:-len(MICRO)]
    return tstamp.strftime(tformat)
951290
def parse_timespan_value(s):
    
    number, unit = split_number_and_unit(s)
    if not unit or unit == "s":
        return number
    elif unit == "min":
        return number * 60
    elif unit == "h":
        return number * 60 * 60
    elif unit == "d":
        return number * 24 * 60 * 60
    else:
        raise ValueError('unknown unit: {} (allowed are s, min, h, and d)'.format(unit))