aaemnnosttv/wp-sqlite-db

Suggestion: Remove unnecessary PHP 5.3.2 support from datediff implementation

Closed this issue · 1 comments

Since WordPress supports the minimum PHP 5.6 and that will change quite soon, why not improve code from

public function datediff($start, $end)
{
    if (version_compare(PHP_VERSION, '5.3.2', '==')) {
        $start_date = strtotime($start);
        $end_date = strtotime($end);
        $interval = floor(($start_date - $end_date) / (3600 * 24));

        return $interval;
    } else {
        $start_date = new DateTime($start);
        $end_date = new DateTime($end);
        $interval = $end_date->diff($start_date, false);

        return $interval->format('%r%a');
    }
}

to

public function datediff($start, $end)
{
    $start_date = new DateTime($start);
    $end_date = new DateTime($end);
    $interval = $end_date->diff($start_date, false);

    return $interval->format('%r%a');
}

Shorter and cleaner.

By the way @aaemnnosttv, if you want me to create pull with this improvement, let me know.