From 4e990b47671dffd5b069b67a5f7267b6ff875f55 Mon Sep 17 00:00:00 2001
From: Rob Swindell <rob@synchro.net>
Date: Mon, 28 Mar 2022 23:53:58 -0700
Subject: [PATCH] Add minutes_to_str() function

Generates a "Dd Hh Mm" string from a specified number of minutes.
---
 src/sbbs3/date_str.c | 10 ++++++++++
 src/sbbs3/date_str.h |  3 ++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/sbbs3/date_str.c b/src/sbbs3/date_str.c
index d01d5f7b53..c1ef7cca99 100644
--- a/src/sbbs3/date_str.c
+++ b/src/sbbs3/date_str.c
@@ -131,6 +131,16 @@ char* seconds_to_str(uint seconds, char* str)
 	return p;
 }
 
+/* Returns a duration in minutes into a string */
+char* minutes_to_str(uint min, char* str, size_t size)
+{
+	safe_snprintf(str, size, "%ud %uh %um"
+		,min / (24 *60)
+		,(min % (24 * 60)) / 60
+		,min % 60);
+	return str;
+}
+
 /****************************************************************************/
 /****************************************************************************/
 char* hhmmtostr(scfg_t* cfg, struct tm* tm, char* str)
diff --git a/src/sbbs3/date_str.h b/src/sbbs3/date_str.h
index 013d0eede4..8f43fc72ab 100644
--- a/src/sbbs3/date_str.h
+++ b/src/sbbs3/date_str.h
@@ -39,8 +39,9 @@ DLLEXPORT char *	sectostr(uint sec, char *str);
 DLLEXPORT char *	seconds_to_str(uint, char*);
 DLLEXPORT char *	hhmmtostr(scfg_t* cfg, struct tm* tm, char* str);
 DLLEXPORT char *	timestr(scfg_t* cfg, time32_t intime, char* str);
+DLLEXPORT char*		minutes_to_str(uint min, char* str, size_t);
 
 #ifdef __cplusplus
 }
 #endif
-#endif /* Don't add anything after this line */
\ No newline at end of file
+#endif /* Don't add anything after this line */
-- 
GitLab