Move common fucntions to helpers.php

This commit is contained in:
Matthew Shillam 2018-10-22 02:58:03 +01:00
parent 1ba10100bf
commit 7b81506dc2
1 changed files with 44 additions and 0 deletions

44
app/Helpers.php Normal file
View File

@ -0,0 +1,44 @@
<?php
/**
*
* Common helper functions as defined by me myself and i.
*
*/
/**
* readableBytes -- : Converts string of bytes into a readable format e.g KB, MB, GB, TB, YB
*
* @param {Int} num The number of bytes.
*/
function readableBytes($bytes)
{
if ($bytes <= 1 ) {
return "0B";
}
$i = floor(log($bytes) / log(1024));
$sizes = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
return sprintf('%.02F', $bytes / pow(1024, $i)) * 1 . ' ' . $sizes[$i];
}
function parse_duplicati_message($message)
{
$message = preg_replace('/:\s+/', '=', $message);
$message = preg_replace('/AM\s+/', '', $message);
$message = preg_replace('/PM\s+/', '', $message);
$message = preg_replace('/(?<=\d)\s+(?=\d)/', '-', $message);
$message = preg_replace('/\s+\(/', '(', $message);
$message = preg_replace('/\s+/', '&', $message);
parse_str($message, $data);
return $data;
}
function parse_duplicati_time($time)
{ // BeginTime: 10/22/2018 2:13:38 AM (1540170818)
$time = str_after($time, '(');
$time = str_before($time, ')');
$time = \Carbon\Carbon::createFromTimestamp($time)->toDateTimeString();
return $time;
}