src/Panda/Support/Helpers/DateTimeHelper.php
public static function getAverageTimeForArrayOfDateTimes($array)
    {
        if (!is_array($array)) {
            return false;
        }

        $averageTime = null;

        $averageSecondsFromDateBeginSum = 0;
        $processedItemsCounter = 0;

        foreach ($array as $datetime) {
            if (!is_object($datetime) || !($datetime instanceof \DateTime)) {
                continue;
            }

            $hours = (int)$datetime->format('H');
            $minutes = (int)$datetime->format('i');
            $seconds = (int)$datetime->format('s');

            $averageSecondsFromDateBeginSum += $hours * 3600 + $minutes * 60 + $seconds;
            $processedItemsCounter += 1;
        }

        $averageTime = gmdate('H:i:s', intval($averageSecondsFromDateBeginSum / $processedItemsCounter) % 86400);

        return $averageTime;
    }
public static function getAverageTimeForArrayOfDateTimes($array)
    {
        if (!is_array($array)) {
            return false;
        }

        $averageTime = null;

        $averageSecondsFromDateBeginSum = 0;
        $processedItemsCounter = 0;

        foreach ($array as $datetime) {
            if (!is_object($datetime) || !($datetime instanceof \DateTime)) {
                continue;
            }

            $hours = (int)$datetime->format('H');
            $minutes = (int)$datetime->format('i');
            $seconds = (int)$datetime->format('s');

            $averageSecondsFromDateBeginSum += $hours * 3600 + $minutes * 60 + $seconds;
            $processedItemsCounter += 1;
        }

        $averageTime = gmdate('H:i:s', intval($averageSecondsFromDateBeginSum / $processedItemsCounter) % 86400);

        return $averageTime;
    }
public static function getAverageTimeForArrayOfDateTimes ( $ array ) { if ( ! is_array ( $ array ) ) { return false ; } $ averageTime = null ; $ averageSecondsFromDateBeginSum = 0 ; $ processedItemsCounter = 0 ; foreach ( $ array as $ datetime ) { if ( ! is_object ( $ datetime ) || ! ( $ datetime instanceof \ DateTime ) ) { continue ; } $ hours = ( int ) $ datetime -> format ( 'H' ) ; $ minutes = ( int ) $ datetime -> format ( 'i' ) ; $ seconds = ( int ) $ datetime -> format ( 's' ) ; $ averageSecondsFromDateBeginSum += $ hours * 3600 + $ minutes * 60 + $ seconds ; $ processedItemsCounter += 1 ; } $ averageTime = gmdate ( 'H:i:s' , intval ( $ averageSecondsFromDateBeginSum / $ processedItemsCounter ) % 86400 ) ; return $ averageTime ; }
Method find the average time for given array of datetime objects
it ignores any non DateTIme values in the given array

@param DateTime[] $array

@return string|bool
Method find the average time for given array of datetime objects it ignores any non DateTIme values in the given array