FileSystemIndexer v0.1.2-beta
File System Indexer - An API to index files from your system
Loading...
Searching...
No Matches
FSI_timeUtils.cpp
Go to the documentation of this file.
2
3#include <chrono>
4#include <ctime>
5
6namespace fsi::utils
7{
8 TimeUtils_DateTime fsClockDataToDT(const fs::file_time_type &time)
9 {
11
12 const auto &sctp = std::chrono::time_point_cast<std::chrono::system_clock::duration>(
13 time - fs::file_time_type::clock::now() + std::chrono::system_clock::now()
14 );
15
16 auto epochSec = std::chrono::time_point_cast<std::chrono::seconds>(sctp);
17 auto epochMs = std::chrono::duration_cast<std::chrono::microseconds>(sctp - epochSec).count();
18
19 std::time_t timeInfo = std::chrono::system_clock::to_time_t(epochSec);
20 std::tm tm{};
21
22 __FSI_LOCALTIME(&timeInfo, &tm);
23
24 // Time
25 dt.hour = tm.tm_hour;
26 dt.min = tm.tm_min;
27 dt.sec = tm.tm_sec;
28 dt.ms = (unsigned int)(epochMs);
29
30 // Date
31 dt.year = tm.tm_year + 1900;
32 dt.month = tm.tm_mon + 1;
33 dt.day = tm.tm_mday;
34
35 return dt;
36 }
37}
38
#define __FSI_LOCALTIME(_tt, _tm)
TimeUtils_DateTime fsClockDataToDT(const fs::file_time_type &time)
Set std::filesystem clock data to an actual usable Date and Time format.