hemplate

Simple XML template engine
git clone git://git.dimitrijedobrota.com/hemplate.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING

common.cpp (1133B)


0 #include <chrono> 1 #include <ctime> 2 #include <format> 3 #include <string> 4 5 #include "hemplate/atom.hpp" 6 #include "hemplate/rss.hpp" 7 8 namespace 9 { 10 11 auto sec_since_epoch(int64_t sec) 12 { 13 return std::chrono::time_point_cast<std::chrono::seconds>( 14 std::chrono::system_clock::from_time_t(time_t {0}) 15 + std::chrono::seconds(sec) 16 ); 17 } 18 19 auto get_time_now() 20 { 21 return std::chrono::current_zone() 22 ->to_local(std::chrono::system_clock::now()) 23 .time_since_epoch() 24 / std::chrono::seconds(1); 25 } 26 27 } // namespace 28 29 namespace hemplate::atom 30 { 31 32 std::string format_time(int64_t sec) 33 { 34 static constexpr const char* rfc3339_f = "{:%FT%H:%M:%SZ}"; 35 return std::format(rfc3339_f, sec_since_epoch(sec)); 36 } 37 38 std::string format_time_now() 39 { 40 return format_time(get_time_now()); 41 } 42 43 } // namespace hemplate::atom 44 45 namespace hemplate::rss 46 { 47 48 std::string format_time(int64_t sec) 49 { 50 static constexpr const char* rfc882_f = "{:%a, %d %b %Y %H:%M:%S %z}"; 51 return std::format(rfc882_f, sec_since_epoch(sec)); 52 } 53 54 std::string format_time_now() 55 { 56 return format_time(get_time_now()); 57 } 58 59 } // namespace hemplate::rss