public function getInstagramLastPostTime($num = 0) { $posts = $this->getInstagramPosts(); return time_elapsed_52($posts->data[$num]->caption->created_time); }
function get_fb_posts_time($num, $truncate_words = false, $divs = true) { $posts = get_facebook_posts(); $i = 1; foreach ($posts as $post) { if ($i > $num) { break; } if ($i < $num) { $i++; continue; } if (empty($post['content'])) { $post_content = $post['link_description']; } elseif (!empty($post['content'])) { $post_content = $post['content']; } else { $post_content = 'Enclothed - Men\'s bespoke outfitters'; } //$time = time_elapsed($post['timestamp']); $time = time_elapsed_52($post['timestamp']); if ($divs) { echo "<div class='fb_post' style='padding-bottom:20px'>"; echo "<div class='fb_post_content'>{$post_content}</div>"; echo "<div class='fb_time'>{$time}</div>"; echo "</div>"; } else { echo $time; } $i++; } }
function time_elapsed($datetime, $full = false) { $now = new DateTime(); $datetime = date('d-m-Y H:m:i', $datetime); $ago = new DateTime($datetime); $diff = $now->diff($ago); $diff = time_elapsed_52($datetime); $diff->w = floor($diff->d / 7); $diff->d -= $diff->w * 7; $string = array('y' => 'year', 'm' => 'month', 'w' => 'week', 'd' => 'day', 'h' => 'hour', 'i' => 'minute', 's' => 'second'); foreach ($string as $k => &$v) { if ($diff->{$k}) { $v = $diff->{$k} . ' ' . $v . ($diff->{$k} > 1 ? 's' : ''); } else { unset($string[$k]); } } if (!$full) { $string = array_slice($string, 0, 1); } return $string ? implode(', ', $string) . ' ago' : 'just now'; }