Switching to short date headers based on user prefs (and timezone)

This change will allow people to switch between 'May 10' and
'10 May' as requested in bug 47211. It also now corrects for the
user's timezone settings.

Bug: 47211

Change-Id: I7c5eae52857fac2d82ff1cb0b10864a1e1b30b6a
This commit is contained in:
kaldari 2013-06-12 16:36:50 -07:00
parent aa5771bceb
commit 0fd7915801
2 changed files with 10 additions and 25 deletions

View file

@ -159,7 +159,6 @@ $1',
// Special page
'echo-date-today' => 'Today',
'echo-date-yesterday' => 'Yesterday',
'echo-date-header' => '$1 $2',
'echo-load-more-error' => 'An error occurred while fetching more results.',
// Bundle
@ -504,10 +503,6 @@ The new notification count next to notification link, for example: 99+
'echo-date-today' => "The header text for today's notification section.
{{Identical|Today}}",
'echo-date-yesterday' => "The header text for yesterday's notification section",
'echo-date-header' => '{{optional}}
The header text for each notification section which is grouped by date
* $1 is the month, it could be {{msg-mw|january-gen}}, {{msg-mw|february-gen}}, {{msg-mw|march-gen}}, {{msg-mw|april-gen}}, {{msg-mw|may-gen}}, {{msg-mw|june-gen}}, {{msg-mw|july-gen}}, {{msg-mw|august-gen}}, {{msg-mw|september-gen}}, {{msg-mw|october-gen}}, {{msg-mw|november-gen}}, {{msg-mw|december-gen}}
* $2 is the date of a month, eg 21',
'echo-load-more-error' => 'Error message for errors in loading more notifications',
'notification-edit-talk-page-bundle' => 'Bundled message for edit-user-talk notification. Parameters:
* $1 - the username who performs the action, which can be used for gender support

View file

@ -84,38 +84,28 @@ class ApiEchoNotifications extends ApiQueryBase {
}
$timestamp = new MWTimestamp( $row->notification_timestamp );
// Adjust for the user's timezone
$timestamp->offsetForUser( $user );
$timestampUnix = $timestamp->getTimestamp( TS_UNIX );
$timestampMw = $timestamp->getTimestamp( TS_MW );
// start creating date section header
// Start creating date section header
$today = wfTimestamp( TS_MW );
$yesterday = wfTimestamp( TS_MW, wfTimestamp( TS_UNIX, $today ) - 24 * 3600 );
if ( substr( $today, 0, 8 ) === substr( $timestampMw, 0, 8 ) ) {
// 'Today'
$date = wfMessage( 'echo-date-today' )->escaped();
} elseif ( substr( $yesterday, 0, 8 ) === substr( $timestampMw, 0, 8 ) ) {
// 'Yesterday'
$date = wfMessage( 'echo-date-yesterday' )->escaped();
} else {
$month = array(
'01' => 'january-gen',
'02' => 'february-gen',
'03' => 'march-gen',
'04' => 'april-gen',
'05' => 'may-gen',
'06' => 'june-gen',
'07' => 'july-gen',
'08' => 'august-gen',
'09' => 'september-gen',
'10' => 'october-gen',
'11' => 'november-gen',
'12' => 'december-gen'
);
$headerMonth = wfMessage( $month[substr( $timestampMw, 4, 2 )] )->text();
$headerDate = substr( $timestampMw, 6, 2 );
$date = wfMessage( 'echo-date-header' )->params( $headerMonth )->numParams( $headerDate )->escaped();
// 'May 10' or '10 May' (depending on user's date format preference)
$lang = RequestContext::getMain()->getLanguage();
$dateFormat = $lang->getDateFormatString( 'pretty', $user->getDatePreference() ?: 'default' );
$date = $lang->sprintfDate( $dateFormat, $timestampMw );
}
// end creating date section header
// End creating date section header
$thisEvent = array(
'id' => $event->getId(),