on xenial help sign in
Fixed up relative time formatting & tests
bdfb1b0Nick Dedekind
plugins/Utils/relativetimeformatter.cpp+89−42
@@ -15,21 +15,25 @@
15 *
15 *
16 */
16 */
17
17
18+// Local
18#include "relativetimeformatter.h"
19#include "relativetimeformatter.h"
19
20
21+// Qt
20#include <QDateTime>
22#include <QDateTime>
21
23
24+// Other
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>
26
30
27RelativeTimeFormatter::RelativeTimeFormatter(QObject *parent)
31RelativeTimeFormatter::RelativeTimeFormatter(QObject *parent)
28 : GDateTimeFormatter(parent)
32 : GDateTimeFormatter(parent)
29{
33{
30}
34}
31
35
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 */
34gboolean
38gboolean
35is_locale_12h(void)
39is_locale_12h(void)
@@ -45,15 +49,15 @@ is_locale_12h(void)
45 return TRUE;
49 return TRUE;
46}
50}
47
51
48−
49typedef enum
52typedef enum
50{
53{
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
55−}
56−date_proximity_t;
60+} date_proximity_t;
57
61
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;
70 }
74 }
71
75
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;
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+ }
79
97
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),
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);
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);
87−
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;
119+
120+ g_date_time_unref(next_week);
121+ g_date_time_unref(next_week_bound);
122+ }
90
123
91− g_date_time_unref(week_bound);
92− g_date_time_unref(week);
93 }
124 }
94
125
95− return DATE_PROXIMITY_FAR;
126+ return prox;
96}
127}
97
128
98/**
129/**
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,
121
149
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"));
158+ break;
159+
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"));
129 break;
165 break;
130
166
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"));
137 break;
173 break;
138
174
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"));
145 break;
182 break;
146
183
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"));
154 break;
191 break;
155 }
192 }
156 } else {
193 } else {
157 switch (prox) {
194 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+
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"));
163 break;
209 break;
164
210
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"));
171 break;
217 break;
172
218
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"));
179 break;
226 break;
180
227
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"));
188 break;
235 break;
189 }
236 }
190 }
237 }
plugins/Utils/timeformatter.cpp+7−1
@@ -121,6 +121,12 @@ TimeFormatter::TimeFormatter(QObject *parent): QObject(parent)
121 g_bus_get (G_BUS_TYPE_SYSTEM, priv->cancellable, got_bus, priv);
121 g_bus_get (G_BUS_TYPE_SYSTEM, priv->cancellable, got_bus, priv);
122}
122}
123
123
124+TimeFormatter::TimeFormatter(const QString &initialFormat, QObject *parent): TimeFormatter(parent)
125+{
126+ priv->format = initialFormat;
127+}
128+
129+
124TimeFormatter::~TimeFormatter()
130TimeFormatter::~TimeFormatter()
125{
131{
126 if (priv->system_bus) {
132 if (priv->system_bus) {
@@ -177,7 +183,7 @@ QString TimeFormatter::formatTime() const
177}
183}
178
184
179GDateTimeFormatter::GDateTimeFormatter(QObject* parent)
185GDateTimeFormatter::GDateTimeFormatter(QObject* parent)
180−: TimeFormatter(parent)
186+: TimeFormatter("%d-%m-%Y %I:%M%p", parent)
181{
187{
182}
188}
183
189
plugins/Utils/timeformatter.h+2
@@ -48,6 +48,8 @@ Q_SIGNALS:
48 void timeChanged(qint64 time);
48 void timeChanged(qint64 time);
49
49
50protected:
50protected:
51+ TimeFormatter(const QString &initialFormat, QObject *parent = 0);
52+
51 virtual QString formatTime() const;
53 virtual QString formatTime() const;
52
54
53private:
55private:
tests/plugins/Utils/CMakeLists.txt+2−2
@@ -11,8 +11,8 @@ macro(run_tests)
11 -o ${CMAKE_BINARY_DIR}/${_test}.xml,xunitxml
11 -o ${CMAKE_BINARY_DIR}/${_test}.xml,xunitxml
12 -o -,txt)
12 -o -,txt)
13 add_test(NAME ${_test} COMMAND ${testCommand})
13 add_test(NAME ${_test} COMMAND ${testCommand})
14− set_tests_properties(${_test} PROPERTIES ENVIRONMENT "LC_ALL=C")
14+ set_tests_properties(${_test} PROPERTIES ENVIRONMENT "LC_ALL=C.UTF-8")
15− add_custom_target(${_test} env "LC_ALL=C" ${testCommand})
15+ add_custom_target(${_test} env "LC_ALL=C.UTF-8" ${testCommand})
16 add_executable(${_test}Exec ${_test}.cpp modeltest.cpp)
16 add_executable(${_test}Exec ${_test}.cpp modeltest.cpp)
17 qt5_use_modules(${_test}Exec Test Core Qml)
17 qt5_use_modules(${_test}Exec Test Core Qml)
18 target_link_libraries(${_test}Exec
18 target_link_libraries(${_test}Exec
tests/plugins/Utils/timeformattertest.cpp+104−7
@@ -17,6 +17,9 @@
17 */
17 */
18
18
19#include "timeformatter.h"
19#include "timeformatter.h"
20+#include "relativetimeformatter.h"
21+
22+#include <locale.h>
20
23
21#include <QtTest>
24#include <QtTest>
22#include <QDebug>
25#include <QDebug>
@@ -24,8 +27,24 @@
24class TimeFormatterTest : public QObject
27class TimeFormatterTest : public QObject
25{
28{
26 Q_OBJECT
29 Q_OBJECT
27−private Q_SLOTS:
30+private:
31+ void addTestData(QList<int> daysToAdd = QList<int>()) {
32+ QTest::addColumn<QDateTime>("time");
33+
34+ Q_FOREACH(int dayToAdd, daysToAdd) {
35+ QDateTime time = QDateTime::currentDateTime().addDays(dayToAdd);
36+ QDateTime am(time); am.setTime(QTime(1, 1, 1));
37+ QDateTime midday(time); midday.setTime(QTime(12, 0, 0));
38+ QDateTime pm(time); pm.setTime(QTime(17, 59, 59));
39+
40+ QTest::newRow(QString("%1day-am").arg(dayToAdd).toLatin1()) << am;
41+ QTest::newRow(QString("%1day-midday").arg(dayToAdd).toLatin1()) << midday;
42+ QTest::newRow(QString("%1day-pm").arg(dayToAdd).toLatin1()) << pm;
43+ }
28
44
45+ }
46+
47+private Q_SLOTS:
29 void initTestCase()
48 void initTestCase()
30 {
49 {
31 setenv("UNITY_TEST_ENV", "1", 1);
50 setenv("UNITY_TEST_ENV", "1", 1);
@@ -36,12 +55,12 @@ private Q_SLOTS:
36 unsetenv("UNITY_TEST_ENV");
55 unsetenv("UNITY_TEST_ENV");
37 }
56 }
38
57
39− void testFormat()
58+ void testTimeFormatter_Format_data() { addTestData(QList<int>() << 0); }
59+ void testTimeFormatter_Format()
40 {
60 {
61+ QFETCH(QDateTime, time);
41 const QString format = "hh:mm dd.MM.yy";
62 const QString format = "hh:mm dd.MM.yy";
42
63
43− QDateTime time = QDateTime::currentDateTime();
44−
45 TimeFormatter formatter;
64 TimeFormatter formatter;
46 formatter.setTime(time.toMSecsSinceEpoch() * 1000);
65 formatter.setTime(time.toMSecsSinceEpoch() * 1000);
47 formatter.setFormat(format);
66 formatter.setFormat(format);
@@ -49,18 +68,96 @@ private Q_SLOTS:
49 QCOMPARE(formatter.timeString(), time.toString(format));
68 QCOMPARE(formatter.timeString(), time.toString(format));
50 }
69 }
51
70
52− void testFormatStrF()
71+ void tesGDatetTimeFormatter_Format_data() { addTestData(QList<int>() << 0); }
72+ void tesGDatetTimeFormatter_Format()
53 {
73 {
74+ QFETCH(QDateTime, time);
54 const QString format = "%d-%m-%Y %I:%M%p";
75 const QString format = "%d-%m-%Y %I:%M%p";
55
76
56− QDateTime time = QDateTime::currentDateTime();
57−
58 GDateTimeFormatter formatter;
77 GDateTimeFormatter formatter;
59 formatter.setTime(time.toMSecsSinceEpoch() / 1000); // strftime in seconds since epoc
78 formatter.setTime(time.toMSecsSinceEpoch() / 1000); // strftime in seconds since epoc
60 formatter.setFormat(format);
79 formatter.setFormat(format);
61
80
62 QCOMPARE(formatter.timeString(), time.toString("dd-MM-yyyy hh:mmAP"));
81 QCOMPARE(formatter.timeString(), time.toString("dd-MM-yyyy hh:mmAP"));
63 }
82 }
83+
84+ void tesRelativeTimeFormatter_FarBack_data() { addTestData(QList<int>() << -200 << -7); }
85+ void tesRelativeTimeFormatter_FarBack()
86+ {
87+ QFETCH(QDateTime, time);
88+
89+ RelativeTimeFormatter formatter;
90+ formatter.setTime(time.toMSecsSinceEpoch() / 1000); // strftime in seconds since epoc
91+
92+ QCOMPARE(formatter.timeString(), time.toString("ddd d MMM\u2003HH:mm"));
93+ }
94+
95+ void tesRelativeTimeFormatter_WeekBack_data() { addTestData(QList<int>() << -6 << -2); }
96+ void tesRelativeTimeFormatter_WeekBack()
97+ {
98+ QFETCH(QDateTime, time);
99+
100+ RelativeTimeFormatter formatter;
101+ formatter.setTime(time.toMSecsSinceEpoch() / 1000); // strftime in seconds since epoc
102+
103+ QCOMPARE(formatter.timeString(), time.toString("ddd\u2003HH:mm"));
104+ }
105+
106+ void tesRelativeTimeFormatter_Yesterday_data() { addTestData(QList<int>() << -1); }
107+ void tesRelativeTimeFormatter_Yesterday()
108+ {
109+ QFETCH(QDateTime, time);
110+
111+ RelativeTimeFormatter formatter;
112+ formatter.setTime(time.toMSecsSinceEpoch() / 1000); // strftime in seconds since epoc
113+
114+ QCOMPARE(formatter.timeString(), QString("Yesterday\u2003%1").arg(time.toString("HH:mm")));
115+ }
116+
117+ void tesRelativeTimeFormatter_Today_data() { addTestData(QList<int>() << 0); }
118+ void tesRelativeTimeFormatter_Today()
119+ {
120+ QFETCH(QDateTime, time);
121+
122+ RelativeTimeFormatter formatter;
123+ formatter.setTime(time.toMSecsSinceEpoch() / 1000); // strftime in seconds since epoc
124+
125+ QCOMPARE(formatter.timeString(), time.toString("HH:mm"));
126+ }
127+
128+ void tesRelativeTimeFormatter_Tomorrow_data() { addTestData(QList<int>() << 1); }
129+ void tesRelativeTimeFormatter_Tomorrow()
130+ {
131+ QFETCH(QDateTime, time);
132+
133+ RelativeTimeFormatter formatter;
134+ formatter.setTime(time.toMSecsSinceEpoch() / 1000); // strftime in seconds since epoc
135+
136+ QCOMPARE(formatter.timeString(), QString("Tomorrow\u2003%1").arg(time.toString("HH:mm")));
137+ }
138+
139+
140+ void tesRelativeTimeFormatter_WeekForward_data() { addTestData(QList<int>() << 2 << 6); }
141+ void tesRelativeTimeFormatter_WeekForward()
142+ {
143+ QFETCH(QDateTime, time);
144+
145+ RelativeTimeFormatter formatter;
146+ formatter.setTime(time.toMSecsSinceEpoch() / 1000); // strftime in seconds since epoc
147+
148+ QCOMPARE(formatter.timeString(), time.toString("ddd\u2003HH:mm"));
149+ }
150+
151+ void tesRelativeTimeFormatter_FarForward_data() { addTestData(QList<int>() << 7 << 200); }
152+ void tesRelativeTimeFormatter_FarForward()
153+ {
154+ QFETCH(QDateTime, time);
155+
156+ RelativeTimeFormatter formatter;
157+ formatter.setTime(time.toMSecsSinceEpoch() / 1000); // strftime in seconds since epoc
158+
159+ QCOMPARE(formatter.timeString(), time.toString("ddd d MMM\u2003HH:mm"));
160+ }
64};
161};
65
162
66QTEST_GUILESS_MAIN(TimeFormatterTest)
163QTEST_GUILESS_MAIN(TimeFormatterTest)