From: Holger Schemel Date: Wed, 21 Oct 2020 00:25:21 +0000 (+0200) Subject: added functions to get timestamp strings X-Git-Tag: 4.2.1.0~14 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=dfe5aa4b462c9507926f1c7a1b8c30911bfacef1;p=rocksndiamonds.git added functions to get timestamp strings --- diff --git a/src/libgame/misc.c b/src/libgame/misc.c index d3ce6940..569526af 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -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; diff --git a/src/libgame/misc.h b/src/libgame/misc.h index e48d21ef..bb7753d7 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -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 *);