I have a function to get the Time-ago from a Timestamp, I grabbed it somewhere from the internet and developed and optimized it. It's fully functioning. The problem here is that it ONLY gets time-ago (from a past Timestamp), it didn't process future Timestamps (It returns 0 seconds ago). Is anybody able to help me add this functionality to the function?
<?php
function time_ago( $ts, $format ) {
    // $format = 'l, F d, Y H:i';
    $granularity    = 1;
    $dif            = time() - $ts;
    if ( $dif < 0 )
        return '0 Seconds ago';
    elseif ( $dif < 604800 ) { // 604800 7 days / 864000 10 days
        $periods = array(
            'Week'      => 604800,
            'Day'       => 86400,
            'Hour'      => 3600,
            'Minute'    => 60,
            'Second'    => 1
        );
        $output = '';
        foreach ( $periods as $key => $value ) {
            if ( $dif >= $value ) {
                $time = round( $dif / $value );
                $dif %= $value;
                $output .= ( $output ? ' ' : '' ) . $time . ' ';
                $output .= ( ( $time > 1 ) ? $key . 's' : $key );
                $granularity --;
            }
            if ( $granularity == 0 )
                break;
        } // foreach( $periods as $key => $value )
        return ($output ? $output : '0 seconds') . ' ago';
    } else
        return date( $format, $ts );
}
?>
 
     
    