diff --git a/examples/example13_easy_stream.cpp b/examples/example13_easy_stream.cpp index 0831f5a..5886feb 100644 --- a/examples/example13_easy_stream.cpp +++ b/examples/example13_easy_stream.cpp @@ -9,8 +9,9 @@ #include #include #include -#include #include +#include +#include // If we are compiling mastodon-cpp, use another include path #ifdef MASTODON_CPP @@ -25,6 +26,19 @@ using Mastodon::API; using Mastodon::Easy; using std::cout; +using std::chrono::system_clock; + +// Transform time_point into a tm holding time info for the local timezone +std::string get_localtime(const system_clock::time_point &timepoint) +{ + std::time_t time = system_clock::to_time_t(timepoint); + std::tm *timeinfo = std::localtime(&time); + char buffer[9]; + + std::strftime(buffer, 9, "%T", timeinfo); + + return buffer; +} int main(int argc, char *argv[]) { @@ -66,6 +80,7 @@ int main(int argc, char *argv[]) { case Easy::event_type::Update: status.from_string(event.second); + cout << "[" << get_localtime(status.created_at()) << "] "; cout << "Status from: " << status.account().acct() << " (" << status.url() << ")\n"; break;