From 79b4221f89cc816a1b6e7eb3e8d0332e50765747 Mon Sep 17 00:00:00 2001 From: Damon Chaplin Date: Mon, 19 Mar 2001 15:46:32 +0000 Subject: added function to format just the time. 2001-03-18 Damon Chaplin * e-time-utils.c (e_time_format_time): added function to format just the time. svn path=/trunk/; revision=8822 --- e-util/ChangeLog | 5 +++++ e-util/e-time-utils.c | 53 +++++++++++++++++++++++++++++++++++++++++++-------- e-util/e-time-utils.h | 15 +++++++++++++-- 3 files changed, 63 insertions(+), 10 deletions(-) (limited to 'e-util') diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 49d5bb89d3..f54c173b1e 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,8 @@ +2001-03-18 Damon Chaplin + + * e-time-utils.c (e_time_format_time): added function to format just + the time. + 2001-03-16 Dan Winship * e-path.c (e_path_to_physical): Fix a bug noticed by kmaraas diff --git a/e-util/e-time-utils.c b/e-util/e-time-utils.c index 80eb38e2e9..de68939f31 100644 --- a/e-util/e-time-utils.c +++ b/e-util/e-time-utils.c @@ -247,17 +247,18 @@ string_is_empty (const char *value) } -/* Creates a string representation of a time value and stores it in result. - result_size is the size of the result buffer, and should be about 64 to - be safe. If show_midnight is FALSE, and the time is midnight, then we just - show the date. */ +/* Creates a string representation of a time value and stores it in buffer. + buffer_size should be about 64 to be safe. If show_midnight is FALSE, and + the time is midnight, then we just show the date. If show_zero_seconds + is FALSE, then if the time has zero seconds only the hour and minute are + shown. */ void e_time_format_date_and_time (struct tm *date_tm, gboolean use_24_hour_format, gboolean show_midnight, gboolean show_zero_seconds, - char *result, - int result_size) + char *buffer, + int buffer_size) { char *format; @@ -287,6 +288,42 @@ e_time_format_date_and_time (struct tm *date_tm, /* strftime returns 0 if the string doesn't fit, and leaves the buffer undefined, so we set it to the empty string in that case. */ - if (strftime (result, result_size, format, date_tm) == 0) - result[0] = '\0'; + if (strftime (buffer, buffer_size, format, date_tm) == 0) + buffer[0] = '\0'; +} + + +/* Creates a string representation of a time value and stores it in buffer. + buffer_size should be about 64 to be safe. */ +void +e_time_format_time (struct tm *date_tm, + gboolean use_24_hour_format, + gboolean show_zero_seconds, + char *buffer, + int buffer_size) +{ + char *format; + + if (use_24_hour_format) { + if (!show_zero_seconds && date_tm->tm_sec == 0) + /* strftime format of a time in 24-hour format, + without seconds. */ + format = _("%H:%M"); + else + /* strftime format of a time in 24-hour format. */ + format = _("%H:%M:%S"); + } else { + if (!show_zero_seconds && date_tm->tm_sec == 0) + /* strftime format of a time in 12-hour format, + without seconds. */ + format = _("%I:%M %p"); + else + /* strftime format of a time in 12-hour format. */ + format = _("%I:%M:%S %p"); + } + + /* strftime returns 0 if the string doesn't fit, and leaves the buffer + undefined, so we set it to the empty string in that case. */ + if (strftime (buffer, buffer_size, format, date_tm) == 0) + buffer[0] = '\0'; } diff --git a/e-util/e-time-utils.h b/e-util/e-time-utils.h index f6449a2f61..762e410e69 100644 --- a/e-util/e-time-utils.h +++ b/e-util/e-time-utils.h @@ -30,6 +30,17 @@ void e_time_format_date_and_time (struct tm *date_tm, gboolean use_24_hour_format, gboolean show_midnight, gboolean show_zero_seconds, - char *result, - int result_size); + char *buffer, + int buffer_size); + +/* Formats a time from a struct tm, e.g. "01:59 PM". */ +void e_time_format_time (struct tm *date_tm, + gboolean use_24_hour_format, + gboolean show_zero_seconds, + char *buffer, + int buffer_size); + + + + #endif /* E_TIME_UTILS */ -- cgit v1.2.3