/* This file is part of mastodon-cpp. * Copyright © 2019 tastytea * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "types_easy.hpp" using namespace Mastodon; Easy::time::operator const system_clock::time_point() const { return timepoint; } Easy::time::operator const string() const { return strtime("%FT%T%z", true); } const string Easy::time::strtime(const string &format, const bool &local) const { constexpr std::uint16_t bufsize = 1024; std::time_t time = system_clock::to_time_t(timepoint); std::tm *tm; if (local) { tm = std::localtime(&time); } else { tm = std::gmtime(&time); } char buffer[bufsize]; std::strftime(buffer, bufsize, format.c_str(), tm); return static_cast(buffer); } std::ostream &Mastodon::Easy::operator <<(std::ostream &out, const Easy::time &t) { const string s = t; // Converts using operator const string(). out << s; return out; }