Added timestamps to example13

This commit is contained in:
tastytea 2018-04-02 02:29:15 +02:00
parent 844fb2c577
commit a0deca93c6
Signed by: tastytea
GPG Key ID: 59346E0EA35C67E5
1 changed files with 16 additions and 1 deletions

View File

@ -9,8 +9,9 @@
#include <string> #include <string>
#include <thread> #include <thread>
#include <memory> #include <memory>
#include <chrono>
#include <vector> #include <vector>
#include <chrono>
#include <ctime>
// If we are compiling mastodon-cpp, use another include path // If we are compiling mastodon-cpp, use another include path
#ifdef MASTODON_CPP #ifdef MASTODON_CPP
@ -25,6 +26,19 @@
using Mastodon::API; using Mastodon::API;
using Mastodon::Easy; using Mastodon::Easy;
using std::cout; 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[]) int main(int argc, char *argv[])
{ {
@ -66,6 +80,7 @@ int main(int argc, char *argv[])
{ {
case Easy::event_type::Update: case Easy::event_type::Update:
status.from_string(event.second); status.from_string(event.second);
cout << "[" << get_localtime(status.created_at()) << "] ";
cout << "Status from: " << status.account().acct() cout << "Status from: " << status.account().acct()
<< " (" << status.url() << ")\n"; << " (" << status.url() << ")\n";
break; break;