[gnome-panel] clock: use GDateTime to format time
- From: Alberts MuktupÄvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel] clock: use GDateTime to format time
- Date: Sun, 30 Oct 2016 22:32:57 +0000 (UTC)
commit 064b83c070f0d726cb841e3ec6b695ada399ba5e
Author: Alberts MuktupÄvels <alberts muktupavels gmail com>
Date: Sun Oct 30 21:10:01 2016 +0200
clock: use GDateTime to format time
applets/clock/calendar-window.c | 59 ++++++++++++++++++++-------------------
1 files changed, 30 insertions(+), 29 deletions(-)
---
diff --git a/applets/clock/calendar-window.c b/applets/clock/calendar-window.c
index 61c89f1..df0e6f5 100644
--- a/applets/clock/calendar-window.c
+++ b/applets/clock/calendar-window.c
@@ -247,43 +247,44 @@ format_time (GDesktopClockFormat format,
gint month,
gint day)
{
- struct tm *tm;
- char *time_format;
- char result [256] = { 0, };
+ GDateTime *dt;
+ gchar *time;
if (!t)
return NULL;
- tm = localtime (&t);
- if (!tm)
+ dt = g_date_time_new_from_unix_local (t);
+ time = NULL;
+
+ if (!dt)
return NULL;
- if (year == (tm->tm_year + 1900) &&
- month == tm->tm_mon &&
- day == tm->tm_mday) {
- if (format == G_DESKTOP_CLOCK_FORMAT_12H)
- /* Translators: This is a strftime format string.
- * It is used to display the time in 12-hours format
- * (eg, like in the US: 8:10 am). The %p expands to
- * am/pm. */
- time_format = g_locale_from_utf8 (_("%l:%M %p"), -1, NULL, NULL, NULL);
- else
- /* Translators: This is a strftime format string.
- * It is used to display the time in 24-hours format
- * (eg, like in France: 20:10). */
- time_format = g_locale_from_utf8 (_("%H:%M"), -1, NULL, NULL, NULL);
- }
- else {
- /* Translators: This is a strftime format string.
- * It is used to display the start date of an appointment, in
- * the most abbreviated way possible. */
- time_format = g_locale_from_utf8 (_("%b %d"), -1, NULL, NULL, NULL);
+ if (year == (g_date_time_get_year (dt) + 1900) &&
+ month == g_date_time_get_month (dt) &&
+ day == g_date_time_get_day_of_month (dt)) {
+ if (format == G_DESKTOP_CLOCK_FORMAT_12H) {
+ /* Translators: This is a strftime format string.
+ * It is used to display the time in 12-hours format
+ * (eg, like in the US: 8:10 am). The %p expands to
+ * am/pm.
+ */
+ time = g_date_time_format (dt, _("%l:%M %p"));
+ } else {
+ /* Translators: This is a strftime format string.
+ * It is used to display the time in 24-hours format
+ * (eg, like in France: 20:10).
+ */
+ time = g_date_time_format (dt, _("%H:%M"));
+ }
+ } else {
+ /* Translators: This is a strftime format string.
+ * It is used to display the start date of an appointment, in
+ * the most abbreviated way possible.
+ */
+ time = g_date_time_format (dt, _("%b %d"));
}
- strftime (result, sizeof (result), time_format, tm);
- g_free (time_format);
-
- return g_locale_to_utf8 (result, -1, NULL, NULL, NULL);
+ return time;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]