From 0c529ba023ab2e91ec530dcef3806ce05191b5be Mon Sep 17 00:00:00 2001 From: Jorens Shtekels Date: Sun, 10 Mar 2024 18:24:13 +0200 Subject: [PATCH] feat[prep]: room constructor --- src/Prep/Prep.h | 15 ++++++++++++++- src/main_lib.cpp | 6 ++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Prep/Prep.h b/src/Prep/Prep.h index d96616d..d06ac12 100644 --- a/src/Prep/Prep.h +++ b/src/Prep/Prep.h @@ -1,6 +1,7 @@ #ifndef PREP_H #define PREP_H +#include #include #include #include @@ -31,10 +32,22 @@ struct Player { }; struct Room { + uint32_t id; std::string title; std::tm *utcTimestampCreatedAt; RoomStatus status; - uint32_t id; + + 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); + } }; struct Event { diff --git a/src/main_lib.cpp b/src/main_lib.cpp index daea41b..c27d9eb 100644 --- a/src/main_lib.cpp +++ b/src/main_lib.cpp @@ -1,7 +1,9 @@ #include "main_lib.h" #include "Prep.h" -#include -void run() { std::cout << add(2, 2) << std::endl; } +void run() { + Room room1(1, "Room 1", 1710087364, RoomStatus::IN_PROGRESS); + Room room2(2, "Room 2", 1710087384, RoomStatus::ENDED); +} int functionToTest(int a) { return a * 2; }