mirror of
https://git.mirrors.martin98.com/https://github.com/gulrak/filesystem
synced 2025-07-20 16:44:27 +08:00
Merge branch 'development-v1.1' of github.com:gulrak/filesystem into development-v1.1
This commit is contained in:
commit
2a0c6c3633
@ -95,8 +95,21 @@ template <typename TP>
|
|||||||
std::time_t to_time_t(TP tp)
|
std::time_t to_time_t(TP tp)
|
||||||
{
|
{
|
||||||
// Based on trick from: Nico Josuttis, C++17 - The Complete Guide
|
// Based on trick from: Nico Josuttis, C++17 - The Complete Guide
|
||||||
std::chrono::system_clock::duration dt = std::chrono::duration_cast<std::chrono::system_clock::duration>(tp - TP::clock::now());
|
using namespace std::chrono;
|
||||||
return std::chrono::system_clock::to_time_t(std::chrono::system_clock::now() + dt);
|
auto sctp = time_point_cast<system_clock::duration>(tp - TP::clock::now() + system_clock::now());
|
||||||
|
//system_clock::duration dt = duration_cast<system_clock::duration>(tp - TP::clock::now());
|
||||||
|
return system_clock::to_time_t(sctp);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename TP>
|
||||||
|
TP from_time_t(std::time_t t)
|
||||||
|
{
|
||||||
|
// Based on trick from: Nico Josuttis, C++17 - The Complete Guide
|
||||||
|
using namespace std::chrono;
|
||||||
|
auto sctp = system_clock::from_time_t(t);
|
||||||
|
auto tp = time_point_cast<TP::duration>(sctp - system_clock::now() + TP::clock::now());
|
||||||
|
// system_clock::duration dt = duration_cast<system_clock::duration>(tp - TP::clock::now());
|
||||||
|
return tp;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
@ -118,9 +131,15 @@ struct StringMaker<fs::file_time_type>
|
|||||||
static std::string convert(fs::file_time_type const& value)
|
static std::string convert(fs::file_time_type const& value)
|
||||||
{
|
{
|
||||||
std::time_t t = to_time_t(value);
|
std::time_t t = to_time_t(value);
|
||||||
std::tm ttm = *std::localtime(&t);
|
std::tm* ptm = std::localtime(&t);
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
|
if (ptm) {
|
||||||
|
std::tm ttm = *ptm;
|
||||||
os << std::put_time(&ttm, "%Y-%m-%d %H:%M:%S");
|
os << std::put_time(&ttm, "%Y-%m-%d %H:%M:%S");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
os << "(invalid-time)";
|
||||||
|
}
|
||||||
return os.str();
|
return os.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -2011,7 +2030,7 @@ static fs::file_time_type timeFromString(const std::string& str)
|
|||||||
throw std::exception();
|
throw std::exception();
|
||||||
}
|
}
|
||||||
#ifdef IS_WCHAR_PATH
|
#ifdef IS_WCHAR_PATH
|
||||||
return fs::file_time_type::min();
|
return from_time_t<fs::file_time_type>(std::mktime(&tm));
|
||||||
#else
|
#else
|
||||||
return fs::file_time_type::clock::from_time_t(std::mktime(&tm));
|
return fs::file_time_type::clock::from_time_t(std::mktime(&tm));
|
||||||
#endif
|
#endif
|
||||||
@ -2353,7 +2372,7 @@ TEST_CASE("Windows: Long filename support", "[filesystem][path][fs.path.win.long
|
|||||||
{
|
{
|
||||||
TemporaryDirectory t(TempOpt::change_path);
|
TemporaryDirectory t(TempOpt::change_path);
|
||||||
char c = 'A';
|
char c = 'A';
|
||||||
fs::path dir = fs::current_path();
|
fs::path dir = "\\\\?\\" + fs::current_path().u8string();
|
||||||
for (; c <= 'Z'; ++c) {
|
for (; c <= 'Z'; ++c) {
|
||||||
std::string part = std::string(16, c);
|
std::string part = std::string(16, c);
|
||||||
dir /= part;
|
dir /= part;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user