From 379c7ec4a0ab657133755f950ec29d72d880ae1f Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 19 Dec 2018 22:35:38 -0800 Subject: [PATCH] Update functions.php Add missing function required for Messages app updates. --- resources/functions.php | 64 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/resources/functions.php b/resources/functions.php index a8ee862b54..e7f715c2d4 100644 --- a/resources/functions.php +++ b/resources/functions.php @@ -1940,4 +1940,68 @@ function number_pad($number,$n) { //return htmlentities($string, ENT_QUOTES, 'UTF-8'); } +// output pre-formatted array keys and values + if (!function_exists('view_array')) { + function view_array($array, $exit = true) { + echo '
'.print_r($array, true).'

'; + $exit and exit(); + } + } + +// format db date and/or time to local date and/or time + if (!function_exists('format_when_local')) { + function format_when_local($when, $format = 'dt', $include_seconds = false) { + if ($when != '') { + // determine when format + if (substr_count($when, ' ') > 0) { // date and time + $tmp = explode(' ', $when); + $date = $tmp[0]; + $time = $tmp[1]; + } + else if (substr_count($when, '-') > 0) { // date only + $date = $when; + } + else if (substr_count($when, ':') > 0) { // time only + $time = $when; + } + unset($when, $tmp); + + // format date + if ($date != '') { + $tmp = explode('-', $date); + $date = $tmp[1].'-'.$tmp[2].'-'.$tmp[0]; + } + + // format time + if ($time != '') { + $tmp = explode(':', $time); + if ($tmp[0] >= 0 && $tmp[0] <= 11) { + $meridiem = 'AM'; + $hour = ($tmp[0] == 0) ? 12 : $tmp[0]; + } + else { + $meridiem = 'PM'; + $hour = ($tmp[0] > 12) ? ($tmp[0] - 12) : $tmp[0]; + } + $minute = $tmp[1]; + $second = $tmp[2]; + } + + // structure requested time format + $time = $hour.':'.$minute; + if ($include_seconds) { $time .= ':'.$second; } + $time .= ' '.$meridiem; + + $return['d'] = $date; + $return['t'] = $time; + $return['dt'] = $date.' '.$time; + + return $return[$format]; + } + else { + return false; + } + } + } + ?>