From 62edcf03d3b0a799c8a02167b8a44d8b03d40c8b Mon Sep 17 00:00:00 2001 From: Cosimo Cecchi Date: Sat, 1 Apr 2017 17:15:41 -0700 Subject: [PATCH] datetime: factor out fallback AM/PM function We will reuse this. https://bugzilla.gnome.org/show_bug.cgi?id=761889 --- glib/gdatetime.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/glib/gdatetime.c b/glib/gdatetime.c index 4b6f99917..0bb5cbca6 100644 --- a/glib/gdatetime.c +++ b/glib/gdatetime.c @@ -194,11 +194,7 @@ static const gint month_item[2][12] = #else -#define GET_AMPM(d) ((g_date_time_get_hour (d) < 12) \ - /* Translators: 'before midday' indicator */ \ - ? C_("GDateTime", "AM") \ - /* Translators: 'after midday' indicator */ \ - : C_("GDateTime", "PM")) +#define GET_AMPM(d) (get_fallback_ampm (g_date_time_get_hour (d))) /* Translators: this is the preferred format for expressing the date and the time */ #define PREFERRED_DATE_TIME_FMT C_("GDateTime", "%a %b %e %H:%M:%S %Y") @@ -347,6 +343,18 @@ get_weekday_name_abbr (gint day) #endif /* HAVE_LANGINFO_TIME */ +/* Format AM/PM indicator if the locale does not have a localized version. */ +static const gchar * +get_fallback_ampm (gint hour) +{ + if (hour < 12) + /* Translators: 'before midday' indicator */ + return C_("GDateTime", "AM"); + else + /* Translators: 'after midday' indicator */ + return C_("GDateTime", "PM"); +} + static inline gint ymd_to_days (gint year, gint month,