Ticket #40653: 40653.diff
File 40653.diff, 2.4 KB (added by , 8 years ago) |
---|
-
src/wp-includes/functions.php
59 59 * @return int|string Integer if $type is 'timestamp', string otherwise. 60 60 */ 61 61 function current_time( $type, $gmt = 0 ) { 62 // Special handling for legacy offset timestamps. 63 if ( 'timestamp' === $type && ! $gmt ) { 64 return time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); 65 } 66 62 67 switch ( $type ) { 63 68 case 'mysql': 64 return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) );69 $format ='Y-m-d H:i:s'; 65 70 case 'timestamp': 66 return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );71 $format = 'U'; 67 72 default: 68 return ( $gmt ) ? date( $type ) : date( $type, time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );73 $format = $type; 69 74 } 75 76 if ( $gmt ) { 77 $timezone = timezone_open( 'UTC' ); 78 } else { 79 $timezone = wp_get_site_timezone(); 80 } 81 82 $datetime = date_create( 'now', $timezone ); 83 return $datetime->format( $format ); 70 84 } 71 85 72 86 /** 87 * Creates a `DateTimeZone` object for the site's timezone. 88 * 89 * This function determines the site timezone as follows: 90 * 91 * - If the site uses a timezone identifier (i.e., 'timezone_string' option is set), 92 * that is used. 93 * - If that's not set, we make up an identifier based on the 'gmt_offset'. 94 * - If the GMT offset is 0, or the identifier is invalid, UTC is used. 95 * 96 * @see https://wordpress.stackexchange.com/a/198453/27757 97 * @see https://us.php.net/manual/en/timezones.others.php 98 * 99 * @since 4.8.0 100 * 101 * @return DateTimeZone The site's timezone. 102 */ 103 function wp_get_site_timezone() { 104 $timezone_string = get_option( 'timezone_string' ); 105 106 // A direct offset may be used instead of a timezone identifier. 107 if ( empty( $timezone_string ) ) { 108 $offset = get_option( 'gmt_offset' ); 109 110 if ( empty( $offset ) ) { 111 $timezone_string = 'UTC'; 112 } else { 113 $hours = (int) $offset; 114 $minutes = ( $offset - floor( $offset ) ) * 60; 115 $timezone_string = sprintf( '%+03d:%02d', $hours, $minutes ); 116 } 117 } 118 119 return new DateTimeZone( $timezone_string ); 120 } 121 122 /** 73 123 * Retrieve the date in localized format, based on timestamp. 74 124 * 75 125 * If the locale specifies the locale month and weekday, then the locale will