json/apiで取得した日時を「◯分前」といったtwitter表記に変更する

■function.php

function getPassedTime($created_at) {
    $now = date_create(date('Y-m-d H:i:s'));//(*1)
    $created = date_create(date('Y-m-d H:i:s', strtotime($created_at)));//(*2)
    $passed = date_diff($now, $created);

    switch (true) :
        case ($passed->y):return $passed->y . '年前';
        case ($passed->m):return $passed->m . 'ヶ月前';
        //case ($passed->w):return $passed->w . '週間前';
        case ($passed->d):return $passed->d . '日前';
        case ($passed->h):return $passed->h . '時間前';
        case ($passed->i):return $passed->i . '分前';
        default:
            return $passed->s . "秒前";
    endswitch;
}

■出力php

<?php
	$timestamp = getPassedTime($tweet_data['created_at']);
?>
<?php echo $timestamp; ?>