Given t seconds, report back the correct format as string.
191168
def reportTime(t, options, field=None):
    
    if options.pretty:
        return prettyTime(t, field=field)
    else:
        if field is not None:
            return "%*.2f" % (field, t)
        else:
            return "%.2f" % t
1234423
def format_seconds(seconds, hide_seconds=False):
    
    if seconds <= 60:
        return str(seconds)
    output = ""
    for period, period_seconds in (
        ('y', 31557600),
        ('d', 86400),
        ('h', 3600),
        ('m', 60),
        ('s', 1),
    ):
        if seconds >= period_seconds and not (hide_seconds and period == 's'):
            output += str(int(seconds / period_seconds))
            output += period
            output += " "
            seconds = seconds % period_seconds
    return output.strip()
758018
def strftime(self, format):
        

        output = self._format(format)
        if py2:
            return output.encode('utf-8')
        return output
666243
def format_timedelta(t, timedelta_format=None):
    """"""
    timedelta_str = str(pd.Timedelta(t))
    try:
        days_str, time_str = timedelta_str.split(' days ')
    except ValueError:
        # catch NaT and others that don't split nicely
        return timedelta_str
    else:
        if timedelta_format == 'date':
            return days_str + ' days'
        elif timedelta_format == 'time':
            return time_str
        else:
            return timedelta_str
1248713
def timeFormat(time_from, time_to=None, prefix="", infix=None):
    
    retval = ""
    if time_from != "" and time_from is not None:
        retval += prefix
        retval += dateformat.time_format(time_from, "fA").lower()
    if time_to != "" and time_to is not None:
        to = format(dateformat.time_format(time_to, "fA").lower())
        if infix is not None:
            retval = "{} {} {}".format(retval, infix, to)
        else:
            retval = _("{fromTime} to {toTime}").format(fromTime=retval,
                                                        toTime=to)
    return retval.strip()
918826
def fmttime(tin):
    
    aaa, bbb = '{:.2e}'.format(tin).split('e')
    bbb = int(bbb)
    return r'$t={} \times 10^{{{}}}$'.format(aaa, bbb)
693484
def _StrftimeGm(value, unused_context, args):
    
    time_tuple = time.gmtime(value)
    return _StrftimeHelper(args, time_tuple)
734059
def time_to_seconds(x):
    """"""
    if isinstance(x, time):
        return ((((x.hour * 60) + x.minute) * 60 + x.second) * 10**6 +
                x.microsecond) / 10**6

    if is_str(x):
        return x
    # Clamp to valid time
    return x and max(0, min(x, 24 * 3600 - 10**-6))
706410
def write_checktime (self, url_data):
        """"""
        self.writeln(u"<tr><td>"+self.part("checktime")+u"</td><td>"+
                     (_("%.3f seconds") % url_data.checktime)+u"</td></tr>")
290543
def strtime(at=None, fmt=PERFECT_TIME_FORMAT):
    """"""
    if not at:
        at = utcnow()
    return at.strftime(fmt)
719104
def check_date_str_format(s, default_time="00:00:00"):
    """"""
    try:
        str_fmt = s
        if ":" not in s:
            str_fmt = '{} {}'.format(s, default_time)

        dt_obj = datetime.strptime(str_fmt, "%Y-%m-%d %H:%M:%S")

        return RET_OK, dt_obj

    except ValueError:
        error_str = ERROR_STR_PREFIX + "wrong time or time format"
        return RET_ERROR, error_str
1359391
def timedelta2period(duration):
    """"""
    seconds = duration.seconds
    minutes = (seconds % 3600) // 60
    seconds = (seconds % 60)
    return '{0:0>2}:{1:0>2}'.format(minutes, seconds)
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)
661701
def _timestamp():
    """"""
    moment = time.time()
    moment_us = repr(moment).split('.')[1]
    return time.strftime("%Y-%m-%d-%H-%M-%S-{}".format(moment_us), time.gmtime(moment))
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)
1277705
def rnow(
        format='%Y-%m-%d %H:%M:%S',
        in_utc=False):
    

    if in_utc:
        return datetime.datetime.utcnow().strftime(
            format)
    else:
        return datetime.datetime.now().strftime(
            format)
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