feat[prep]: room constructor

This commit is contained in:
Jorens Shtekels 2024-03-10 18:24:13 +02:00
parent 6df34b5529
commit 0c529ba023
2 changed files with 18 additions and 3 deletions

View File

@ -1,6 +1,7 @@
#ifndef PREP_H #ifndef PREP_H
#define PREP_H #define PREP_H
#include <chrono>
#include <cstdint> #include <cstdint>
#include <ctime> #include <ctime>
#include <string> #include <string>
@ -31,10 +32,22 @@ struct Player {
}; };
struct Room { struct Room {
uint32_t id;
std::string title; std::string title;
std::tm *utcTimestampCreatedAt; std::tm *utcTimestampCreatedAt;
RoomStatus status; 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<std::chrono::system_clock> 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 { struct Event {

View File

@ -1,7 +1,9 @@
#include "main_lib.h" #include "main_lib.h"
#include "Prep.h" #include "Prep.h"
#include <iostream>
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; } int functionToTest(int a) { return a * 2; }