Converts microseconds to Duration.
2818
def FromMicroseconds(self, micros):
    """"""
    self._NormalizeDuration(
        micros // _MICROS_PER_SECOND,
        (micros % _MICROS_PER_SECOND) * _NANOS_PER_MICROSECOND)
1342478
function toSeconds() {
      var seconds = this.seconds + 60 * this.minutes + 3600 * this.hours +
                    86400 * this.days + 7 * 86400 * this.weeks;
      return (this.isNegative ? -seconds : seconds);
    }
1344236
def from_str(duration):
    """"""

    if duration in ("0", "+0", "-0"):
        return datetime.timedelta()

    pattern = re.compile('([\d\.]+)([a-zµμ]+)')
    total = 0
    sign = -1 if duration[0] == '-' else 1
    matches = pattern.findall(duration)

    if not len(matches):
        raise Exception("Invalid duration {}".format(duration))

    for (value, unit) in matches:
        if unit not in units:
            raise Exception(
                "Unknown unit {} in duration {}".format(unit, duration))
        try:
            total += float(value) * units[unit]
        except:
            raise Exception(
                "Invalid value {} in duration {}".format(value, duration))

    microseconds = total / _microsecond_size
    return datetime.timedelta(microseconds=sign * microseconds)
45333
def format_duration(duration)
      seconds = ((duration % 60) * 100.0).round / 100.0   # 1.8.7 safe .round(2)
      seconds = seconds.to_i if seconds.to_i == seconds   # drop that zero if it's not needed

      message = "#{seconds} second#{seconds == 1 ? "" : "s"}"
      message = "#{(duration / 60).to_i} minute#{(duration / 60).to_i == 1 ? "" : "s"} and " + message if duration >= 60

      message
    end
164174
def total_seconds(offset):
    """"""
    seconds = offset.days * 24 * 60 * 60 + offset.seconds
    microseconds = seconds * 10**6 + offset.microseconds
    return microseconds / (10**6 * 1.0)
958077
def fmt_duration(secs):
    """"""
    return ' '.join(fmt.human_duration(secs, 0, precision=2, short=True).strip().split())
63532
public static Timestamp ofTimeMicroseconds(long microseconds) {
    long seconds = microseconds / 1_000_000;
    int nanos = (int) (microseconds % 1_000_000 * 1000);
    if (nanos < 0) {
      seconds--;
      nanos += 1_000_000_000;
    }
    checkArgument(
        Timestamps.isValid(seconds, nanos), "timestamp out of range: %s, %s", seconds, nanos);
    return new Timestamp(seconds, nanos);
  }
699013
def ToMilliseconds(self):
    """"""
    millis = _RoundTowardZero(self.nanos, _NANOS_PER_MILLISECOND)
    return self.seconds * _MILLIS_PER_SECOND + millis
559180
def convert_timedelta(duration):
    
    days, seconds = duration.days, duration.seconds
    hours = seconds // 3600
    minutes = (seconds % 3600) // 60
    seconds = (seconds % 60)
    return days, hours, minutes, seconds
368592
def dt2ts(dt):
    """"""
    # Note: no assertion to really keep this fast
    assert isinstance(dt, (datetime.datetime, datetime.date))
    ret = time.mktime(dt.timetuple())
    if isinstance(dt, datetime.datetime):
        ret += 1e-6 * dt.microsecond
    return ret
1196510
def time_to_seconds(t):
    
    l = list(map(int, t.split(':')))
    return sum(n * sec for n, sec in zip(l[::-1], (1, 60, 3600)))
902501
def _convert_timedelta_to_seconds(timedelta):
    

    days_in_seconds = timedelta.days * 24 * 3600
    return int((timedelta.microseconds + (timedelta.seconds + days_in_seconds) * 10 ** 6) / 10 ** 6)
534760
static function microtime(): float
    {
        if (self::$now !== null) {
            return (float) self::$now;
        }

        return microtime(true);
    }
1154752
def seconds_to_time(x):
    """"""
    t = int(x * 10**6)
    ms = t % 10**6
    t = t // 10**6
    s = t % 60
    t = t // 60
    m = t % 60
    t = t // 60
    h = t
    return time(h, m, s, ms)
1340457
def micros_to_timestamp(micros, timestamp):
  
  seconds = long(micros / _MICROS_PER_SECOND)
  micro_remainder = micros % _MICROS_PER_SECOND
  timestamp.seconds = seconds
  timestamp.nanos = micro_remainder * _NANOS_PER_MICRO
600104
def nsamples_to_minsec(x, pos):
    '''
    '''
    h, m, s = hourminsec(x/16.0)
    return '{:2.0f}′ {:2.1f}″'.format(m+(h*60), s)
783216
def to_timedelta(value):
    """"""
    if value is None:
        return None
    if isinstance(value, (six.integer_types, float)):
        return timedelta(microseconds=(float(value) / 10))
    match = _TIMESPAN_PATTERN.match(value)
    if match:
        if match.group(1) == "-":
            factor = -1
        else:
            factor = 1
        return factor * timedelta(
            days=int(match.group("d") or 0),
            hours=int(match.group("h")),
            minutes=int(match.group("m")),
            seconds=float(match.group("s")),
        )
    else:
        raise ValueError("Timespan value '{}' cannot be decoded".format(value))