Skip to content

Commit 2d789de

Browse files
committed
refactor: remove util namespace from time
1 parent 2975555 commit 2d789de

File tree

7 files changed

+14
-17
lines changed

7 files changed

+14
-17
lines changed

app/src/core/logger/logger.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void Logger::writeToEngine(const std::string &msg, const std::string &time, cons
6161
return;
6262
}
6363

64-
const auto timestamp = time.empty() ? util::time::datetime_precise() : time;
64+
const auto timestamp = time.empty() ? time::datetime_precise() : time;
6565

6666
const auto id = std::this_thread::get_id();
6767

app/src/core/logger/logger.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ class Logger {
133133
std::string fmt_message;
134134

135135
if constexpr (thread) {
136-
fmt_message = fmt::format(fmt, label, util::time::datetime_precise(), std::this_thread::get_id(), message);
136+
fmt_message = fmt::format(fmt, label, time::datetime_precise(), std::this_thread::get_id(), message);
137137
} else {
138-
fmt_message = fmt::format(fmt, label, util::time::datetime_precise(), "", message);
138+
fmt_message = fmt::format(fmt, label, time::datetime_precise(), "", message);
139139
}
140140

141141
const std::lock_guard<std::mutex> lock(log_mutex_);

app/src/core/time/time.hpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
#include <sstream>
88
#include <string>
99

10-
namespace fastchess::util {
10+
namespace fastchess::time {
1111

1212
namespace sc = std::chrono;
1313

14-
namespace time {
15-
1614
// Get the current date and time in a given format.
1715
[[nodiscard]] inline std::optional<std::string> datetime(const std::string &format) {
1816
// Get the current time in UTC
@@ -64,6 +62,5 @@ namespace time {
6462
ss << str.value_or("") << "." << std::setfill('0') << std::setw(6) << elapsed_ms.count();
6563
return ss.str();
6664
}
67-
} // namespace time
6865

69-
} // namespace fastchess::util
66+
} // namespace fastchess::time

app/src/engine/process/process_posix.hpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ class Process : public IProcess {
318318
LOG_TRACE_THREAD("Terminating process with pid: {} {}", process_pid_, status);
319319

320320
// log the status of the process
321-
Logger::readFromEngine(signalToString(status), util::time::datetime_precise(), log_name_, true);
321+
Logger::readFromEngine(signalToString(status), time::datetime_precise(), log_name_, true);
322322

323323
is_initalized_ = false;
324324
}
@@ -365,8 +365,8 @@ class Process : public IProcess {
365365

366366
// timeout
367367
if (ready == 0) {
368-
if (!current_line_.empty()) lines.emplace_back(Line{current_line_, util::time::datetime_precise()});
369-
if (realtime_logging_) Logger::readFromEngine(current_line_, util::time::datetime_precise(), log_name_);
368+
if (!current_line_.empty()) lines.emplace_back(Line{current_line_, time::datetime_precise()});
369+
if (realtime_logging_) Logger::readFromEngine(current_line_, time::datetime_precise(), log_name_);
370370

371371
return Status::TIMEOUT;
372372
}
@@ -446,7 +446,7 @@ class Process : public IProcess {
446446
// to the vector and reset the current_line_.
447447
// Dont add empty lines
448448
if (!current_line_.empty()) {
449-
const auto time = Logger::should_log_ ? util::time::datetime_precise() : "";
449+
const auto time = Logger::should_log_ ? time::datetime_precise() : "";
450450

451451
lines.emplace_back(Line{current_line_, time});
452452

app/src/engine/process/process_win.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class Process : public IProcess {
270270
}
271271

272272
void addLine(std::vector<Line> &lines) const {
273-
const auto timestamp = Logger::should_log_ ? util::time::datetime_precise() : "";
273+
const auto timestamp = Logger::should_log_ ? time::datetime_precise() : "";
274274

275275
lines.emplace_back(Line{current_line_, timestamp});
276276

app/src/matchmaking/match/match.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ void Match::start(engine::UciEngine& white, engine::UciEngine& black, const std:
209209

210210
data_.variant = config::TournamentConfig->variant;
211211

212-
data_.end_time = util::time::datetime("%Y-%m-%dT%H:%M:%S %z").value_or("-");
213-
data_.duration = util::time::duration(chrono::duration_cast<chrono::seconds>(end - start));
212+
data_.end_time = time::datetime("%Y-%m-%dT%H:%M:%S %z").value_or("-");
213+
data_.duration = time::duration(chrono::duration_cast<chrono::seconds>(end - start));
214214

215215
data_.players = GamePair(MatchData::PlayerInfo{white_player.engine.getConfig(), white_player.getResult()},
216216
MatchData::PlayerInfo{black_player.engine.getConfig(), black_player.getResult()});

app/src/types/match_data.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ struct MatchData {
6363
MatchData() {}
6464

6565
explicit MatchData(std::string fen) : fen(std::move(fen)) {
66-
start_time = util::time::datetime("%Y-%m-%dT%H:%M:%S %z").value_or("-");
67-
date = util::time::datetime("%Y.%m.%d").value_or("-");
66+
start_time = time::datetime("%Y-%m-%dT%H:%M:%S %z").value_or("-");
67+
date = time::datetime("%Y.%m.%d").value_or("-");
6868
}
6969

7070
GamePair<PlayerInfo, PlayerInfo> players;

0 commit comments

Comments
 (0)