summaryrefslogtreecommitdiff
path: root/lib/ephy-time-helpers.c
diff options
context:
space:
mode:
authorMichael Catanzaro <mcatanzaro@igalia.com>2016-03-21 23:13:34 -0500
committerMichael Catanzaro <mcatanzaro@igalia.com>2016-03-29 13:03:13 -0500
commit9ccb9da9eb9601c66e615d7a4a44c747832ddac1 (patch)
tree3b7f694c37af6e77e264bf9ded228f1a43aa7516 /lib/ephy-time-helpers.c
parent5a5e0d7cf463c14f4769de4e9a3ae9e8b38d54b4 (diff)
downloadepiphany-9ccb9da9eb9601c66e615d7a4a44c747832ddac1.tar.gz
Uncrustify
For a better future. Apologies when your 'git blame' resolves to this. I'm actually really impressed how well uncrustify works. This required only a little one-time manual work to avoid extra space in 'else {'. This breaks function prototype alignment, but we should get rid of most of those anyway. We decided to start aligning function parameters, like other GNOME applications. It looks nicer this way, and I couldn't teach uncrustify the previous Epiphany style.
Diffstat (limited to 'lib/ephy-time-helpers.c')
-rw-r--r--lib/ephy-time-helpers.c370
1 files changed, 185 insertions, 185 deletions
diff --git a/lib/ephy-time-helpers.c b/lib/ephy-time-helpers.c
index dc3fe7422..85863309b 100644
--- a/lib/ephy-time-helpers.c
+++ b/lib/ephy-time-helpers.c
@@ -64,223 +64,223 @@
char *
eel_strdup_strftime (const char *format, struct tm *time_pieces)
{
- GString *string;
- const char *remainder, *percent;
- char code[4], buffer[512];
- char *piece, *result, *converted;
- size_t string_length;
- gboolean strip_leading_zeros, turn_leading_zeros_to_spaces;
- char modifier;
- int i;
+ GString *string;
+ const char *remainder, *percent;
+ char code[4], buffer[512];
+ char *piece, *result, *converted;
+ size_t string_length;
+ gboolean strip_leading_zeros, turn_leading_zeros_to_spaces;
+ char modifier;
+ int i;
- /* Format could be translated, and contain UTF-8 chars,
- * so convert to locale encoding which strftime uses */
- converted = g_locale_from_utf8 (format, -1, NULL, NULL, NULL);
- g_return_val_if_fail (converted != NULL, NULL);
+ /* Format could be translated, and contain UTF-8 chars,
+ * so convert to locale encoding which strftime uses */
+ converted = g_locale_from_utf8 (format, -1, NULL, NULL, NULL);
+ g_return_val_if_fail (converted != NULL, NULL);
- string = g_string_new ("");
- remainder = converted;
+ string = g_string_new ("");
+ remainder = converted;
- /* Walk from % character to % character. */
- for (;;) {
- percent = strchr (remainder, '%');
- if (percent == NULL) {
- g_string_append (string, remainder);
- break;
- }
- g_string_append_len (string, remainder,
- percent - remainder);
+ /* Walk from % character to % character. */
+ for (;; ) {
+ percent = strchr (remainder, '%');
+ if (percent == NULL) {
+ g_string_append (string, remainder);
+ break;
+ }
+ g_string_append_len (string, remainder,
+ percent - remainder);
- /* Handle the "%" character. */
- remainder = percent + 1;
- switch (*remainder) {
- case '-':
- strip_leading_zeros = TRUE;
- turn_leading_zeros_to_spaces = FALSE;
- remainder++;
- break;
- case '_':
- strip_leading_zeros = FALSE;
- turn_leading_zeros_to_spaces = TRUE;
- remainder++;
- break;
- case '%':
- g_string_append_c (string, '%');
- remainder++;
- continue;
- case '\0':
- g_warning ("Trailing %% passed to eel_strdup_strftime");
- g_string_append_c (string, '%');
- continue;
- default:
- strip_leading_zeros = FALSE;
- turn_leading_zeros_to_spaces = FALSE;
- break;
- }
+ /* Handle the "%" character. */
+ remainder = percent + 1;
+ switch (*remainder) {
+ case '-':
+ strip_leading_zeros = TRUE;
+ turn_leading_zeros_to_spaces = FALSE;
+ remainder++;
+ break;
+ case '_':
+ strip_leading_zeros = FALSE;
+ turn_leading_zeros_to_spaces = TRUE;
+ remainder++;
+ break;
+ case '%':
+ g_string_append_c (string, '%');
+ remainder++;
+ continue;
+ case '\0':
+ g_warning ("Trailing %% passed to eel_strdup_strftime");
+ g_string_append_c (string, '%');
+ continue;
+ default:
+ strip_leading_zeros = FALSE;
+ turn_leading_zeros_to_spaces = FALSE;
+ break;
+ }
- modifier = 0;
- if (strchr (SUS_EXTENDED_STRFTIME_MODIFIERS, *remainder) != NULL) {
- modifier = *remainder;
- remainder++;
+ modifier = 0;
+ if (strchr (SUS_EXTENDED_STRFTIME_MODIFIERS, *remainder) != NULL) {
+ modifier = *remainder;
+ remainder++;
- if (*remainder == 0) {
- g_warning ("Unfinished %%%c modifier passed to eel_strdup_strftime", modifier);
- break;
- }
- }
+ if (*remainder == 0) {
+ g_warning ("Unfinished %%%c modifier passed to eel_strdup_strftime", modifier);
+ break;
+ }
+ }
- if (strchr (C_STANDARD_STRFTIME_CHARACTERS, *remainder) == NULL) {
- g_warning ("eel_strdup_strftime does not support "
- "non-standard escape code %%%c",
- *remainder);
- }
+ if (strchr (C_STANDARD_STRFTIME_CHARACTERS, *remainder) == NULL) {
+ g_warning ("eel_strdup_strftime does not support "
+ "non-standard escape code %%%c",
+ *remainder);
+ }
- /* Convert code to strftime format. We have a fixed
- * limit here that each code can expand to a maximum
- * of 512 bytes, which is probably OK. There's no
- * limit on the total size of the result string.
- */
- i = 0;
- code[i++] = '%';
- if (modifier != 0) {
+ /* Convert code to strftime format. We have a fixed
+ * limit here that each code can expand to a maximum
+ * of 512 bytes, which is probably OK. There's no
+ * limit on the total size of the result string.
+ */
+ i = 0;
+ code[i++] = '%';
+ if (modifier != 0) {
#ifdef HAVE_STRFTIME_EXTENSION
- code[i++] = modifier;
+ code[i++] = modifier;
#endif
- }
- code[i++] = *remainder;
- code[i++] = '\0';
+ }
+ code[i++] = *remainder;
+ code[i++] = '\0';
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
- /* Format string under control of caller, since this is a wrapper for strftime. */
- string_length = strftime (buffer, sizeof (buffer),
- code, time_pieces);
+ /* Format string under control of caller, since this is a wrapper for strftime. */
+ string_length = strftime (buffer, sizeof (buffer),
+ code, time_pieces);
#pragma GCC diagnostic pop
- if (string_length == 0) {
- /* We could put a warning here, but there's no
- * way to tell a successful conversion to
- * empty string from a failure.
- */
- buffer[0] = '\0';
- }
+ if (string_length == 0) {
+ /* We could put a warning here, but there's no
+ * way to tell a successful conversion to
+ * empty string from a failure.
+ */
+ buffer[0] = '\0';
+ }
- /* Strip leading zeros if requested. */
- piece = buffer;
- if (strip_leading_zeros || turn_leading_zeros_to_spaces) {
- if (strchr (C_STANDARD_NUMERIC_STRFTIME_CHARACTERS, *remainder) == NULL) {
- g_warning ("eel_strdup_strftime does not support "
- "modifier for non-numeric escape code %%%c%c",
- remainder[-1],
- *remainder);
- }
- if (*piece == '0') {
- do {
- piece++;
- } while (*piece == '0');
- if (!g_ascii_isdigit (*piece)) {
- piece--;
- }
- }
- if (turn_leading_zeros_to_spaces) {
- memset (buffer, ' ', piece - buffer);
- piece = buffer;
- }
- }
- remainder++;
+ /* Strip leading zeros if requested. */
+ piece = buffer;
+ if (strip_leading_zeros || turn_leading_zeros_to_spaces) {
+ if (strchr (C_STANDARD_NUMERIC_STRFTIME_CHARACTERS, *remainder) == NULL) {
+ g_warning ("eel_strdup_strftime does not support "
+ "modifier for non-numeric escape code %%%c%c",
+ remainder[-1],
+ *remainder);
+ }
+ if (*piece == '0') {
+ do {
+ piece++;
+ } while (*piece == '0');
+ if (!g_ascii_isdigit (*piece)) {
+ piece--;
+ }
+ }
+ if (turn_leading_zeros_to_spaces) {
+ memset (buffer, ' ', piece - buffer);
+ piece = buffer;
+ }
+ }
+ remainder++;
- /* Add this piece. */
- g_string_append (string, piece);
- }
+ /* Add this piece. */
+ g_string_append (string, piece);
+ }
- /* Convert the string back into utf-8. */
- result = g_locale_to_utf8 (string->str, -1, NULL, NULL, NULL);
+ /* Convert the string back into utf-8. */
+ result = g_locale_to_utf8 (string->str, -1, NULL, NULL, NULL);
- g_string_free (string, TRUE);
- g_free (converted);
+ g_string_free (string, TRUE);
+ g_free (converted);
- return result;
+ return result;
}
/* Based on evolution/mail/message-list.c:filter_date() */
char *
ephy_time_helpers_utf_friendly_time (time_t date)
{
- time_t nowdate;
- time_t yesdate;
- struct tm then, now, yesterday;
- const char *format = NULL;
- char *str = NULL;
- gboolean done = FALSE;
+ time_t nowdate;
+ time_t yesdate;
+ struct tm then, now, yesterday;
+ const char *format = NULL;
+ char *str = NULL;
+ gboolean done = FALSE;
- nowdate = time (NULL);
+ nowdate = time (NULL);
- if (date == 0)
- return NULL;
+ if (date == 0)
+ return NULL;
- localtime_r (&date, &then);
- localtime_r (&nowdate, &now);
+ localtime_r (&date, &then);
+ localtime_r (&nowdate, &now);
- if (then.tm_mday == now.tm_mday &&
- then.tm_mon == now.tm_mon &&
- then.tm_year == now.tm_year) {
- /* Translators: "friendly time" string for the current day, strftime format. like "Today 12:34 am" */
- format = _("Today %I:%M %p");
- done = TRUE;
- }
+ if (then.tm_mday == now.tm_mday &&
+ then.tm_mon == now.tm_mon &&
+ then.tm_year == now.tm_year) {
+ /* Translators: "friendly time" string for the current day, strftime format. like "Today 12:34 am" */
+ format = _("Today %I:%M %p");
+ done = TRUE;
+ }
- if (! done) {
- yesdate = nowdate - 60 * 60 * 24;
- localtime_r (&yesdate, &yesterday);
- if (then.tm_mday == yesterday.tm_mday &&
- then.tm_mon == yesterday.tm_mon &&
- then.tm_year == yesterday.tm_year) {
- /* Translators: "friendly time" string for the previous day,
- * strftime format. e.g. "Yesterday 12:34 am"
- */
- format = _("Yesterday %I:%M %p");
- done = TRUE;
- }
- }
+ if (!done) {
+ yesdate = nowdate - 60 * 60 * 24;
+ localtime_r (&yesdate, &yesterday);
+ if (then.tm_mday == yesterday.tm_mday &&
+ then.tm_mon == yesterday.tm_mon &&
+ then.tm_year == yesterday.tm_year) {
+ /* Translators: "friendly time" string for the previous day,
+ * strftime format. e.g. "Yesterday 12:34 am"
+ */
+ format = _("Yesterday %I:%M %p");
+ done = TRUE;
+ }
+ }
- if (! done) {
- int i;
- for (i = 2; i < 7; i++) {
- yesdate = nowdate - 60 * 60 * 24 * i;
- localtime_r (&yesdate, &yesterday);
- if (then.tm_mday == yesterday.tm_mday &&
- then.tm_mon == yesterday.tm_mon &&
- then.tm_year == yesterday.tm_year) {
- /* Translators: "friendly time" string for a day in the current week,
- * strftime format. e.g. "Wed 12:34 am"
- */
- format = _("%a %I:%M %p");
- done = TRUE;
- break;
- }
- }
- }
+ if (!done) {
+ int i;
+ for (i = 2; i < 7; i++) {
+ yesdate = nowdate - 60 * 60 * 24 * i;
+ localtime_r (&yesdate, &yesterday);
+ if (then.tm_mday == yesterday.tm_mday &&
+ then.tm_mon == yesterday.tm_mon &&
+ then.tm_year == yesterday.tm_year) {
+ /* Translators: "friendly time" string for a day in the current week,
+ * strftime format. e.g. "Wed 12:34 am"
+ */
+ format = _("%a %I:%M %p");
+ done = TRUE;
+ break;
+ }
+ }
+ }
- if (! done) {
- if (then.tm_year == now.tm_year) {
- /* Translators: "friendly time" string for a day in the current year,
- * strftime format. e.g. "Feb 12 12:34 am"
- */
- format = _("%b %d %I:%M %p");
- } else {
- /* Translators: "friendly time" string for a day in a different year,
- * strftime format. e.g. "Feb 12 1997"
- */
- format = _("%b %d %Y");
- }
- }
+ if (!done) {
+ if (then.tm_year == now.tm_year) {
+ /* Translators: "friendly time" string for a day in the current year,
+ * strftime format. e.g. "Feb 12 12:34 am"
+ */
+ format = _("%b %d %I:%M %p");
+ } else {
+ /* Translators: "friendly time" string for a day in a different year,
+ * strftime format. e.g. "Feb 12 1997"
+ */
+ format = _("%b %d %Y");
+ }
+ }
- if (format != NULL) {
- str = eel_strdup_strftime (format, &then);
- }
+ if (format != NULL) {
+ str = eel_strdup_strftime (format, &then);
+ }
- if (str == NULL) {
- /* impossible time or broken locale settings */
- str = g_strdup (_("Unknown"));
- }
+ if (str == NULL) {
+ /* impossible time or broken locale settings */
+ str = g_strdup (_("Unknown"));
+ }
- return str;
+ return str;
}