bb_gmdate_i18n

Retrieve the date in localized format, based on timestamp.

Description

(string) bb_gmdate_i18n( (string) $dateformatstring, (constant) $unixtimestamp = false, (bool) $gmt = true ); 

If the locale specifies the locale month and weekday, then the locale will take over the format for the date. If it isn't, then the date format string will be used instead.

Returns (string)

The date, translated if locale specifies it.

Parameters (3)

0. $dateformatstring (string)
Format to display the date.
1. $unixtimestamp — Optional. (constant) => false
Unix timestamp.
2. $gmt — Optional. (bool) => true
Optional, default is true. Whether to convert to GMT for time.

Usage

  1. if ( !function_exists( 'bb_gmdate_i18n' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/class.bb-locale.php'; 
  3.  
  4. // Format to display the date. 
  5. $dateformatstring = ''; 
  6.  
  7. // Optional. Unix timestamp. 
  8. $unixtimestamp = false; 
  9.  
  10. // Optional, default is true. Whether to convert to GMT for time. 
  11. $gmt = true; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bb_gmdate_i18n($dateformatstring, $unixtimestamp, $gmt); 
  15.  

Defined (1)

The function is defined in the following location(s).

/bp-forums/bbpress/bb-includes/class.bb-locale.php  
  1. function bb_gmdate_i18n( $dateformatstring, $unixtimestamp = false, $gmt = true ) { 
  2. global $bb_locale; 
  3. $i = $unixtimestamp; 
  4. // Sanity check for PHP 5.1.0- 
  5. if ( false === $i || intval($i) < 0 ) { 
  6. if ( ! $gmt ) 
  7. $i = current_time( 'timestamp' ); 
  8. else 
  9. $i = time(); 
  10. // we should not let date() interfere with our 
  11. // specially computed timestamp 
  12. $gmt = true; 
  13.  
  14. // store original value for language with untypical grammars 
  15. // see http://core.trac.wordpress.org/ticket/9396 
  16. $req_format = $dateformatstring; 
  17.  
  18. $datefunc = $gmt? 'gmdate' : 'date'; 
  19.  
  20. if ( ( !empty( $bb_locale->month ) ) && ( !empty( $bb_locale->weekday ) ) ) { 
  21. $datemonth = $bb_locale->get_month( $datefunc( 'm', $i ) ); 
  22. $datemonth_abbrev = $bb_locale->get_month_abbrev( $datemonth ); 
  23. $dateweekday = $bb_locale->get_weekday( $datefunc( 'w', $i ) ); 
  24. $dateweekday_abbrev = $bb_locale->get_weekday_abbrev( $dateweekday ); 
  25. $datemeridiem = $bb_locale->get_meridiem( $datefunc( 'a', $i ) ); 
  26. $datemeridiem_capital = $bb_locale->get_meridiem( $datefunc( 'A', $i ) ); 
  27. $dateformatstring = ' '.$dateformatstring; 
  28. $dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring ); 
  29. $dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring ); 
  30. $dateformatstring = preg_replace( "/([^\\\])l/", "\\1" . backslashit( $dateweekday ), $dateformatstring ); 
  31. $dateformatstring = preg_replace( "/([^\\\])M/", "\\1" . backslashit( $datemonth_abbrev ), $dateformatstring ); 
  32. $dateformatstring = preg_replace( "/([^\\\])a/", "\\1" . backslashit( $datemeridiem ), $dateformatstring ); 
  33. $dateformatstring = preg_replace( "/([^\\\])A/", "\\1" . backslashit( $datemeridiem_capital ), $dateformatstring ); 
  34.  
  35. $dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 ); 
  36. $j = @$datefunc( $dateformatstring, $i ); 
  37. // allow plugins to redo this entirely for languages with untypical grammars 
  38. $j = apply_filters('bb_gmdate_i18n', $j, $req_format, $i, $gmt); 
  39. return $j;