1/*
2 * LegacyClonk
3 *
4 * Copyright (c) 1998-2000, Matthes Bender (RedWolf Design)
5 * Copyright (c) 2017-2020, The LegacyClonk Team and contributors
6 *
7 * Distributed under the terms of the ISC license; see accompanying file
8 * "COPYING" for details.
9 *
10 * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11 * See accompanying file "TRADEMARK" for details.
12 *
13 * To redistribute this file separately, substitute the full license texts
14 * for the above references.
15 */
16
17#include "C4Chrono.h"
18
19#include <ctime>
20
21#ifndef _WIN32
22
23#include <sys/time.h>
24
25unsigned long timeGetTime(void)
26{
27 static time_t sec_offset;
28 timeval tv;
29 gettimeofday(tv: &tv, tz: nullptr);
30 if (!sec_offset) sec_offset = tv.tv_sec;
31 return (tv.tv_sec - sec_offset) * 1000 + tv.tv_usec / 1000;
32}
33
34#endif
35
36const char *GetCurrentTimeStamp(bool enableMarkupColor)
37{
38 static char buf[25];
39
40 time_t timenow;
41 time(timer: &timenow);
42
43 strftime(s: buf, maxsize: sizeof(buf), format: enableMarkupColor ? "<c 909090>[%H:%M:%S]</c>" : "[%H:%M:%S]", tp: localtime(timer: &timenow));
44
45 return buf;
46}
47