Browse Source

Add string::formatTime/formatTimeISO().

tags/v2.0.0
Andrew Belt 3 years ago
parent
commit
71423e0e94
3 changed files with 17 additions and 1 deletions
  1. +1
    -1
      adapters/standalone.cpp
  2. +3
    -0
      include/string.hpp
  3. +13
    -0
      src/string.cpp

+ 1
- 1
adapters/standalone.cpp View File

@@ -140,7 +140,7 @@ int main(int argc, char* argv[]) {
#if defined ARCH_MAC
INFO("Bundle path: %s", asset::bundlePath.c_str());
#endif
INFO("System time: %lf", system::getUnixTime());
INFO("System time: %s", string::formatTimeISO(system::getUnixTime()).c_str());

// Load settings
settings::init();


+ 3
- 0
include/string.hpp View File

@@ -79,6 +79,9 @@ Examples:
*/
std::vector<std::string> split(const std::string& s, const std::string& seperator, size_t maxTokens = 0);

std::string formatTime(const char* format, double timestamp);
std::string formatTimeISO(double timestamp);


#if defined ARCH_WIN
/** Performs a Unicode string conversion from UTF-16 to UTF-8.


+ 13
- 0
src/string.cpp View File

@@ -1,3 +1,4 @@
#include <ctime>
#include <cctype> // for tolower and toupper
#include <algorithm> // for transform and equal
#include <libgen.h> // for dirname and basename
@@ -234,6 +235,18 @@ std::vector<std::string> split(const std::string& s, const std::string& separato
}


std::string formatTime(const char* format, double timestamp) {
time_t t = timestamp;
char str[1024];
size_t s = std::strftime(str, sizeof(str), format, std::localtime(&t));
return std::string(str, s);
}

std::string formatTimeISO(double timestamp) {
return formatTime("%FT%T%z", timestamp);
}


#if defined ARCH_WIN
std::string UTF16toUTF8(const std::wstring& w) {
if (w.empty())


Loading…
Cancel
Save