aboutsummaryrefslogtreecommitdiffstats
path: root/calendar
diff options
context:
space:
mode:
Diffstat (limited to 'calendar')
-rw-r--r--calendar/ChangeLog8
-rw-r--r--calendar/gui/alarm-notify/util.c62
-rw-r--r--calendar/gui/misc.c66
3 files changed, 60 insertions, 76 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog
index ec40e44a01..80bb64f09a 100644
--- a/calendar/ChangeLog
+++ b/calendar/ChangeLog
@@ -1,3 +1,11 @@
+2006-03-06 Theppitak Karoonboonyanan <thep@linux.thai.net>
+
+ ** Fixes bug #328988
+
+ * gui/alarm-notify/util.c: (calculate_time):
+ * gui/misc.c: (calculate_time): Added code to simplify the function
+ calculate_time and made strings translatable.
+
2006-03-06 Chenthill Palanisamy <pchenthill@novell.com>
Fixes #330448
diff --git a/calendar/gui/alarm-notify/util.c b/calendar/gui/alarm-notify/util.c
index 9409cc928c..661b0f44c0 100644
--- a/calendar/gui/alarm-notify/util.c
+++ b/calendar/gui/alarm-notify/util.c
@@ -53,47 +53,35 @@ calculate_time (time_t start, time_t end)
{
time_t difference = end - start;
char *str;
+ int hours, minutes;
+ char *times[4];
+ char *joined;
+ int i;
- if (difference < 60) {/* Can't be zero */
- str = g_strdup_printf (_("(%ld seconds)"), difference);
- } else if (difference > 60 && difference < 3600) { /* It will be x minutes y seconds*/
- int minutes, seconds;
- minutes = difference / 60;
- seconds = difference % 60;
- if (seconds)
- /* TRANSLATORS: here, "second" is the time division (like "minute"), not the ordinal number (like "third") */
- str = g_strdup_printf (_("(%d %s %d %s)"), minutes, ngettext(_("minute"), _("minutes"), minutes), seconds, ngettext(_("second"), _("seconds"), seconds));
- else
- str = g_strdup_printf (_("(%d %s)"), minutes, ngettext(_("minute"), _("minutes"), minutes));
- } else {
- guint hours, minutes, seconds;
- char *s_hours = NULL, *s_minutes = NULL, *s_seconds = NULL;
-
+ i = 0;
+ if (difference >= 3600) {
hours = difference / 3600;
- minutes = (difference % 3600)/60;
- seconds = difference % 60;
+ difference %= 3600;
-
- if (seconds)
- s_seconds = g_strdup_printf (ngettext(_(" %u second"), _(" %u seconds"), seconds), seconds);
- if (minutes)
- s_minutes = g_strdup_printf (ngettext(_(" %u minute"), _(" %u minutes"), minutes), minutes);
- if (hours)
- s_hours = g_strdup_printf (ngettext(_("%u hour"),_("%u hours"), hours), hours);
-
- if (s_minutes && s_seconds)
- str = g_strconcat ("(", s_hours, s_minutes, s_seconds, ")", NULL);
- else if (s_minutes)
- str = g_strconcat ("(", s_hours, s_minutes, ")", NULL);
- else if (s_seconds)
- str = g_strconcat ("(", s_hours, s_seconds, ")", NULL);
- else
- str = g_strconcat ("(", s_hours, ")", NULL);
+ times[i++] = g_strdup_printf (ngettext("%d hour", "%d hours", hours), hours);
+ }
+ if (difference >= 60) {
+ minutes = difference / 60;
+ difference %= 60;
- g_free (s_hours);
- g_free (s_minutes);
- g_free (s_seconds);
+ times[i++] = g_strdup_printf (ngettext("%d minute", "%d minutes", minutes), minutes);
+ }
+ if (i == 0 || difference != 0) {
+ /* TRANSLATORS: here, "second" is the time division (like "minute"), not the ordinal number (like "third") */
+ times[i++] = g_strdup_printf (ngettext("%d second", "%d seconds", difference), (int)difference);
}
- return g_strchug(str);
+ times[i] = NULL;
+ joined = g_strjoinv (" ", times);
+ str = g_strconcat ("(", joined, ")", NULL);
+ while (i > 0)
+ g_free (times[--i]);
+ g_free (joined);
+
+ return str;
}
diff --git a/calendar/gui/misc.c b/calendar/gui/misc.c
index 2bcc9e1ab5..067c4abeea 100644
--- a/calendar/gui/misc.c
+++ b/calendar/gui/misc.c
@@ -100,47 +100,35 @@ calculate_time (time_t start, time_t end)
{
time_t difference = end - start;
char *str;
-
- if (difference < 60) {/* Can't be zero */
- str = g_strdup_printf (_("(%d seconds)"), difference);
- } else if (difference > 60 && difference < 3600) { /* It will be x minutes y seconds*/
- int minutes, seconds;
+ int hours, minutes;
+ char *times[4];
+ char *joined;
+ int i;
+
+ i = 0;
+ if (difference >= 3600) {
+ hours = difference / 3600;
+ difference %= 3600;
+
+ times[i++] = g_strdup_printf (ngettext("%d hour", "%d hours", hours), hours);
+ }
+ if (difference >= 60) {
minutes = difference / 60;
- seconds = difference % 60;
- if (seconds)
+ difference %= 60;
+
+ times[i++] = g_strdup_printf (ngettext("%d minute", "%d minutes", minutes), minutes);
+ }
+ if (i == 0 || difference != 0) {
/* TRANSLATORS: here, "second" is the time division (like "minute"), not the ordinal number (like "third") */
- str = g_strdup_printf (_("(%d %s %d %s)"), minutes, ngettext(_("minute"), _("minutes"), minutes), seconds, ngettext(_("second"), _("seconds"), seconds));
- else
- str = g_strdup_printf (_("(%d %s)"), minutes, ngettext(_("minute"), _("minutes"), minutes));
- } else {
- guint hours, minutes, seconds;
- char *s_hours = NULL, *s_minutes = NULL, *s_seconds = NULL;
-
- hours = difference / 3600;
- minutes = (difference % 3600)/60;
- seconds = difference % 60;
-
-
- if (seconds)
- s_seconds = g_strdup_printf (ngettext(_(" %u second"), _(" %u seconds"), seconds), seconds);
- if (minutes)
- s_minutes = g_strdup_printf (ngettext(_(" %u minute"), _(" %u minutes"), minutes), minutes);
- if (hours)
- s_hours = g_strdup_printf (ngettext(_("%u hour"),_("%u hours"), hours), hours);
-
- if (s_minutes && s_seconds)
- str = g_strconcat ("(", s_hours, s_minutes, s_seconds, ")", NULL);
- else if (s_minutes)
- str = g_strconcat ("(", s_hours, s_minutes, ")", NULL);
- else if (s_seconds)
- str = g_strconcat ("(", s_hours, s_seconds, ")", NULL);
- else
- str = g_strconcat ("(", s_hours, ")", NULL);
-
- g_free (s_hours);
- g_free (s_minutes);
- g_free (s_seconds);
+ times[i++] = g_strdup_printf (ngettext("%d second", "%d seconds", difference), (int)difference);
}
- return g_strchug(str);
+ times[i] = NULL;
+ joined = g_strjoinv (" ", times);
+ str = g_strconcat ("(", joined, ")", NULL);
+ while (i > 0)
+ g_free (times[--i]);
+ g_free (joined);
+
+ return str;
}