mirror of
https://github.com/jorenchik/mdemory.git
synced 2026-03-22 00:26:21 +00:00
spacing with correct cooldowns and updates
This commit is contained in:
@@ -141,6 +141,18 @@ Result<NoneType> ValidateGrammar(const std::vector<Token>& tokens) {
|
||||
return {};
|
||||
}
|
||||
|
||||
time_t parseToUTCTime(const std::string datetime, std::string format) {
|
||||
std::tm tm = {};
|
||||
std::istringstream ss(datetime);
|
||||
ss >> std::get_time(&tm, format.c_str());
|
||||
if (ss.fail()) {
|
||||
throw std::runtime_error("Failed to parse datetime string");
|
||||
}
|
||||
std::time_t time = timegm(&tm);
|
||||
return time;
|
||||
}
|
||||
|
||||
|
||||
Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
||||
auto questions = std::vector<Question*>();
|
||||
time_t time = 0;
|
||||
@@ -178,16 +190,14 @@ Result<ParseInfo> parseQuestions(const std::vector<Token>& tokens) {
|
||||
};
|
||||
|
||||
if (isInBounds(i) && tokens[i].tokenType == TokenType::TextFragment) {
|
||||
std::tm tm = {};
|
||||
try {
|
||||
strptime(tokens[i].content.c_str(), "%d.%m.%Y %H:%M", &tm);
|
||||
time = parseToUTCTime(tokens[i].content.c_str(), "%d.%m.%Y %H:%M");
|
||||
} catch (std::exception e) {
|
||||
return makeResult(
|
||||
std::format("cannot parse the time - {}", e.what()),
|
||||
tokens[i]
|
||||
);
|
||||
}
|
||||
time = mktime(&tm);
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user