Changeset 9617
- Timestamp:
- 03/11/2015 08:01:21 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-template.php
r9523 r9617 284 284 * 'date_format' and 'time_format' settings are). False on failure. 285 285 */ 286 function bp_format_time( $time, $just_date = false, $localize_time = true ) { 287 288 if ( ! isset( $time ) || ! is_numeric( $time ) ) { 286 function bp_format_time( $time = '', $just_date = false, $localize_time = true ) { 287 288 // Bail if time is empty or not numeric 289 // @todo We should output something smarter here 290 if ( empty( $time ) || ! is_numeric( $time ) ) { 289 291 return false; 290 292 } 291 293 292 294 // Get GMT offset from root blog 293 $root_blog_offset = false; 294 if ( ! empty( $localize_time ) ) { 295 $root_blog_offset = get_blog_option( bp_get_root_blog_id(), 'gmt_offset' ); 296 } 297 298 // Calculate offset time 299 $time_offset = $time + ( $root_blog_offset * 3600 ); 295 if ( true === $localize_time ) { 296 297 // Use Timezone string if set 298 $timezone_string = bp_get_option( 'timezone_string' ); 299 if ( ! empty( $timezone_string ) ) { 300 $timezone_object = timezone_open( $timezone_string ); 301 $datetime_object = date_create( "@{$time}" ); 302 $timezone_offset = timezone_offset_get( $timezone_object, $datetime_object ) / HOUR_IN_SECONDS; 303 304 // Fall back on less reliable gmt_offset 305 } else { 306 $timezone_offset = bp_get_option( 'gmt_offset' ); 307 } 308 309 // Calculate time based on the offset 310 $calculated_time = $time + ( $timezone_offset * HOUR_IN_SECONDS ); 311 312 // No localizing, so just use the time that was submitted 313 } else { 314 $calculated_time = $time; 315 } 300 316 301 317 // Current date (January 1, 2010) 302 $ date = date_i18n( get_option( 'date_format' ), $time_offset);318 $formatted_date = date_i18n( bp_get_option( 'date_format' ), $calculated_time, $localize_time ); 303 319 304 320 // Should we show the time also? 305 if ( empty( $just_date ) ) { 321 if ( false === $just_date ) { 322 306 323 // Current time (9:50pm) 307 $ time = date_i18n( get_option( 'time_format' ), $time_offset);324 $formatted_time = date_i18n( bp_get_option( 'time_format' ), $calculated_time, $localize_time ); 308 325 309 326 // Return string formatted with date and time 310 $ date = sprintf( __( '%1$s at %2$s', 'buddypress' ), $date, $time );311 } 312 313 return apply_filters( 'bp_format_time', $ date );327 $formatted_date = sprintf( esc_html__( '%1$s at %2$s', 'buddypress' ), $formatted_date, $formatted_time ); 328 } 329 330 return apply_filters( 'bp_format_time', $formatted_date ); 314 331 } 315 332
Note: See TracChangeset
for help on using the changeset viewer.