1
0
mirror of https://github.com/wesnoth/wesnoth synced 2025-04-24 21:38:14 +00:00
This commit is contained in:
Charles Dang 2025-03-24 22:40:31 -04:00
parent 015809fa4b
commit 0992fde08a
8 changed files with 20 additions and 23 deletions

@ -444,6 +444,9 @@ static bfs::path subtract_path(const bfs::path& full, const bfs::path& prefix_pa
return rest;
}
// Forward declaration, implemented below
std::chrono::system_clock::time_point file_modified_time(const bfs::path& path);
void get_files_in_dir(const std::string& dir,
std::vector<std::string>* files,
std::vector<std::string>* dirs,
@ -504,11 +507,8 @@ void get_files_in_dir(const std::string& dir,
push_if_exists(files, di->path(), mode == name_mode::ENTIRE_FILE_PATH);
if(checksum != nullptr) {
std::time_t mtime = bfs::last_write_time(di->path(), ec);
if(ec) {
LOG_FS << "Failed to read modification time of " << di->path().string() << ": " << ec.message();
} else if(auto t = std::chrono::system_clock::from_time_t(mtime); t > checksum->modified) { // TODO: no from_time_t
checksum->modified = t;
if(auto mtime = file_modified_time(di->path()); mtime > checksum->modified) {
checksum->modified = mtime;
}
uintmax_t size = bfs::file_size(di->path(), ec);
@ -1244,17 +1244,23 @@ bool file_exists(const std::string& name)
return file_exists(bfs::path(name));
}
std::chrono::system_clock::time_point file_modified_time(const std::string& fname)
/** @todo expose to public interface. Most string functions should take a path object */
std::chrono::system_clock::time_point file_modified_time(const bfs::path& path)
{
error_code ec;
std::time_t mtime = bfs::last_write_time(bfs::path(fname), ec);
std::time_t mtime = bfs::last_write_time(path, ec);
if(ec) {
LOG_FS << "Failed to read modification time of " << fname << ": " << ec.message();
LOG_FS << "Failed to read modification time of " << path.string() << ": " << ec.message();
}
return chrono::parse_timestamp(mtime);
}
std::chrono::system_clock::time_point file_modified_time(const std::string& fname)
{
return file_modified_time(bfs::path(fname));
}
bool is_map(const std::string& filename)
{
return bfs::path(filename).extension() == map_extension;

@ -21,7 +21,6 @@
#pragma once
#include <chrono>
#include <ctime>
#include <cstdint>
#include <fstream>
#include <iosfwd>

@ -18,7 +18,7 @@
#include "gettext.hpp"
#include "preferences/preferences.hpp"
#include "serialization/chrono.hpp"
#undef CPP20_CHRONO_SUPPORT
#include <cassert>
#ifndef CPP20_CHRONO_SUPPORT
#include <ctime>
@ -61,10 +61,6 @@ std::string format_time_summary(const std::chrono::system_clock::time_point& t)
// TRANSLATORS: Month + day of month + year, eg 'Nov 02 2021'. Format for your locale.
format_string = _("%b %d %Y");
}
// TODO: make sure this doesn't result in #1709 coming back
assert(!format_string.empty());
return chrono::format_local_timestamp(t, format_string);
#else
const auto now = std::chrono::system_clock::now();
@ -118,10 +114,10 @@ std::string format_time_summary(const std::chrono::system_clock::time_point& t)
// TRANSLATORS: Month + day of month + year, eg 'Nov 02 2021'. Format for your locale.
format_string = _("%b %d %Y");
}
assert(!format_string.empty());
return translation::strftime(format_string, &save_time);
#endif
// TODO: make sure this doesn't result in #1709 coming back
assert(!format_string.empty());
return chrono::format_local_timestamp(t, format_string);
}
} // namespace utils

@ -30,7 +30,6 @@
#include <boost/algorithm/string.hpp>
#include <map>
#include <ctime>
#include <mutex>
#include <iostream>
#include <iomanip>

@ -23,7 +23,6 @@
#include "log.hpp"
#include "serialization/unicode.hpp"
#include <ctime>
#include <iomanip>
#include <iostream>

@ -41,7 +41,6 @@
#include "whiteboard/manager.hpp"
#include <boost/format.hpp>
#include <ctime>
#include <iomanip>
#include <utility>

@ -17,7 +17,6 @@
#include <boost/test/unit_test.hpp>
#include <array>
#include <ctime>
#include "formula/formula.hpp"
#include "formula/callable.hpp"

@ -421,9 +421,9 @@ static int process_command_args(commandline_options& cmdline_opts)
}
if(!cmdline_opts.nobanner) {
const auto now = std::chrono::system_clock::now();
PLAIN_LOG << "Battle for Wesnoth v" << game_config::revision << " " << game_config::build_arch();
static constexpr std::string_view format = "%a %b %d %T %Y"; // equivalent to std::ctime
PLAIN_LOG << "Started on " << chrono::format_local_timestamp(std::chrono::system_clock::now(), format) << '\n';
PLAIN_LOG << "Started on " << chrono::format_local_timestamp(now, "%a %b %d %T %Y") << '\n';
}
if(cmdline_opts.usercache_path) {