mirror of
https://github.com/jorenchik/testing-spring-2024.git
synced 2025-10-21 20:10:36 +00:00
feat[prep]: move time function into a module
This commit is contained in:
parent
42d1f3b908
commit
0a61c08a0e
@ -1 +1 @@
|
|||||||
add_library(prepLib prep.cpp prep.hh)
|
add_library(prepLib prep.cpp prep.hh timeUtils.cpp timeUtils.hh)
|
||||||
|
|||||||
@ -1,5 +1,14 @@
|
|||||||
#include "prep.hh"
|
#include "prep.hh"
|
||||||
|
|
||||||
|
#include "timeUtils.hh"
|
||||||
|
|
||||||
int add(int a, int b) {
|
int add(int a, int b) {
|
||||||
return a + 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);
|
||||||
|
}
|
||||||
|
|||||||
@ -61,17 +61,7 @@ struct Room {
|
|||||||
std::tm *utcTimestampCreatedAt;
|
std::tm *utcTimestampCreatedAt;
|
||||||
RoomStatus status;
|
RoomStatus status;
|
||||||
|
|
||||||
Room(uint32_t id, std::string title, uint32_t utcTimestampCreatedAt,
|
Room(uint32_t id, std::string title, uint32_t utcTimestampCreatedAt, RoomStatus status);
|
||||||
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 {
|
||||||
|
|||||||
15
src/prep/timeUtils.cpp
Normal file
15
src/prep/timeUtils.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "timeUtils.hh"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
|
std::tm *createUTCTimestamp(uint32_t timestamp) {
|
||||||
|
// Convert the timestamp into a time_point object
|
||||||
|
std::chrono::seconds sec(timestamp);
|
||||||
|
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
|
||||||
|
return std::gmtime(&time_object);
|
||||||
|
}
|
||||||
9
src/prep/timeUtils.hh
Normal file
9
src/prep/timeUtils.hh
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include <cstdint>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
|
#ifndef TIMEUTILS_H
|
||||||
|
# define TIMEUTILS_H
|
||||||
|
|
||||||
|
std::tm *createUTCTimestamp(uint32_t timestamp);
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Reference in New Issue
Block a user