iftekharul

Bangla Time Ago in WordPress

Sep 10th, 2015
90
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // How Minute Ago
  2. function get_date_time_count( $from ) {
  3.     $to = current_time( 'mysql' );
  4.     $from = strtotime($from);
  5.     $to = strtotime($to);
  6.     $diff = abs($to - $from);
  7.     $years = floor($diff / (365*60*60*24));
  8.     $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
  9.     $weeks = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (7*60*60*24));
  10.     $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
  11.     $hours = floor($diff / (60*60));
  12.     $minutes = floor(($diff - $hours * 60*60) / 60);
  13.     $seconds = floor($diff - $hours * 60*60 - $minutes*60);
  14.     if(($days == 7 || $days == 14 || $days == 21 || $days == 28) && $weeks > 0) {
  15.         if($years == 0) {
  16.             if($months > 0) { $time_ago = sprintf( _n( '%s মাস %s সপ্তাহ', '%s মাস %s সপ্তাহ', $months, $weeks ), eng_to_ban($months), eng_to_ban($weeks) ); }
  17.             elseif($months == 0) { $time_ago = sprintf( _n( '%s সপ্তাহ', '%s সপ্তাহ', $weeks ), eng_to_ban($weeks) ); }
  18.         }
  19.         else {
  20.             if($months == 0) { $time_ago = sprintf( _n( '%s বছর %s সপ্তাহ', '%s বছর %s সপ্তাহ', $years, $weeks ), eng_to_ban($years), eng_to_ban($weeks) ); }
  21.             else { $time_ago = sprintf( _n( '%s বছর %s মাস %s সপ্তাহ', '%s বছর %s মাস %s সপ্তাহ', $years, $months, $weeks ), eng_to_ban($years), eng_to_ban($months), eng_to_ban($weeks) ); }
  22.         }
  23.     }
  24.     else {
  25.         if($years == 0) {
  26.             if($months > 0 && $days == 0) { $time_ago = sprintf( _n( '%s মাস', '%s মাস', $months ), eng_to_ban($months) ); }
  27.             elseif($months > 0 && $days != 0) { $time_ago = sprintf( _n( '%s মাস %s দিন', '%s মাস %s দিন', $months, $days ), eng_to_ban($months), eng_to_ban($days) ); }
  28.             elseif($months == 0 && $days > 0) { $time_ago = sprintf( _n( '%s দিন', '%s দিন', $days ), eng_to_ban($days) ); }
  29.             elseif($months == 0 && $days == 0 && $hours > 0) { $time_ago = sprintf( _n( '%s ঘণ্টা %s মিনিট', '%s ঘণ্টা %s মিনিট', $hours, $minutes ), eng_to_ban($hours), eng_to_ban($minutes) ); }
  30.             elseif($months == 0 && $days == 0 && $hours == 0 && $minutes > 0) { $time_ago = sprintf( _n( '%s মিনিট %s সেকেন্ড', '%s মিনিট %s সেকেন্ড', $minutes, $seconds ), eng_to_ban($minutes), eng_to_ban($seconds) ); }
  31.             elseif($months == 0 && $days == 0 && $hours == 0 && $minutes == 0) { $time_ago = sprintf( _n( '%s সেকেন্ড', '%s সেকেন্ড', $seconds ), eng_to_ban($seconds) ); }
  32.         }
  33.         else {
  34.             if($months == 0) { $time_ago = sprintf( _n( '%s বছর %s দিন', '%s বছর %s দিন', $years, $days ), eng_to_ban($years), eng_to_ban($days) ); }
  35.             else { $time_ago = sprintf( _n( '%s বছর %s মাস %s দিন', '%s বছর %s মাস %s দিন', $years, $months, $days ), eng_to_ban($years), eng_to_ban($months), eng_to_ban($days) ); }
  36.         }
  37.     }
  38.     return $time_ago;
  39. }
RAW Paste Data