Advertisement
philker_viceleader

get_the_clock (WordPress)

May 31st, 2012
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.52 KB | None | 0 0
  1. /*
  2.     function get_the_clock
  3.     Formatted the Date and Time
  4.     @author Van Lauren Laffressia
  5. */
  6. function get_the_clock() {
  7.  
  8.     global $post;
  9.     setlocale( LC_TIME, "fr_CA" );
  10.  
  11.     $date = get_post_time('G', true, $post);
  12.     static $clock = 86400;
  13.  
  14.     if( !is_numeric( $date ) ) {
  15.         $time_chunks = explode( ':', str_replace( ' ', ':', $date ) );
  16.         $date_chunks = explode( '-', str_replace( ' ', '-', $date ) );
  17.         $date = gmmktime( (int)$time_chunks[1], (int)$time_chunks[2], (int)$time_chunks[3], (int)$date_chunks[1], (int)$date_chunks[2], (int)$date_chunks[0] );
  18.     }
  19.  
  20.     $current_time = current_time( 'mysql', $gmt );
  21.     $newer_date = ( !$newer_date ) ? strtotime( $current_time ) : $newer_date;
  22.  
  23.     // Difference in seconds
  24.     $since = $newer_date - $date;
  25.  
  26.     // Something went wrong with date calculation and we ended up with a negative date.
  27.     if( 0 > $since )
  28.         return __( 'sometime', 'lexpress' );
  29.     else {
  30.         //Within 24 hours
  31.         if( $since < $clock )
  32.             return __( 'Aujourd\'hui', 'lexpress' );
  33.         //Within 48 hours
  34.         elseif( $since < $clock * 2 )
  35.             return __( 'Hier', 'lexpress' );
  36.         //Mercredi
  37.         elseif( $since < $clock * 3 )
  38.             return strftime( "%A", $clock );
  39.         //Jeudi
  40.         elseif( $since < $clock * 4 )
  41.             return strftime( "%A", $clock );
  42.         //Vendredi
  43.         elseif( $since < $clock * 5 )
  44.             return strftime( "%A", $clock );
  45.         //Samedi
  46.         elseif( $since < $clock * 6 )
  47.             return strftime( "%A", $clock );
  48.         //Dimanche
  49.         elseif( $since < $clock * 7 )
  50.             return strftime( "%A", $clock );
  51.         else
  52.             return get_the_date();
  53.    
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement