Tribe__Date_Utils::wp_locale_weekday( int|string $weekday, string $format = 'weekday' )
Return a WP Locale weekday in the specified format
Contents
Parameters
- $weekday
-
(int|string) (Required) Day of week
- $format
-
(string) (Optional) Weekday format: full, weekday, initial, abbreviation, abbrev, abbr, short
Default value: 'weekday'
Return
(string)
Source
File: src/Tribe/Date_Utils.php
public static function wp_locale_weekday( $weekday, $format = 'weekday' ) {
$weekday = trim( $weekday );
$valid_formats = array(
'full',
'weekday',
'initial',
'abbreviation',
'abbrev',
'abbr',
'short',
);
// if there isn't a valid format, bail without providing a localized string
if ( ! in_array( $format, $valid_formats ) ) {
return $weekday;
}
if ( empty( self::$localized_weekdays ) ) {
self::build_localized_weekdays();
}
// if the weekday isn't numeric, we need to convert to numeric in order to
// leverage self::localized_weekdays
if ( ! is_numeric( $weekday ) ) {
$days_of_week = array(
'Sun',
'Mon',
'Tue',
'Wed',
'Thu',
'Fri',
'Sat',
);
$day_index = array_search( ucwords( substr( $weekday, 0, 3 ) ), $days_of_week );
if ( false === $day_index ) {
return $weekday;
}
$weekday = $day_index;
}
switch ( $format ) {
case 'initial':
$type = 'initial';
break;
case 'abbreviation':
case 'abbrev':
case 'abbr':
case 'short':
$type = 'short';
break;
case 'weekday':
case 'full':
default:
$type = 'full';
break;
}
return self::$localized_weekdays[ $type ][ $weekday ];
}
Changelog
| Version | Description |
|---|---|
| 4.4.3 | Introduced. |