-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLastModified.cpp
More file actions
54 lines (41 loc) · 955 Bytes
/
Copy pathLastModified.cpp
File metadata and controls
54 lines (41 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "LastModified.h"
#include "Logger.h"
#include <filesystem>
#include <chrono>
#include <ctime>
#include <iomanip>
#include <sstream>
using namespace std;
string LastModified::generate(
const string& file)
{
namespace fs = std::filesystem;
if(!fs::exists(file))
return "";
auto ftime =
fs::last_write_time(file);
auto sctp =
chrono::time_point_cast<
chrono::system_clock::duration
>(
ftime -
fs::file_time_type::clock::now()
+ chrono::system_clock::now()
);
time_t tt =
chrono::system_clock::to_time_t(sctp);
tm utc{};
#ifdef _WIN32
gmtime_s(&utc, &tt);
#else
gmtime_r(&tt, &utc);
#endif
stringstream ss;
ss
<< put_time(
&utc,
"%a, %d %b %Y %H:%M:%S GMT"
);
Logger::debug("LastModified generated for " + file + ": " + ss.str());
return ss.str();
}