@@ -15,21 +15,25 @@
1515 *
1616 */
1717
18+// Local
1819#include "relativetimeformatter.h"
1920
21+// Qt
2022#include <QDateTime>
2123
24+// Other
2225#include <glib.h>
26+#include <glib/gi18n.h>
2327#include <locale.h>
2428#include <langinfo.h>
25−#include <libintl.h>
29+#include <string.h>
2630
2731RelativeTimeFormatter::RelativeTimeFormatter(QObject *parent)
2832 : GDateTimeFormatter(parent)
2933{
3034}
3135
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
3337 time or 12-hour time */
3438gboolean
3539is_locale_12h(void)
@@ -45,15 +49,15 @@ is_locale_12h(void)
4549 return TRUE;
4650}
4751
48−
4952typedef enum
5053{
51− DATE_PROXIMITY_TODAY,
5254 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,
5459 DATE_PROXIMITY_FAR
55−}
56−date_proximity_t;
60+} date_proximity_t;
5761
5862static date_proximity_t
5963getDateProximity(GDateTime* now, GDateTime* time)
@@ -69,44 +73,68 @@ getDateProximity(GDateTime* now, GDateTime* time)
6973 return DATE_PROXIMITY_TODAY;
7074 }
7175
72− // does it happen tomorrow?
76+ // did it happen yesterday?
7377 GDateTime* tomorrow = g_date_time_add_days(now, -1);
7478 gint tom_year, tom_month, tom_day;
7579 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;
7880 g_date_time_unref(tomorrow);
81+ if ((tom_year == time_year) && (tom_month == time_month) && (tom_day == time_day)) {
82+ return DATE_PROXIMITY_YESTERDAY;
83+ }
84+
85+ // does it happen tomorrow?
86+ if (prox == DATE_PROXIMITY_FAR)
87+ {
88+ GDateTime* tomorrow = g_date_time_add_days(now, 1);
89+
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;
95+ }
96+ }
7997
8098 // does it happen this week?
8199 if (prox == DATE_PROXIMITY_FAR) {
82− GDateTime* week = g_date_time_add_days(now, -6);
83− GDateTime* week_bound = g_date_time_new_local(g_date_time_get_year(week),
84− g_date_time_get_month(week),
85− g_date_time_get_day_of_month(week),
86− 23, 59, 59.9);
87−
88− if (g_date_time_compare(time, week_bound) >= 0)
89− prox = DATE_PROXIMITY_WEEK;
100+ if (g_date_time_compare(time, now) < 0) {
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),
105+ 0, 0, 0);
106+ if (g_date_time_compare(time, last_week_bound) >= 0)
107+ prox = DATE_PROXIMITY_LAST_WEEK;
108+
109+ g_date_time_unref(last_week);
110+ g_date_time_unref(last_week_bound);
111+ } else {
112+ GDateTime* next_week = g_date_time_add_days(now, 6);
113+ GDateTime* next_week_bound = g_date_time_new_local(g_date_time_get_year(next_week),
114+ g_date_time_get_month(next_week),
115+ g_date_time_get_day_of_month(next_week),
116+ 23, 59, 59.9);
117+ if (g_date_time_compare(time, next_week_bound) <= 0)
118+ prox = DATE_PROXIMITY_NEXT_WEEK;
119+
120+ g_date_time_unref(next_week);
121+ g_date_time_unref(next_week_bound);
122+ }
90123
91− g_date_time_unref(week_bound);
92− g_date_time_unref(week);
93124 }
94125
95− return DATE_PROXIMITY_FAR;
126+ return prox;
96127}
97128
98129/**
130+ * _ a time yesterday should be shown as (e.g. “Yesterday 3:55 PM”)
99131 * _ 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”)
101133 * _ a time any other day this week should be shown as the short version of the
102134 * 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
105135 * weekday (e.g. “Friday”)
106136 * _ a time after this week should be shown as the short version of the day,
107137 * 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”).
110138 * _ in addition, when presenting the times of upcoming events, the time should
111139 * be followed by the timezone if it is different from the one the computer
112140 * 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,
121149
122150 if (is_locale_12h()) {
123151 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"));
158+ break;
159+
124160 case DATE_PROXIMITY_TODAY:
125161 /* Translators, please edit/rearrange these strftime(3) tokens to suit your locale!
126162 This format string is used for showing, on a 12-hour clock, times that happened today.
127163 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"));
129165 break;
130166
131− case DATE_PROXIMITY_YESTERDAY:
167+ case DATE_PROXIMITY_TOMORROW:
132168 /* 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.
134170 (\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" */
136− g_string_assign (ret, gettext("Yesterday\u2003%l:%M %p"));
171+ en_US example: "Tomorrow\u2003%l:%M %p" --> "Tomorrow 1:00 PM" */
172+ g_string_assign (ret, dgettext("indicator-datetime", "Tomorrow\u2003%l:%M %p"));
137173 break;
138174
139− case DATE_PROXIMITY_WEEK:
175+ case DATE_PROXIMITY_LAST_WEEK:
176+ case DATE_PROXIMITY_NEXT_WEEK:
140177 /* Translators, please edit/rearrange these strftime(3) tokens to suit your locale!
141178 This format string is used for showing, on a 12-hour clock, times that happened in the last week.
142179 (\u2003 is a unicode em space which is slightly wider than a normal space.)
143180 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"));
145182 break;
146183
147184 case DATE_PROXIMITY_FAR:
@@ -150,32 +187,42 @@ char* generate_full_format_string_at_time (GDateTime* now,
150187 (\u2003 is a unicode em space which is slightly wider than a normal space.)
151188 en_US example: "%a %d %b\u2003%l:%M %p" --> "Fri Oct 31 1:00 PM"
152189 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"));
154191 break;
155192 }
156193 } else {
157194 switch (prox) {
195+
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"));
202+ break;
203+
158204 case DATE_PROXIMITY_TODAY:
159205 /* Translators, please edit/rearrange these strftime(3) tokens to suit your locale!
160206 This format string is used for showing, on a 24-hour clock, times that happened today.
161207 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"));
163209 break;
164210
165− case DATE_PROXIMITY_YESTERDAY:
211+ case DATE_PROXIMITY_TOMORROW:
166212 /* 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.
168214 (\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" */
170− g_string_assign (ret, gettext("Yesterday\u2003%H:%M"));
215+ en_US example: "Tomorrow\u2003%l:%M %p" --> "Tomorrow 13:00" */
216+ g_string_assign (ret, dgettext("indicator-datetime", "Tomorrow\u2003%H:%M"));
171217 break;
172218
173− case DATE_PROXIMITY_WEEK:
219+ case DATE_PROXIMITY_LAST_WEEK:
220+ case DATE_PROXIMITY_NEXT_WEEK:
174221 /* Translators, please edit/rearrange these strftime(3) tokens to suit your locale!
175222 This format string is used for showing, on a 24-hour clock, times that happened in the last week.
176223 (\u2003 is a unicode em space which is slightly wider than a normal space.)
177224 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"));
179226 break;
180227
181228 case DATE_PROXIMITY_FAR:
@@ -184,7 +231,7 @@ char* generate_full_format_string_at_time (GDateTime* now,
184231 (\u2003 is a unicode em space which is slightly wider than a normal space.)
185232 en_US example: "%a %d %b\u2003%H:%M" --> "Fri Oct 31 13:00"
186233 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"));
188235 break;
189236 }
190237 }