on xenial help sign in
fixed local relative time
293b66cNick Dedekind
plugins/Utils/relativetimeformatter.cpp+31−39
@@ -74,53 +74,45 @@ getDateProximity(GDateTime* now, GDateTime* time)
74 }
74 }
75
75
76 // did it happen yesterday?
76 // did it happen yesterday?
77− GDateTime* tomorrow = g_date_time_add_days(now, -1);
77+ GDateTime* yesterday = g_date_time_add_days(now, -1);
78 gint tom_year, tom_month, tom_day;
78 gint tom_year, tom_month, tom_day;
79− g_date_time_get_ymd(tomorrow, &tom_year, &tom_month, &tom_day);
79+ g_date_time_get_ymd(yesterday, &tom_year, &tom_month, &tom_day);
80− g_date_time_unref(tomorrow);
80+ g_date_time_unref(yesterday);
81 if ((tom_year == time_year) && (tom_month == time_month) && (tom_day == time_day)) {
81 if ((tom_year == time_year) && (tom_month == time_month) && (tom_day == time_day)) {
82 return DATE_PROXIMITY_YESTERDAY;
82 return DATE_PROXIMITY_YESTERDAY;
83 }
83 }
84
84
85 // does it happen tomorrow?
85 // does it happen tomorrow?
86− if (prox == DATE_PROXIMITY_FAR)
87− {
88− GDateTime* tomorrow = g_date_time_add_days(now, 1);
86+ 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);
87+ g_date_time_get_ymd(tomorrow, &tom_year, &tom_month, &tom_day);
92− g_date_time_unref(tomorrow);
88+ g_date_time_unref(tomorrow);
93− if ((tom_year == time_year) && (tom_month == time_month) && (tom_day == time_day)) {
89+ if ((tom_year == time_year) && (tom_month == time_month) && (tom_day == time_day)) {
94− return DATE_PROXIMITY_TOMORROW;
90+ return DATE_PROXIMITY_TOMORROW;
95− }
96 }
91 }
97
92
98 // does it happen this week?
93 // does it happen this week?
99− if (prox == DATE_PROXIMITY_FAR) {
100− if (g_date_time_compare(time, now) < 0) {
94+ if (g_date_time_compare(time, now) < 0) {
101− GDateTime* last_week = g_date_time_add_days(now, -6);
95+ 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),
96+ GDateTime* last_week_bound = g_date_time_new_local(g_date_time_get_year(last_week),
103− g_date_time_get_month(last_week),
97+ g_date_time_get_month(last_week),
104− g_date_time_get_day_of_month(last_week),
98+ g_date_time_get_day_of_month(last_week),
105− 0, 0, 0);
99+ 0, 0, 0);
106− if (g_date_time_compare(time, last_week_bound) >= 0)
100+ if (g_date_time_compare(time, last_week_bound) >= 0)
107− prox = DATE_PROXIMITY_LAST_WEEK;
101+ prox = DATE_PROXIMITY_LAST_WEEK;
108−
102+
109− g_date_time_unref(last_week);
103+ g_date_time_unref(last_week);
110− g_date_time_unref(last_week_bound);
104+ g_date_time_unref(last_week_bound);
111− } else {
105+ } else {
112− GDateTime* next_week = g_date_time_add_days(now, 6);
106+ 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),
107+ GDateTime* next_week_bound = g_date_time_new_local(g_date_time_get_year(next_week),
114− g_date_time_get_month(next_week),
108+ g_date_time_get_month(next_week),
115− g_date_time_get_day_of_month(next_week),
109+ g_date_time_get_day_of_month(next_week),
116− 23, 59, 59.9);
110+ 23, 59, 59.9);
117− if (g_date_time_compare(time, next_week_bound) <= 0)
111+ if (g_date_time_compare(time, next_week_bound) <= 0)
118− prox = DATE_PROXIMITY_NEXT_WEEK;
112+ prox = DATE_PROXIMITY_NEXT_WEEK;
119−
113+
120− g_date_time_unref(next_week);
114+ g_date_time_unref(next_week);
121− g_date_time_unref(next_week_bound);
115+ g_date_time_unref(next_week_bound);
122− }
123−
124 }
116 }
125
117
126 return prox;
118 return prox;
@@ -250,7 +242,7 @@ char* generate_full_format_string_at_time (GDateTime* now,
250
242
251QString RelativeTimeFormatter::format() const
243QString RelativeTimeFormatter::format() const
252{
244{
253− GDateTime* now = g_date_time_new_from_unix_utc(QDateTime::currentMSecsSinceEpoch() / 1000);
245+ GDateTime* now = g_date_time_new_now_local();
254 if (!now) { return QString(); }
246 if (!now) { return QString(); }
255
247
256 GDateTime* then = g_date_time_new_from_unix_local(time());
248 GDateTime* then = g_date_time_new_from_unix_local(time());