Add more timestamp conversion functions to dateconv.hpp

This commit is contained in:
King_DuckZ 2020-08-10 22:17:42 +01:00
parent 616ac36a34
commit a930622569
3 changed files with 27 additions and 13 deletions

View file

@ -61,4 +61,28 @@ Timestamp from_header_timestamp (const std::string& str) {
//date has this format: Fri, 19 Jun 2020 22:33:43 GMT
return to_timestamp("%a, %d %b %Y %T %Z", str);
}
Timestamp from_sqlite_timestamp (const std::string& str) {
return to_timestamp("%F %T", str);
}
std::string to_sqlite_string (const oro::Timestamp& ts) {
using date::operator<<;
using std::chrono::seconds;
using date::floor;
using date::format;
return format("%F %T", floor<seconds>(ts.ts));
}
//https://en.wikipedia.org/wiki/ISO_8601
std::string to_iso8601_string (const oro::Timestamp& ts) {
using date::operator<<;
using std::chrono::seconds;
using date::floor;
using date::format;
return format("%FT%TZ", floor<seconds>(ts.ts));
}
} //namespace oro

View file

@ -23,4 +23,7 @@
namespace oro {
Timestamp from_json_timestamp (const std::string& str);
Timestamp from_header_timestamp (const std::string& str);
Timestamp from_sqlite_timestamp (const std::string& str);
std::string to_sqlite_string (const Timestamp& ts);
std::string to_iso8601_string (const Timestamp& ts);
} //namespace oro

View file

@ -24,10 +24,6 @@
#include "oro/icons.hpp"
#include "oro/shops.hpp"
#include <mutex>
#include <chrono>
#define HAS_UNCAUGHT_EXCEPTIONS 1
#include "date/date.h"
namespace oro {
@ -40,15 +36,6 @@ namespace {
{
}
};
std::string to_sqlite_string (const oro::Timestamp& ts) {
using date::operator<<;
using std::chrono::seconds;
using date::floor;
using date::format;
return format("%FT%T", floor<seconds>(ts.ts));
}
} //unnamed namespace
OriginsDB::OriginsDB (std::string_view path) :