mirror of
https://github.com/itflow-org/itflow
synced 2026-07-23 08:50:42 +00:00
Cleanup format Functions
This commit is contained in:
@@ -15,6 +15,7 @@ function initials($string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function truncate($text, $chars) {
|
function truncate($text, $chars) {
|
||||||
if (strlen($text) <= $chars) {
|
if (strlen($text) <= $chars) {
|
||||||
return $text;
|
return $text;
|
||||||
@@ -28,6 +29,7 @@ function truncate($text, $chars) {
|
|||||||
return $text . "...";
|
return $text . "...";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function formatPhoneNumber($phoneNumber, $country_code = '', $show_country_code = false) {
|
function formatPhoneNumber($phoneNumber, $country_code = '', $show_country_code = false) {
|
||||||
// Remove all non-digit characters
|
// Remove all non-digit characters
|
||||||
$digits = preg_replace('/\D/', '', $phoneNumber ?? '');
|
$digits = preg_replace('/\D/', '', $phoneNumber ?? '');
|
||||||
@@ -189,8 +191,8 @@ function formatPhoneNumber($phoneNumber, $country_code = '', $show_country_code
|
|||||||
return $show_country_code && $country_code ? "+$country_code $formatted" : $formatted;
|
return $show_country_code && $country_code ? "+$country_code $formatted" : $formatted;
|
||||||
}
|
}
|
||||||
|
|
||||||
function timeAgo($datetime)
|
|
||||||
{
|
function timeAgo($datetime) {
|
||||||
if (is_null($datetime)) {
|
if (is_null($datetime)) {
|
||||||
return "-";
|
return "-";
|
||||||
}
|
}
|
||||||
@@ -225,8 +227,8 @@ function timeAgo($datetime)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function shortenClientName($client)
|
|
||||||
{
|
function shortenClientName($client) {
|
||||||
// Pre-process by removing any non-alphanumeric characters except for certain punctuations.
|
// Pre-process by removing any non-alphanumeric characters except for certain punctuations.
|
||||||
$client = html_entity_decode($client); // Decode any HTML entities
|
$client = html_entity_decode($client); // Decode any HTML entities
|
||||||
$client = str_replace("'", "", $client); // Removing all occurrences of '
|
$client = str_replace("'", "", $client); // Removing all occurrences of '
|
||||||
@@ -267,13 +269,13 @@ function shortenClientName($client)
|
|||||||
return strtoupper(substr($shortened, 0, 3));
|
return strtoupper(substr($shortened, 0, 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
function roundUpToNearestMultiple($n, $increment = 1000)
|
|
||||||
{
|
function roundUpToNearestMultiple($n, $increment = 1000) {
|
||||||
return (int) ($increment * ceil($n / $increment));
|
return (int) ($increment * ceil($n / $increment));
|
||||||
}
|
}
|
||||||
|
|
||||||
function roundToNearest15Min($time)
|
|
||||||
{
|
function roundToNearest15Min($time) {
|
||||||
// Validate the input time format
|
// Validate the input time format
|
||||||
if (!preg_match('/^(\d{2}):(\d{2}):(\d{2})$/', $time, $matches)) {
|
if (!preg_match('/^(\d{2}):(\d{2}):(\d{2})$/', $time, $matches)) {
|
||||||
return false; // or throw an exception
|
return false; // or throw an exception
|
||||||
@@ -301,6 +303,7 @@ function roundToNearest15Min($time)
|
|||||||
return number_format($decimalHours, 2);
|
return number_format($decimalHours, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function formatDuration($time) {
|
function formatDuration($time) {
|
||||||
// expects "HH:MM:SS"
|
// expects "HH:MM:SS"
|
||||||
[$h, $m, $s] = array_map('intval', explode(':', $time));
|
[$h, $m, $s] = array_map('intval', explode(':', $time));
|
||||||
@@ -318,6 +321,7 @@ function formatDuration($time) {
|
|||||||
return implode(' ', $parts);
|
return implode(' ', $parts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function validateDate($date) {
|
function validateDate($date) {
|
||||||
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $date)) {
|
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $date)) {
|
||||||
return $date;
|
return $date;
|
||||||
|
|||||||
Reference in New Issue
Block a user