aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--e-util/ChangeLog5
-rw-r--r--e-util/e-time-utils.c53
-rw-r--r--e-util/e-time-utils.h15
3 files changed, 63 insertions, 10 deletions
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 <damon@ximian.com>
+
+ * e-time-utils.c (e_time_format_time): added function to format just
+ the time.
+
2001-03-16 Dan Winship <danw@ximian.com>
* 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 */