lots of updates
This commit is contained in:
@ -1,5 +1,10 @@
|
||||
<?php
|
||||
|
||||
require_once "functions/strings.php";
|
||||
require_once "functions/date_and_time.php";
|
||||
require_once "functions/distances.php";
|
||||
require_once "functions/temperatures.php";
|
||||
|
||||
/**
|
||||
|--------------------------------------------------------------------------
|
||||
| Global Functions
|
||||
@ -10,21 +15,31 @@
|
||||
|
|
||||
*/
|
||||
|
||||
if (! function_exists('snake2Title')) {
|
||||
if (! function_exists('humanBytes')) {
|
||||
/**
|
||||
* Convert a snake case string to a title with spaces
|
||||
* and every word capitalized.
|
||||
* Convert bytes to a human-friendly format.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $stakeSlug A snake case string, commonly a slug
|
||||
* @param int|string $number
|
||||
* @param int|string|null $precision Decimal places to show (optional)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function snake2Title(string $snakeSlug): string
|
||||
function humanBytes($number, $precision = null): string
|
||||
{
|
||||
$output = preg_replace('/\_/', ' ', $snakeSlug);
|
||||
return ucwords($output);
|
||||
if (empty($number)) {
|
||||
return '0 B';
|
||||
}
|
||||
|
||||
static $units = ['B', 'KB', 'MB', 'GB'];
|
||||
static $bytePreceision = [0, 0, 1, 2];
|
||||
$divisor = 1024;
|
||||
|
||||
for ($i = 0; $number / $divisor > = 0.9 && $i < 4; $i++) {
|
||||
$number /= $divisor;
|
||||
}
|
||||
return round($number, is_null($precision) ? $bytePreceision[$i] : $precision) . $units[$i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,31 +65,6 @@ if (! function_exists('carbon')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('jddayofweek')) {
|
||||
/**
|
||||
* Returns the day of the week. Can return a string or an integer depending on the mode.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param int|null $intDay
|
||||
* @param int $mode
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function jddayofweek(?int $intDay = null, int $mode = 0): string
|
||||
{
|
||||
if (is_null($intDay)) {
|
||||
$intDay = date('l');
|
||||
}
|
||||
|
||||
if ($mode === 0) {
|
||||
return $intDay;
|
||||
}
|
||||
|
||||
return ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][$intDay];
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('is_serialized')) {
|
||||
/**
|
||||
* Check a value to find if it was serialized.
|
||||
@ -174,284 +164,3 @@ if (! function_exists('maybe_unserialize')) {
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|--------------------------------------------------------------------------
|
||||
| Metric functions
|
||||
|--------------------------------------------------------------------------
|
||||
| Functions that convert from metric to imperial or from a smaller
|
||||
| metric unit to a larger one.
|
||||
|
|
||||
*/
|
||||
|
||||
if (! function_exists('centimeters2Inches')) {
|
||||
/**
|
||||
* Convert from centimeters to inches.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $centimeters
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function centimeters2Inches($centimeters, int $preceision = 1): float
|
||||
{
|
||||
return round(($centimeters / 2.54), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('centimeters2Feet')) {
|
||||
/**
|
||||
* Convert from centimeters to inches.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $centimeters
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function centimeters2Feet($centimeters, int $preceision = 1): float
|
||||
{
|
||||
return round((($centimeters / 2.54) * 12), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('centimeters2Meters')) {
|
||||
/**
|
||||
* Convert from centimeters to meters.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $centimeters
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function centimeters2Meters($centimeters, int $preceision = 1): float
|
||||
{
|
||||
return round(($centimeters / 100), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('centimeters2Yards')) {
|
||||
/**
|
||||
* Convert from centimeters to yards.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $centimeters
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function centimeters2Yards($centimeters, int $preceision = 1): float
|
||||
{
|
||||
return round(($centimeters / 91.44), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('meters2Miles')) {
|
||||
/**
|
||||
* Convert from meters to miles.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $meters
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function meters2Miles($meters, int $preceision = 1): float
|
||||
{
|
||||
return round(($meters * 0.00062137), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('kilometers2Miles')) {
|
||||
/**
|
||||
* Convert from kilometers to meters.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $kilometers
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function kilometers2Miles($kilometers, int $preceision = 1): float
|
||||
{
|
||||
return round(($kilometers * 1.609), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('meters2Kilometers')) {
|
||||
/**
|
||||
* Convert from meters to kilometers.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $meters
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function meters2Kilometers($meters, int $preceision = 1): float
|
||||
{
|
||||
return round(($meters / 1000), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('celsius2Fahrenheit')) {
|
||||
/**
|
||||
* Convert from celsius to fahrenheit.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $celsius
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function celsius2Fahrenheit($celsius, int $preceision = 0): float
|
||||
{
|
||||
return round((($celsius * (9/5)) + 32), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('millimeters2Inches')) {
|
||||
/**
|
||||
* Convert from millimeters to inches.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $millimeters
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function millimeters2Inches($millimeters, int $preceision = 1): float
|
||||
{
|
||||
return round(($millimeters / 25.4), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|--------------------------------------------------------------------------
|
||||
| Imperial functions
|
||||
|--------------------------------------------------------------------------
|
||||
| Functions that convert from imperial to metric or from a smaller
|
||||
| imperial unit to a larger one.
|
||||
|
|
||||
*/
|
||||
|
||||
if (! function_exists('inches2Millimeters')) {
|
||||
/**
|
||||
* Convert from inches to millimeters.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $inches
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function inches2Millimeters($inches, int $preceision = 1): float
|
||||
{
|
||||
return round(($inches * 2.54), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('inches2Meters')) {
|
||||
/**
|
||||
* Convert from inches to meters.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $inches
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function inches2Meters($inches, int $preceision = 1): float
|
||||
{
|
||||
return round(($inches / 39.37), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('inches2Yards')) {
|
||||
/**
|
||||
* Convert from inches to yards.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $inches
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function inches2Yards($inches, int $preceision = 1): float
|
||||
{
|
||||
return round(($inches / 36), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('inches2Feet')) {
|
||||
/**
|
||||
* Convert from inches to feet.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $inches
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function inches2Feet($inches, int $preceision = 1): float
|
||||
{
|
||||
return round(($inches * 12), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('fahrenheit2Celsius')) {
|
||||
/**
|
||||
* Convert from fahrenheit to celsius.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $fahrenheit
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function fahrenheit2Celsius($fahrenheit, int $preceision = 1): float
|
||||
{
|
||||
return round(($fahrenheit - 32 * (5/9)), $preceision);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|--------------------------------------------------------------------------
|
||||
| Miscellaneous functions
|
||||
|--------------------------------------------------------------------------
|
||||
| Functions that don't really belong to the other two categories.
|
||||
|
|
||||
*/
|
||||
|
||||
if (! function_exists('pa2Mbar')) {
|
||||
/**
|
||||
* Convert from pascals to milibars.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param float|int|string $pascals
|
||||
* @param int $precision
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
function pa2Mbar($pascals, int $preceision = 1): float
|
||||
{
|
||||
return round(($pascals / 100), $preceision);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user