date_i18n() fixes. Props nbachiyski. fixes #8153

git-svn-id: http://svn.automattic.com/wordpress/trunk@9742 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-11-17 21:31:46 +00:00
parent b32aa16ec3
commit 222159d16c
2 changed files with 21 additions and 12 deletions

View File

@ -121,7 +121,7 @@ foreach ( $offset_range as $offset ) {
<?php _e('hours') ?> <?php _e('hours') ?>
<span id="utc-time"><?php printf(__('<abbr title="Coordinated Universal Time">UTC</abbr> time is <code>%s</code>'), date_i18n(__('Y-m-d G:i:s'), false, 'gmt')); ?></span> <span id="utc-time"><?php printf(__('<abbr title="Coordinated Universal Time">UTC</abbr> time is <code>%s</code>'), date_i18n(__('Y-m-d G:i:s'), false, 'gmt')); ?></span>
<?php if ($current_offset) : ?> <?php if ($current_offset) : ?>
<span id="local-time"><?php printf(__('UTC %1$s is <code>%2$s</code>'), $current_offset_name, date_i18n(__('Y-m-d G:i:s'), current_time('timestamp'), 'gmt')); ?></span> <span id="local-time"><?php printf(__('UTC %1$s is <code>%2$s</code>'), $current_offset_name, date_i18n(__('Y-m-d G:i:s'))); ?></span>
<?php endif; ?> <?php endif; ?>
<br/> <br/>
<span class="setting-description"><?php _e('Unfortunately, you have to manually update this for Daylight Savings Time. Lame, we know, but will be fixed in the future.'); ?></span> <span class="setting-description"><?php _e('Unfortunately, you have to manually update this for Daylight Savings Time. Lame, we know, but will be fixed in the future.'); ?></span>
@ -148,12 +148,12 @@ foreach ( $offset_range as $offset ) {
echo " checked='checked'"; echo " checked='checked'";
$custom = FALSE; $custom = FALSE;
} }
echo ' /> ' . date_i18n( $format, current_time('timestamp'), 'gmt' ) . "</label><br />\n"; echo ' /> ' . date_i18n( $format ) . "</label><br />\n";
} }
echo ' <label><input type="radio" name="date_format" id="date_format_custom_radio" value="\c\u\s\t\o\m"'; echo ' <label><input type="radio" name="date_format" id="date_format_custom_radio" value="\c\u\s\t\o\m"';
checked( $custom, TRUE ); checked( $custom, TRUE );
echo '/> ' . __('Custom:') . ' </label><input type="text" name="date_format_custom" value="' . attribute_escape( get_option('date_format') ) . '" class="small-text" /> ' . date_i18n( get_option('date_format'), current_time('timestamp'), 'gmt' ) . "\n"; echo '/> ' . __('Custom:') . ' </label><input type="text" name="date_format_custom" value="' . attribute_escape( get_option('date_format') ) . '" class="small-text" /> ' . date_i18n( get_option('date_format') ) . "\n";
echo "\t<p>" . __('<a href="http://codex.wordpress.org/Formatting_Date_and_Time">Documentation on date formatting</a>. Click "Save Changes" to update sample output.') . "</p>\n"; echo "\t<p>" . __('<a href="http://codex.wordpress.org/Formatting_Date_and_Time">Documentation on date formatting</a>. Click "Save Changes" to update sample output.') . "</p>\n";
?> ?>
@ -180,12 +180,12 @@ foreach ( $offset_range as $offset ) {
echo " checked='checked'"; echo " checked='checked'";
$custom = FALSE; $custom = FALSE;
} }
echo ' /> ' . date_i18n( $format, current_time('timestamp'), 'gmt' ) . "</label><br />\n"; echo ' /> ' . date_i18n( $format ) . "</label><br />\n";
} }
echo ' <label><input type="radio" name="time_format" id="time_format_custom_radio" value="\c\u\s\t\o\m"'; echo ' <label><input type="radio" name="time_format" id="time_format_custom_radio" value="\c\u\s\t\o\m"';
checked( $custom, TRUE ); checked( $custom, TRUE );
echo '/> ' . __('Custom:') . ' </label><input type="text" name="time_format_custom" value="' . attribute_escape( get_option('time_format') ) . '" class="small-text" /> ' . date_i18n( get_option('time_format'), current_time('timestamp'), 'gmt' ) . "\n"; echo '/> ' . __('Custom:') . ' </label><input type="text" name="time_format_custom" value="' . attribute_escape( get_option('time_format') ) . '" class="small-text" /> ' . date_i18n( get_option('time_format') ) . "\n";
?> ?>
</fieldset> </fieldset>
</td> </td>

View File

@ -116,16 +116,25 @@ function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) {
global $wp_locale; global $wp_locale;
$i = $unixtimestamp; $i = $unixtimestamp;
// Sanity check for PHP 5.1.0- // Sanity check for PHP 5.1.0-
if ( false === $i || intval($i) < 0 ) if ( false === $i || intval($i) < 0 ) {
$i = time(); if ( ! $gmt )
$i = current_time( 'timestamp' );
else
$i = time();
// we should not let date() interfere with our
// specially computed timestamp
$gmt = true;
}
$datefunc = $gmt? 'gmdate' : 'date';
if ( ( !empty( $wp_locale->month ) ) && ( !empty( $wp_locale->weekday ) ) ) { if ( ( !empty( $wp_locale->month ) ) && ( !empty( $wp_locale->weekday ) ) ) {
$datemonth = $wp_locale->get_month( date( 'm', $i ) ); $datemonth = $wp_locale->get_month( $datefunc( 'm', $i ) );
$datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth ); $datemonth_abbrev = $wp_locale->get_month_abbrev( $datemonth );
$dateweekday = $wp_locale->get_weekday( date( 'w', $i ) ); $dateweekday = $wp_locale->get_weekday( $datefunc( 'w', $i ) );
$dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday ); $dateweekday_abbrev = $wp_locale->get_weekday_abbrev( $dateweekday );
$datemeridiem = $wp_locale->get_meridiem( date( 'a', $i ) ); $datemeridiem = $wp_locale->get_meridiem( $datefunc( 'a', $i ) );
$datemeridiem_capital = $wp_locale->get_meridiem( date( 'A', $i ) ); $datemeridiem_capital = $wp_locale->get_meridiem( $datefunc( 'A', $i ) );
$dateformatstring = ' '.$dateformatstring; $dateformatstring = ' '.$dateformatstring;
$dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring ); $dateformatstring = preg_replace( "/([^\\\])D/", "\\1" . backslashit( $dateweekday_abbrev ), $dateformatstring );
$dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring ); $dateformatstring = preg_replace( "/([^\\\])F/", "\\1" . backslashit( $datemonth ), $dateformatstring );
@ -136,7 +145,7 @@ function date_i18n( $dateformatstring, $unixtimestamp = false, $gmt = false ) {
$dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 ); $dateformatstring = substr( $dateformatstring, 1, strlen( $dateformatstring ) -1 );
} }
$j = $gmt? @gmdate( $dateformatstring, $i ) : @date( $dateformatstring, $i ); $j = @$datefunc( $dateformatstring, $i );
return $j; return $j;
} }