Use formatTime() for timestamps
Replace the time formatting in notifications and events with the new utility method - this makes sure that all times are now following the clock-format setting and use LC_TIME. https://bugzilla.gnome.org/show_bug.cgi?id=745111
This commit is contained in:
parent
ebf132770e
commit
1c36ade125
@ -32,9 +32,6 @@ const DEFAULT_EXPAND_LINES = 6;
|
||||
const gtk30_ = Gettext_gtk30.gettext;
|
||||
const NC_ = function(context, str) { return context + '\u0004' + str; };
|
||||
|
||||
// in org.gnome.desktop.interface
|
||||
const CLOCK_FORMAT_KEY = 'clock-format';
|
||||
|
||||
function _sameYear(dateA, dateB) {
|
||||
return (dateA.getYear() == dateB.getYear());
|
||||
}
|
||||
@ -71,7 +68,7 @@ function _getEndOfDay(date) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
function _formatEventTime(event, clockFormat, periodBegin, periodEnd) {
|
||||
function _formatEventTime(event, periodBegin, periodEnd) {
|
||||
let ret;
|
||||
let allDay = (event.allDay || (event.date <= periodBegin && event.end >= periodEnd));
|
||||
if (allDay) {
|
||||
@ -81,22 +78,7 @@ function _formatEventTime(event, clockFormat, periodBegin, periodEnd) {
|
||||
ret = C_("event list time", "All Day");
|
||||
} else {
|
||||
let date = event.date >= periodBegin ? event.date : event.end;
|
||||
switch (clockFormat) {
|
||||
case '24h':
|
||||
/* Translators: Shown in calendar event list, if 24h format,
|
||||
\u2236 is a ratio character, similar to : */
|
||||
ret = date.toLocaleFormat(C_("event list time", "%H\u2236%M"));
|
||||
break;
|
||||
|
||||
default:
|
||||
/* explicit fall-through */
|
||||
case '12h':
|
||||
/* Translators: Shown in calendar event list, if 12h format,
|
||||
\u2236 is a ratio character, similar to : and \u2009 is
|
||||
a thin space */
|
||||
ret = date.toLocaleFormat(C_("event list time", "%l\u2236%M\u2009%p"));
|
||||
break;
|
||||
}
|
||||
ret = Util.formatTime(date, { timeOnly: true });
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@ -1480,10 +1462,9 @@ const EventsSection = new Lang.Class({
|
||||
let periodEnd = _getEndOfDay(this._date);
|
||||
let events = this._eventSource.getEvents(periodBegin, periodEnd);
|
||||
|
||||
let clockFormat = this._desktopSettings.get_string(CLOCK_FORMAT_KEY);
|
||||
for (let i = 0; i < events.length; i++) {
|
||||
let event = events[i];
|
||||
let title = _formatEventTime(event, clockFormat, periodBegin, periodEnd);
|
||||
let title = _formatEventTime(event, periodBegin, periodEnd);
|
||||
|
||||
let rtl = this.actor.get_text_direction() == Clutter.TextDirection.RTL;
|
||||
if (event.date < periodBegin && !event.allDay) {
|
||||
@ -1593,7 +1574,7 @@ const NotificationSection = new Lang.Class({
|
||||
_onNotificationAdded: function(source, notification) {
|
||||
let message = new NotificationMessage(notification);
|
||||
|
||||
let time = new Date().toLocaleFormat(C_("event list time", "%H\u2236%M"));
|
||||
let time = Util.formatTime(new Date());
|
||||
message.setSecondaryActor(new St.Label({ style_class: 'event-time',
|
||||
x_align: Clutter.ActorAlign.END,
|
||||
text: time }));
|
||||
|
@ -17,6 +17,7 @@ const Main = imports.ui.main;
|
||||
const MessageTray = imports.ui.messageTray;
|
||||
const Params = imports.misc.params;
|
||||
const PopupMenu = imports.ui.popupMenu;
|
||||
const Util = imports.misc.util;
|
||||
|
||||
// See Notification.appendMessage
|
||||
const SCROLLBACK_IMMEDIATE_TIME = 3 * 60; // 3 minutes
|
||||
@ -30,8 +31,6 @@ const SCROLLBACK_HISTORY_LINES = 10;
|
||||
// See Notification._onEntryChanged
|
||||
const COMPOSING_STOP_TIMEOUT = 5;
|
||||
|
||||
const CLOCK_FORMAT_KEY = 'clock-format';
|
||||
|
||||
const NotificationDirection = {
|
||||
SENT: 'chat-sent',
|
||||
RECEIVED: 'chat-received'
|
||||
@ -746,94 +745,13 @@ const ChatNotification = new Lang.Class({
|
||||
this._filterMessages();
|
||||
},
|
||||
|
||||
_formatTimestamp: function(date) {
|
||||
let now = new Date();
|
||||
|
||||
var daysAgo = (now.getTime() - date.getTime()) / (24 * 60 * 60 * 1000);
|
||||
|
||||
let format;
|
||||
|
||||
let desktopSettings = new Gio.Settings({ schema_id: 'org.gnome.desktop.interface' });
|
||||
let clockFormat = desktopSettings.get_string(CLOCK_FORMAT_KEY);
|
||||
let hasAmPm = date.toLocaleFormat('%p') != '';
|
||||
|
||||
if (clockFormat == '24h' || !hasAmPm) {
|
||||
// Show only the time if date is on today
|
||||
if(daysAgo < 1){
|
||||
/* Translators: Time in 24h format */
|
||||
format = N_("%H\u2236%M");
|
||||
}
|
||||
// Show the word "Yesterday" and time if date is on yesterday
|
||||
else if(daysAgo <2){
|
||||
/* Translators: this is the word "Yesterday" followed by a
|
||||
time string in 24h format. i.e. "Yesterday, 14:30" */
|
||||
// xgettext:no-c-format
|
||||
format = N_("Yesterday, %H\u2236%M");
|
||||
}
|
||||
// Show a week day and time if date is in the last week
|
||||
else if (daysAgo < 7) {
|
||||
/* Translators: this is the week day name followed by a time
|
||||
string in 24h format. i.e. "Monday, 14:30" */
|
||||
// xgettext:no-c-format
|
||||
format = N_("%A, %H\u2236%M");
|
||||
|
||||
} else if (date.getYear() == now.getYear()) {
|
||||
/* Translators: this is the month name and day number
|
||||
followed by a time string in 24h format.
|
||||
i.e. "May 25, 14:30" */
|
||||
// xgettext:no-c-format
|
||||
format = N_("%B %d, %H\u2236%M");
|
||||
} else {
|
||||
/* Translators: this is the month name, day number, year
|
||||
number followed by a time string in 24h format.
|
||||
i.e. "May 25 2012, 14:30" */
|
||||
// xgettext:no-c-format
|
||||
format = N_("%B %d %Y, %H\u2236%M");
|
||||
}
|
||||
} else {
|
||||
// Show only the time if date is on today
|
||||
if(daysAgo < 1){
|
||||
/* Translators: Time in 12h format */
|
||||
format = N_("%l\u2236%M %p");
|
||||
}
|
||||
// Show the word "Yesterday" and time if date is on yesterday
|
||||
else if(daysAgo <2){
|
||||
/* Translators: this is the word "Yesterday" followed by a
|
||||
time string in 12h format. i.e. "Yesterday, 2:30 pm" */
|
||||
// xgettext:no-c-format
|
||||
format = N_("Yesterday, %l\u2236%M %p");
|
||||
}
|
||||
// Show a week day and time if date is in the last week
|
||||
else if (daysAgo < 7) {
|
||||
/* Translators: this is the week day name followed by a time
|
||||
string in 12h format. i.e. "Monday, 2:30 pm" */
|
||||
// xgettext:no-c-format
|
||||
format = N_("%A, %l\u2236%M %p");
|
||||
|
||||
} else if (date.getYear() == now.getYear()) {
|
||||
/* Translators: this is the month name and day number
|
||||
followed by a time string in 12h format.
|
||||
i.e. "May 25, 2:30 pm" */
|
||||
// xgettext:no-c-format
|
||||
format = N_("%B %d, %l\u2236%M %p");
|
||||
} else {
|
||||
/* Translators: this is the month name, day number, year
|
||||
number followed by a time string in 12h format.
|
||||
i.e. "May 25 2012, 2:30 pm"*/
|
||||
// xgettext:no-c-format
|
||||
format = N_("%B %d %Y, %l\u2236%M %p");
|
||||
}
|
||||
}
|
||||
return date.toLocaleFormat(Shell.util_translate_time_string(format));
|
||||
},
|
||||
|
||||
appendTimestamp: function() {
|
||||
this._timestampTimeoutId = 0;
|
||||
|
||||
let lastMessageTime = this._history[0].time;
|
||||
let lastMessageDate = new Date(lastMessageTime * 1000);
|
||||
|
||||
let timeLabel = new St.Label({ text: this._formatTimestamp(lastMessageDate),
|
||||
let timeLabel = new St.Label({ text: Util.formatTime(lastMessageDate),
|
||||
style_class: 'chat-meta-message',
|
||||
x_expand: true,
|
||||
y_expand: true,
|
||||
|
Loading…
Reference in New Issue
Block a user