Changeset View
Changeset View
Standalone View
Standalone View
src/utils/utils.php
Show First 20 Lines • Show All 1,107 Lines • ▼ Show 20 Lines | case 'seconds': | ||||
break; | break; | ||||
default: | default: | ||||
throw new InvalidArgumentException( | throw new InvalidArgumentException( | ||||
pht( | pht( | ||||
'This function can not convert from the unit "%s".', | 'This function can not convert from the unit "%s".', | ||||
$src_unit)); | $src_unit)); | ||||
} | } | ||||
break; | break; | ||||
case 'bytes': | case 'bytes': | ||||
switch ($src_unit) { | switch ($src_unit) { | ||||
case 'byte': | case 'byte': | ||||
case 'bytes': | case 'bytes': | ||||
$factor = 1; | $factor = 1; | ||||
break; | break; | ||||
case 'bit': | case 'bit': | ||||
case 'bits': | case 'bits': | ||||
$factor = 8; | $factor = 8; | ||||
$is_divisor = true; | $is_divisor = true; | ||||
break; | break; | ||||
default: | default: | ||||
throw new InvalidArgumentException( | throw new InvalidArgumentException( | ||||
pht( | pht( | ||||
'This function can not convert from the unit "%s".', | 'This function can not convert from the unit "%s".', | ||||
$src_unit)); | $src_unit)); | ||||
} | } | ||||
break; | break; | ||||
case 'milliseconds': | |||||
switch ($src_unit) { | |||||
case 'second': | |||||
case 'seconds': | |||||
$factor = 1000; | |||||
break; | |||||
case 'minute': | |||||
case 'minutes': | |||||
$factor = 1000 * 60; | |||||
break; | |||||
case 'hour': | |||||
case 'hours': | |||||
$factor = 1000 * 60 * 60; | |||||
break; | |||||
case 'day': | |||||
case 'days': | |||||
$factor = 1000 * 60 * 60 * 24; | |||||
break; | |||||
default: | |||||
throw new InvalidArgumentException( | |||||
pht( | |||||
'This function can not convert from the unit "%s".', | |||||
$src_unit)); | |||||
} | |||||
break; | |||||
case 'microseconds': | |||||
switch ($src_unit) { | |||||
case 'second': | |||||
case 'seconds': | |||||
$factor = 1000000; | |||||
break; | |||||
case 'minute': | |||||
case 'minutes': | |||||
$factor = 1000000 * 60; | |||||
break; | |||||
case 'hour': | |||||
case 'hours': | |||||
$factor = 1000000 * 60 * 60; | |||||
break; | |||||
case 'day': | |||||
case 'days': | |||||
$factor = 1000000 * 60 * 60 * 24; | |||||
break; | |||||
default: | |||||
throw new InvalidArgumentException( | |||||
pht( | |||||
'This function can not convert from the unit "%s".', | |||||
$src_unit)); | |||||
} | |||||
break; | |||||
default: | default: | ||||
throw new InvalidArgumentException( | throw new InvalidArgumentException( | ||||
pht( | pht( | ||||
'This function can not convert into the unit "%s".', | 'This function can not convert into the unit "%s".', | ||||
$dst_unit)); | $dst_unit)); | ||||
} | } | ||||
if ($is_divisor) { | if ($is_divisor) { | ||||
▲ Show 20 Lines • Show All 564 Lines • Show Last 20 Lines |