History

streamline system startup logging

Ge Wang committed 3 years ago

Commit f8d387a1 parent 87efd116 files · +130 −69Browse files

Showing the changes to src/core/util_string.cpp (1 of 6 files). Show all

Unified · Split

src/core/util_string.cpp+34−0
@@ -43,6 +43,7 @@ · 42 unmodified lines
4343 #endif // #ifndef __CHUNREAL_ENGINE__
4444 #endif // #ifdef __PLATFORM_WIN32__
4545
46+#include <time.h>
4647 #include <limits.h>
4748 #include <stdio.h>
4849 using namespace std;
@@ -747,3 +748,36 @@ t_CKBOOL extension_matches( const std::string & filename, const std::string & ex · 698 unmodified lines
747748 // return strncmp( extension, filename+(filename_length-extension_length),
748749 // extension_length ) == 0;
749750 }
751+
752+
753+
754+
755+//-----------------------------------------------------------------------------
756+// name: timestamp_formatted() | 1.5.0.4 (ge) added
757+// desc: return formatted string of current local time; no newline
758+//-----------------------------------------------------------------------------
759+std::string timestamp_formatted()
760+{
761+ // timestamp
762+ char datetime_buf[32];
763+ // how computer sees time
764+ time_t datetime;
765+ // get local time
766+ time( &datetime );
767+ // format time
768+ const char * timestr = ctime(&datetime);
769+ // check if result ok
770+ if( !timestr ) return "[unable to determine/format time]";
771+
772+ // copy formatted date; ctime() always returns fixed length
773+ // e.g., "Sat Jun 24 04:18:42 2023" -- 24 characters... okay
774+ // what happens when the year becomes 5 or more digits?
775+ // in the year 10000...
776+ // will there still be computers? or humans? computer music?!?
777+ strncpy( datetime_buf, timestr, 24 );
778+ // terminate the string
779+ datetime_buf[24] = '\0';
780+
781+ // return the formatted timestamp
782+ return datetime_buf;
783+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t