added functions to get timestamp strings
authorHolger Schemel <info@artsoft.org>
Wed, 21 Oct 2020 00:25:21 +0000 (02:25 +0200)
committerHolger Schemel <info@artsoft.org>
Sun, 13 Dec 2020 23:57:59 +0000 (00:57 +0100)
src/libgame/misc.c
src/libgame/misc.h

index d3ce694021fc36fe30e04b263406622ff0c2ad0e..569526af608cf081e8dd976e5e8d581f91567d8e 100644 (file)
@@ -918,6 +918,23 @@ char *getDefaultUserName(int nr)
   return user_name[nr];
 }
 
+char *getTimestampFromEpoch(time_t epoch_seconds)
+{
+  struct tm *now = localtime(&epoch_seconds);
+  static char timestamp[20];
+
+  sprintf(timestamp, "%04d%02d%02d-%02d%02d%02d",
+         now->tm_year + 1900, now->tm_mon + 1, now->tm_mday,
+         now->tm_hour, now->tm_min, now->tm_sec);
+
+  return timestamp;
+}
+
+char *getCurrentTimestamp(void)
+{
+  return getTimestampFromEpoch(time(NULL));
+}
+
 time_t getFileTimestampEpochSeconds(char *filename)
 {
   struct stat file_status;
index e48d21efa0c7cb626983885356b510d8c5e45357..bb7753d77c5763319402ea0b40adce0584fb0534 100644 (file)
@@ -146,6 +146,9 @@ char *getRealName(void);
 char *getFixedUserName(char *);
 char *getDefaultUserName(int);
 
+char *getTimestampFromEpoch(time_t);
+char *getCurrentTimestamp(void);
+
 time_t getFileTimestampEpochSeconds(char *);
 
 char *getBasePath(char *);