Convert given time in given unit to given destination unit in given mode.
491627
public static function convert(float $time, string $unit, string $destUnit, string $mode)
    {
        self::validateMode($mode);

        if ($mode === self::MODE_TIME) {
            return self::convertTo($time, $unit, $destUnit);
        }

        return self::convertInto($time, $unit, $destUnit);
    }
1366730
public function toDestUnit(float $time, string $destUnit = null, string $mode = null)
    {
        return self::convert($time, $this->sourceUnit, $this->getDestUnit($destUnit), $this->getMode($mode));
    }
160484
private static ZonedDateTime toZonedDateTimeUtc(final long epochValue, final EpochUnits units) {
        Preconditions.checkArgument(units != null, "units must be non-null");
        final Instant instant = units.toInstant(epochValue);
        return ZonedDateTime.ofInstant(instant, ZoneOffset.UTC);
    }
866097
def convertTime(self, frametime, which):
        """"""
        SubAssert(frametime.frame >= 0, _("Negative time present."))
        return frametime.frame
345449
def to_local(self, dt):
        """"""
        if dt.tzinfo is None:
            dt = dt.replace(tzinfo=self.utc)
        return dt.astimezone(self.local)
130300
public static function convertTo(float $time, string $unit, string $destUnit)
    {
        self::validateUnit($unit);
        self::validateUnit($destUnit);

        $destM = self::$map[$destUnit];
        $sourceM = self::$map[$unit];

        $time = ($time * $sourceM) / $destM;

        return $time;
    }
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)
746170
def _convert_seconds(self, packed_seconds):
        """"""
        seconds = struct.unpack("!H", packed_seconds[:2])[0]
        seconds += struct.unpack("!I", packed_seconds[2:])[0]
        return seconds
1027784
private String toLabel(final TimeUnit unit) {
      switch(unit) {
         case DAYS: return "day";
         case HOURS: return "hour";
         case MINUTES: return "minute";
         case SECONDS: return "second";
         case MILLISECONDS: return "ms";
         case MICROSECONDS: return "us";
         case NANOSECONDS: return "ns";
         default: return "";
      }
   }
1244835
function convertTime(value, fromUnit, toUnit)
{
    if(fromUnit != toUnit && value !== 0)
    {
        return value * (toUnit == 's'? 0.001 : 1000);
    }
    return value;
}
1198536
def normalize(value, unit):
    
    if value < 0:
        raise ValueError('Negative value: %s %s.' % (value, unit))

    if unit in functions.get_keys(INFORMATION_UNITS):
        return _normalize_information(value, unit)
    elif unit in TIME_UNITS:
        return _normalize_time(value, unit)
    else:
        # Unknown unit, just return it
        return functions.format_value(value), unit
70114
def localize(self, dt, is_dst=False):
        """"""
        if dt.tzinfo is not None:
            raise ValueError('Not naive datetime (tzinfo is already set)')
        return dt.replace(tzinfo=self)
46196
def convert_to_unit(self, unit):
        """"""
        self._values = self._header.data_type.to_unit(
            self._values, unit, self._header.unit)
        self._header._unit = unit
179591
def to_unix_ts(start_time):
    """"""
    if isinstance(start_time, datetime):
        if is_timezone_aware(start_time):
            start_time = start_time.astimezone(pytz.utc)
        else:
            log.warning(
                "Non timezone-aware datetime object passed to IncrementalEndpoint. "
                "The Zendesk API expects UTC time, if this is not the case results will be incorrect!"
            )
        unix_time = calendar.timegm(start_time.timetuple())
    else:
        unix_time = start_time

    return int(unix_time)
593323
def go_to(self, time):
        """"""
        half_dur = self.half_duration
        self.set_interval((time - half_dur, time + half_dur))
205241
def _to_timezone(self, dt):
        """"""
        tz = self._get_tz()
        utc_dt = pytz.utc.localize(dt)
        return utc_dt.astimezone(tz)
47079
def to_utc(self, dt):
        """"""
        if dt.tzinfo is None:
            return dt.replace(tzinfo=self.utc)
        return dt.astimezone(self.utc)