Added timestamps to example13
This commit is contained in:
parent
844fb2c577
commit
a0deca93c6
|
@ -9,8 +9,9 @@
|
|||
#include <string>
|
||||
#include <thread>
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
|
||||
// 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;
|
||||
|
|
Reference in New Issue