diff --git a/src/prep/CMakeLists.txt b/src/prep/CMakeLists.txt index 6199629..6d9cc1d 100644 --- a/src/prep/CMakeLists.txt +++ b/src/prep/CMakeLists.txt @@ -1 +1 @@ -add_library(prepLib prep.cpp prep.hh) +add_library(prepLib prep.cpp prep.hh timeUtils.cpp timeUtils.hh) diff --git a/src/prep/prep.cpp b/src/prep/prep.cpp index f9e2f6e..5d4d199 100644 --- a/src/prep/prep.cpp +++ b/src/prep/prep.cpp @@ -1,5 +1,14 @@ #include "prep.hh" +#include "timeUtils.hh" + int add(int a, int b) { return a + b; } + +Room::Room(uint32_t id, std::string title, uint32_t utcTimestampCreatedAt, RoomStatus status): + id(id), + title(title), + status(status) { + this->utcTimestampCreatedAt = createUTCTimestamp(utcTimestampCreatedAt); +} diff --git a/src/prep/prep.hh b/src/prep/prep.hh index 4604427..9a8d1aa 100644 --- a/src/prep/prep.hh +++ b/src/prep/prep.hh @@ -61,17 +61,7 @@ struct Room { std::tm *utcTimestampCreatedAt; RoomStatus status; - Room(uint32_t id, std::string title, uint32_t utcTimestampCreatedAt, - RoomStatus status) - : id(id), title(title), status(status) { - // Convert the timestamp into a time_point object - std::chrono::seconds sec(utcTimestampCreatedAt); - std::chrono::time_point tp(sec); - // Convert to time_t for formatting - std::time_t time_object = std::chrono::system_clock::to_time_t(tp); - // Convert to tm as UTC time - this->utcTimestampCreatedAt = std::gmtime(&time_object); - } + Room(uint32_t id, std::string title, uint32_t utcTimestampCreatedAt, RoomStatus status); }; struct Event { diff --git a/src/prep/timeUtils.cpp b/src/prep/timeUtils.cpp new file mode 100644 index 0000000..e52033c --- /dev/null +++ b/src/prep/timeUtils.cpp @@ -0,0 +1,15 @@ +#include "timeUtils.hh" + +#include +#include +#include + +std::tm *createUTCTimestamp(uint32_t timestamp) { + // Convert the timestamp into a time_point object + std::chrono::seconds sec(timestamp); + std::chrono::time_point tp(sec); + // Convert to time_t for formatting + std::time_t time_object = std::chrono::system_clock::to_time_t(tp); + // Convert to tm as UTC time + return std::gmtime(&time_object); +} diff --git a/src/prep/timeUtils.hh b/src/prep/timeUtils.hh new file mode 100644 index 0000000..74060e2 --- /dev/null +++ b/src/prep/timeUtils.hh @@ -0,0 +1,9 @@ +#include +#include + +#ifndef TIMEUTILS_H +# define TIMEUTILS_H + +std::tm *createUTCTimestamp(uint32_t timestamp); + +#endif