wp_maybe_decline_date

Determines if the date should be declined.

Description

(string) wp_maybe_decline_date( (string) $date ); 

If the locale specifies that month names require a genitive case in certain formats (like j F Y), the month name will be replaced with a correct form.

Returns (string)

The date, declined if locale specifies it.

Parameters (1)

0. $date (string)
Formatted date string.

Usage

  1. if ( !function_exists( 'wp_maybe_decline_date' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // Formatted date string. 
  5. $date = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_maybe_decline_date($date); 
  9.  

Defined (1)

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

/wp-includes/functions.php  
  1. function wp_maybe_decline_date( $date ) { 
  2. global $wp_locale; 
  3.  
  4. // i18n functions are not available in SHORTINIT mode 
  5. if ( ! function_exists( '_x' ) ) { 
  6. return $date; 
  7.  
  8. /** translators: If months in your language require a genitive case,  
  9. * translate this to 'on'. Do not translate into your own language. 
  10. */ 
  11. if ( 'on' === _x( 'off', 'decline months names: on or off' ) ) { 
  12. // Match a format like 'j F Y' or 'j. F' 
  13. if ( @preg_match( '#^\d{1, 2}\.? [^\d ]+#u', $date ) ) { 
  14. $months = $wp_locale->month; 
  15. $months_genitive = $wp_locale->month_genitive; 
  16.  
  17. foreach ( $months as $key => $month ) { 
  18. $months[ $key ] = '# ' . $month . '( |$)#u'; 
  19.  
  20. foreach ( $months_genitive as $key => $month ) { 
  21. $months_genitive[ $key ] = ' ' . $month . '$1'; 
  22.  
  23. $date = preg_replace( $months, $months_genitive, $date ); 
  24.  
  25. // Used for locale-specific rules 
  26. $locale = get_locale(); 
  27.  
  28. if ( 'ca' === $locale ) { 
  29. // " de abril| de agost| de octubre..." -> " d'abril| d'agost| d'octubre..." 
  30. $date = preg_replace( '# de ([ao])#i', " d'\\1", $date ); 
  31.  
  32. return $date;