[gnome-todo] panel-scheduled: fix headers
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-todo] panel-scheduled: fix headers
- Date: Fri, 12 Feb 2016 03:43:23 +0000 (UTC)
commit 9ce23de51f1f9dac0cee9a10e91b913df6965cec
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Fri Feb 12 01:28:06 2016 -0200
panel-scheduled: fix headers
This commit better calculates the days
difference between the event's date and
the current date. More importantly, it now
considers the timezone.
It also uses the apropriate gettext function
to translate dates.
https://bugzilla.gnome.org/show_bug.cgi?id=760923
plugins/eds/gtd-panel-scheduled.c | 32 ++++++++++++++++++++++----------
1 files changed, 22 insertions(+), 10 deletions(-)
---
diff --git a/plugins/eds/gtd-panel-scheduled.c b/plugins/eds/gtd-panel-scheduled.c
index 3e1ad8e..833d350 100644
--- a/plugins/eds/gtd-panel-scheduled.c
+++ b/plugins/eds/gtd-panel-scheduled.c
@@ -20,6 +20,7 @@
#include <glib/gi18n.h>
#include <gnome-todo.h>
+#include <math.h>
struct _GtdPanelScheduled
{
@@ -54,24 +55,33 @@ static gchar*
get_string_for_date (GDateTime *dt,
gint *span)
{
+ GDateTime *today;
+ GDateTime *next_year;
GDateTime *now;
gchar *str;
gint days_diff;
+ gint next_year_diff;
/* This case should never happen */
if (!dt)
return g_strdup (_("No date set"));
- now = g_date_time_new_now_local ();
- days_diff = g_date_time_difference (dt, now) / G_TIME_SPAN_DAY;
-
- if (days_diff < -1)
- {
- str = g_strdup_printf (_("%d days ago"), -days_diff);
- }
- else if (days_diff == -1)
+ now = g_date_time_new_now_utc ();
+ today = g_date_time_new_utc (g_date_time_get_year (now),
+ g_date_time_get_month (now),
+ g_date_time_get_day_of_month (now),
+ 0, 0, 0);
+ next_year = g_date_time_new_utc (g_date_time_get_year (now) + 1,
+ G_DATE_JANUARY,
+ 1,
+ 0, 0, 0);
+ next_year_diff = g_date_time_difference (next_year, today) / G_TIME_SPAN_DAY;
+ days_diff = g_date_time_difference (dt, today) / G_TIME_SPAN_DAY;
+
+ if (days_diff < 0)
{
- str = g_strdup (_("Yesterday"));
+ str = g_strdup_printf (g_dngettext (NULL, _("Yesterday"), _("%d days ago"), -days_diff),
+ -days_diff);
}
else if (days_diff == 0)
{
@@ -85,7 +95,7 @@ get_string_for_date (GDateTime *dt,
{
str = g_date_time_format (dt, "%A"); // Weekday name
}
- else if (days_diff >= 7 && days_diff < (365 + g_date_time_get_year (dt) % 4 == 0))
+ else if (days_diff >= 7 && days_diff < next_year_diff)
{
str = g_date_time_format (dt, "%B"); // Full month name
}
@@ -97,6 +107,8 @@ get_string_for_date (GDateTime *dt,
if (span)
*span = days_diff;
+ g_clear_pointer (&next_year, g_date_time_unref);
+ g_clear_pointer (&today, g_date_time_unref);
g_clear_pointer (&now, g_date_time_unref);
return str;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]