summaryrefslogtreecommitdiff
path: root/src/schemas/channel.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/schemas/channel.hpp')
-rw-r--r--src/schemas/channel.hpp27
1 files changed, 3 insertions, 24 deletions
diff --git a/src/schemas/channel.hpp b/src/schemas/channel.hpp
index a304149..2560331 100644
--- a/src/schemas/channel.hpp
+++ b/src/schemas/channel.hpp
@@ -1,15 +1,12 @@
#pragma once
#include <chrono>
-#include <ctime>
-#include <iomanip>
#include <optional>
#include <pqxx/pqxx>
-#include <sstream>
-#include <stdexcept>
#include <string>
#include "../constants.hpp"
+#include "../utils/chrono.hpp"
namespace bot::schemas {
class Channel {
@@ -19,30 +16,12 @@ namespace bot::schemas {
this->alias_id = row[1].as<int>();
this->alias_name = row[2].as<std::string>();
- std::tm tm = {};
- std::stringstream ss(row[3].as<std::string>());
-
- ss >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S");
-
- if (ss.fail()) {
- throw std::invalid_argument("Invalid time format");
- }
-
this->joined_at =
- std::chrono::system_clock::from_time_t(std::mktime(&tm));
+ utils::chrono::string_to_time_point(row[3].as<std::string>());
if (!row[4].is_null()) {
- tm = {};
- ss = std::stringstream(row[4].as<std::string>());
-
- ss >> std::get_time(&tm, "%Y-%m-%d %H:%M:%S");
-
- if (ss.fail()) {
- throw std::invalid_argument("Invalid time format");
- }
-
this->opted_out_at =
- std::chrono::system_clock::from_time_t(std::mktime(&tm));
+ utils::chrono::string_to_time_point(row[4].as<std::string>());
}
}