@@ -15,21 +15,25 @@
18#include "relativetimeformatter.h"
19#include "relativetimeformatter.h"
20#include <QDateTime>
22#include <QDateTime>
22#include <glib.h>
25#include <glib.h>
26+#include <glib/gi18n.h>
23#include <locale.h>
27#include <locale.h>
24#include <langinfo.h>
28#include <langinfo.h>
25−#include <libintl.h>
29+#include <string.h>
27RelativeTimeFormatter::RelativeTimeFormatter(QObject *parent)
31RelativeTimeFormatter::RelativeTimeFormatter(QObject *parent)
28 : GDateTimeFormatter(parent)
32 : GDateTimeFormatter(parent)
32−/* Check the system locale setting to see if the format is 24-hour
36+ /* Check the system locale setting to see if the format is 24-hour
33 time or 12-hour time */
37 time or 12-hour time */
35is_locale_12h(void)
39is_locale_12h(void)
@@ -45,15 +49,15 @@ is_locale_12h(void)
45 return TRUE;
49 return TRUE;
49typedef enum
52typedef enum
51− DATE_PROXIMITY_TODAY,
52 DATE_PROXIMITY_YESTERDAY,
54 DATE_PROXIMITY_YESTERDAY,
53− DATE_PROXIMITY_WEEK,
55+ DATE_PROXIMITY_TODAY,
56+ DATE_PROXIMITY_TOMORROW,
57+ DATE_PROXIMITY_LAST_WEEK,
58+ DATE_PROXIMITY_NEXT_WEEK,
54 DATE_PROXIMITY_FAR
59 DATE_PROXIMITY_FAR
56−date_proximity_t;
60+} date_proximity_t;
58static date_proximity_t
62static date_proximity_t
59getDateProximity(GDateTime* now, GDateTime* time)
63getDateProximity(GDateTime* now, GDateTime* time)
@@ -69,44 +73,68 @@ getDateProximity(GDateTime* now, GDateTime* time)
69 return DATE_PROXIMITY_TODAY;
73 return DATE_PROXIMITY_TODAY;
72− // does it happen tomorrow?
76+ // did it happen yesterday?
73 GDateTime* tomorrow = g_date_time_add_days(now, -1);
77 GDateTime* tomorrow = g_date_time_add_days(now, -1);
74 gint tom_year, tom_month, tom_day;
78 gint tom_year, tom_month, tom_day;
75 g_date_time_get_ymd(tomorrow, &tom_year, &tom_month, &tom_day);
79 g_date_time_get_ymd(tomorrow, &tom_year, &tom_month, &tom_day);
76− if ((tom_year == time_year) && (tom_month == time_month) && (tom_day == time_day))
77− return DATE_PROXIMITY_YESTERDAY;
78 g_date_time_unref(tomorrow);
80 g_date_time_unref(tomorrow);
81+ if ((tom_year == time_year) && (tom_month == time_month) && (tom_day == time_day)) {
82+ return DATE_PROXIMITY_YESTERDAY;
85+ // does it happen tomorrow?
86+ if (prox == DATE_PROXIMITY_FAR)
88+ GDateTime* tomorrow = g_date_time_add_days(now, 1);
90+ gint tom_year, tom_month, tom_day;
91+ g_date_time_get_ymd(tomorrow, &tom_year, &tom_month, &tom_day);
92+ g_date_time_unref(tomorrow);
93+ if ((tom_year == time_year) && (tom_month == time_month) && (tom_day == time_day)) {
94+ return DATE_PROXIMITY_TOMORROW;
80 // does it happen this week?
98 // does it happen this week?
81 if (prox == DATE_PROXIMITY_FAR) {
99 if (prox == DATE_PROXIMITY_FAR) {
100+ if (g_date_time_compare(time, now) < 0) {
82− GDateTime* week = g_date_time_add_days(now, -6);
101+ GDateTime* last_week = g_date_time_add_days(now, -6);
102+ GDateTime* last_week_bound = g_date_time_new_local(g_date_time_get_year(last_week),
103+ g_date_time_get_month(last_week),
104+ g_date_time_get_day_of_month(last_week),
106+ if (g_date_time_compare(time, last_week_bound) >= 0)
107+ prox = DATE_PROXIMITY_LAST_WEEK;
109+ g_date_time_unref(last_week);
110+ g_date_time_unref(last_week_bound);
112+ GDateTime* next_week = g_date_time_add_days(now, 6);
83− GDateTime* week_bound = g_date_time_new_local(g_date_time_get_year(week),
113+ GDateTime* next_week_bound = g_date_time_new_local(g_date_time_get_year(next_week),
84− g_date_time_get_month(week),
114+ g_date_time_get_month(next_week),
85− g_date_time_get_day_of_month(week),
115+ g_date_time_get_day_of_month(next_week),
86− 23, 59, 59.9);
116+ 23, 59, 59.9);
88− if (g_date_time_compare(time, week_bound) >= 0)
117+ if (g_date_time_compare(time, next_week_bound) <= 0)
89− prox = DATE_PROXIMITY_WEEK;
118+ prox = DATE_PROXIMITY_NEXT_WEEK;
120+ g_date_time_unref(next_week);
121+ g_date_time_unref(next_week_bound);
91− g_date_time_unref(week_bound);
92− g_date_time_unref(week);
95− return DATE_PROXIMITY_FAR;
126+ return prox;
130+ * _ a time yesterday should be shown as (e.g. “Yesterday 3:55 PM”)
99 * _ a time today should be shown as just the time (e.g. “3:55 PM”)
131 * _ a time today should be shown as just the time (e.g. “3:55 PM”)
100− * _ a full-day event today should be shown as “Today”
132+ * _ a time tomorrow should be shown as(e.g. “Tomorrow 3:55 PM”)
101 * _ a time any other day this week should be shown as the short version of the
133 * _ a time any other day this week should be shown as the short version of the
102 * day and time (e.g. “Wed 3:55 PM”)
134 * day and time (e.g. “Wed 3:55 PM”)
103− * _ a full-day event tomorrow should be shown as “Tomorrow”
104− * _ a full-day event another day this week should be shown as the
105 * weekday (e.g. “Friday”)
135 * weekday (e.g. “Friday”)
106 * _ a time after this week should be shown as the short version of the day,
136 * _ a time after this week should be shown as the short version of the day,
107 * date, and time (e.g. “Wed 21 Apr 3:55 PM”)
137 * date, and time (e.g. “Wed 21 Apr 3:55 PM”)
108− * _ a full-day event after this week should be shown as the short version of
109− * the day and date (e.g. “Wed 21 Apr”).
110 * _ in addition, when presenting the times of upcoming events, the time should
138 * _ in addition, when presenting the times of upcoming events, the time should
111 * be followed by the timezone if it is different from the one the computer
139 * be followed by the timezone if it is different from the one the computer
112 * is currently set to. For example, “Wed 3:55 PM UTC−5”.
140 * is currently set to. For example, “Wed 3:55 PM UTC−5”.
@@ -121,27 +149,36 @@ char* generate_full_format_string_at_time (GDateTime* now,
122 if (is_locale_12h()) {
150 if (is_locale_12h()) {
123 switch (prox) {
151 switch (prox) {
152+ case DATE_PROXIMITY_YESTERDAY:
153+ /* Translators, please edit/rearrange these strftime(3) tokens to suit your locale!
154+ This format string is used for showing, on a 12-hour clock, times that happen yesterday.
155+ (\u2003 is a unicode em space which is slightly wider than a normal space.)
156+ en_US example: "Yesterday\u2003%l:%M %p" --> "Tomorrow 1:00 PM" */
157+ g_string_assign (ret, dgettext("indicator-datetime", "Yesterday\u2003%l:%M %p"));
124 case DATE_PROXIMITY_TODAY:
160 case DATE_PROXIMITY_TODAY:
125 /* Translators, please edit/rearrange these strftime(3) tokens to suit your locale!
161 /* Translators, please edit/rearrange these strftime(3) tokens to suit your locale!
126 This format string is used for showing, on a 12-hour clock, times that happened today.
162 This format string is used for showing, on a 12-hour clock, times that happened today.
127 en_US example: "%l:%M %p" --> "1:00 PM" */
163 en_US example: "%l:%M %p" --> "1:00 PM" */
128− g_string_assign (ret, gettext("%l:%M %p"));
164+ g_string_assign (ret, dgettext("indicator-datetime", "%l:%M %p"));
131− case DATE_PROXIMITY_YESTERDAY:
167+ case DATE_PROXIMITY_TOMORROW:
132 /* Translators, please edit/rearrange these strftime(3) tokens to suit your locale!
168 /* Translators, please edit/rearrange these strftime(3) tokens to suit your locale!
133− This format string is used for showing, on a 12-hour clock, times that happen yesterday.
169+ This format string is used for showing, on a 12-hour clock, events/appointments that happen tomorrow.
134 (\u2003 is a unicode em space which is slightly wider than a normal space.)
170 (\u2003 is a unicode em space which is slightly wider than a normal space.)
135− en_US example: "Yesterday\u2003%l:%M %p" --> "Tomorrow 1:00 PM" */
171+ en_US example: "Tomorrow\u2003%l:%M %p" --> "Tomorrow 1:00 PM" */
136− g_string_assign (ret, gettext("Yesterday\u2003%l:%M %p"));
172+ g_string_assign (ret, dgettext("indicator-datetime", "Tomorrow\u2003%l:%M %p"));
139− case DATE_PROXIMITY_WEEK:
175+ case DATE_PROXIMITY_LAST_WEEK:
176+ case DATE_PROXIMITY_NEXT_WEEK:
140 /* Translators, please edit/rearrange these strftime(3) tokens to suit your locale!
177 /* Translators, please edit/rearrange these strftime(3) tokens to suit your locale!
141 This format string is used for showing, on a 12-hour clock, times that happened in the last week.
178 This format string is used for showing, on a 12-hour clock, times that happened in the last week.
142 (\u2003 is a unicode em space which is slightly wider than a normal space.)
179 (\u2003 is a unicode em space which is slightly wider than a normal space.)
143 en_US example: "%a\u2003%l:%M %p" --> "Fri 1:00 PM" */
180 en_US example: "%a\u2003%l:%M %p" --> "Fri 1:00 PM" */
144− g_string_assign (ret, gettext("%a\u2003%l:%M %p"));
181+ g_string_assign (ret, dgettext("indicator-datetime", "%a\u2003%l:%M %p"));
147 case DATE_PROXIMITY_FAR:
184 case DATE_PROXIMITY_FAR:
@@ -150,32 +187,42 @@ char* generate_full_format_string_at_time (GDateTime* now,
150 (\u2003 is a unicode em space which is slightly wider than a normal space.)
187 (\u2003 is a unicode em space which is slightly wider than a normal space.)
151 en_US example: "%a %d %b\u2003%l:%M %p" --> "Fri Oct 31 1:00 PM"
188 en_US example: "%a %d %b\u2003%l:%M %p" --> "Fri Oct 31 1:00 PM"
152 en_GB example: "%a %b %d\u2003%l:%M %p" --> "Fri 31 Oct 1:00 PM" */
189 en_GB example: "%a %b %d\u2003%l:%M %p" --> "Fri 31 Oct 1:00 PM" */
153− g_string_assign (ret, gettext("%a %d %b\u2003%l:%M %p"));
190+ g_string_assign (ret, dgettext("indicator-datetime", "%a %d %b\u2003%l:%M %p"));
157 switch (prox) {
194 switch (prox) {
196+ case DATE_PROXIMITY_YESTERDAY:
197+ /* Translators, please edit/rearrange these strftime(3) tokens to suit your locale!
198+ This format string is used for showing, on a 24-hour clock, times that happen yesterday.
199+ (\u2003 is a unicode em space which is slightly wider than a normal space.)
200+ en_US example: "Yesterday\u2003%l:%M %p" --> "Tomorrow 13:00" */
201+ g_string_assign (ret, dgettext("indicator-datetime", "Yesterday\u2003%H:%M"));
158 case DATE_PROXIMITY_TODAY:
204 case DATE_PROXIMITY_TODAY:
159 /* Translators, please edit/rearrange these strftime(3) tokens to suit your locale!
205 /* Translators, please edit/rearrange these strftime(3) tokens to suit your locale!
160 This format string is used for showing, on a 24-hour clock, times that happened today.
206 This format string is used for showing, on a 24-hour clock, times that happened today.
161 en_US example: "%H:%M" --> "13:00" */
207 en_US example: "%H:%M" --> "13:00" */
162− g_string_assign (ret, gettext("%H:%M"));
208+ g_string_assign (ret, dgettext("indicator-datetime", "%H:%M"));
165− case DATE_PROXIMITY_YESTERDAY:
211+ case DATE_PROXIMITY_TOMORROW:
166 /* Translators, please edit/rearrange these strftime(3) tokens to suit your locale!
212 /* Translators, please edit/rearrange these strftime(3) tokens to suit your locale!
167− This format string is used for showing, on a 24-hour clock, times that happen yesterday.
213+ This format string is used for showing, on a 24-hour clock, events/appointments that happen tomorrow.
168 (\u2003 is a unicode em space which is slightly wider than a normal space.)
214 (\u2003 is a unicode em space which is slightly wider than a normal space.)
169− en_US example: "Yesterday\u2003%l:%M %p" --> "Tomorrow 13:00" */
215+ en_US example: "Tomorrow\u2003%l:%M %p" --> "Tomorrow 13:00" */
170− g_string_assign (ret, gettext("Yesterday\u2003%H:%M"));
216+ g_string_assign (ret, dgettext("indicator-datetime", "Tomorrow\u2003%H:%M"));
173− case DATE_PROXIMITY_WEEK:
219+ case DATE_PROXIMITY_LAST_WEEK:
220+ case DATE_PROXIMITY_NEXT_WEEK:
174 /* Translators, please edit/rearrange these strftime(3) tokens to suit your locale!
221 /* Translators, please edit/rearrange these strftime(3) tokens to suit your locale!
175 This format string is used for showing, on a 24-hour clock, times that happened in the last week.
222 This format string is used for showing, on a 24-hour clock, times that happened in the last week.
176 (\u2003 is a unicode em space which is slightly wider than a normal space.)
223 (\u2003 is a unicode em space which is slightly wider than a normal space.)
177 en_US example: "%a\u2003%H:%M" --> "Fri 13:00" */
224 en_US example: "%a\u2003%H:%M" --> "Fri 13:00" */
178− g_string_assign (ret, gettext("%a\u2003%H:%M"));
225+ g_string_assign (ret, dgettext("indicator-datetime", "%a\u2003%H:%M"));
181 case DATE_PROXIMITY_FAR:
228 case DATE_PROXIMITY_FAR:
@@ -184,7 +231,7 @@ char* generate_full_format_string_at_time (GDateTime* now,
184 (\u2003 is a unicode em space which is slightly wider than a normal space.)
231 (\u2003 is a unicode em space which is slightly wider than a normal space.)
185 en_US example: "%a %d %b\u2003%H:%M" --> "Fri Oct 31 13:00"
232 en_US example: "%a %d %b\u2003%H:%M" --> "Fri Oct 31 13:00"
186 en_GB example: "%a %b %d\u2003%H:%M" --> "Fri 31 Oct 13:00" */
233 en_GB example: "%a %b %d\u2003%H:%M" --> "Fri 31 Oct 13:00" */
187− g_string_assign (ret, gettext("%a %d %b\u2003%H:%M"));
234+ g_string_assign (ret, dgettext("indicator-datetime", "%a %d %b\u2003%H:%M"));