diff options
author | B. Stack <bgstack15@gmail.com> | 2021-04-05 15:59:11 +0000 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2021-04-05 15:59:11 +0000 |
commit | 8d28254d708c88ae4aaebbc82cbb6c91726aa390 (patch) | |
tree | dafb5e266c513a5ed9863401e62d246742861e0c /zen/time.h | |
parent | Merge branch '11.7' into 'master' (diff) | |
parent | add upstream 11.9 (diff) | |
download | FreeFileSync-8d28254d708c88ae4aaebbc82cbb6c91726aa390.tar.gz FreeFileSync-8d28254d708c88ae4aaebbc82cbb6c91726aa390.tar.bz2 FreeFileSync-8d28254d708c88ae4aaebbc82cbb6c91726aa390.zip |
Merge branch '11.9' into 'master'11.9
add upstream 11.9
See merge request opensource-tracking/FreeFileSync!32
Diffstat (limited to 'zen/time.h')
-rw-r--r-- | zen/time.h | 46 |
1 files changed, 46 insertions, 0 deletions
@@ -147,12 +147,57 @@ TimeComp getLocalTime(time_t utc) } +//FILETIME: number of 100-nanosecond intervals since January 1, 1601 UTC +//time_t: number of seconds since Jan. 1st 1970 UTC +constexpr auto fileTimeTimetOffset = 11'644'473'600; + + +warn_static("remove after test") +#if 0 +inline +TimeComp getUtcTime2(time_t utc) +{ + utc += year100UnixOffset; //first century not divisible by 400 + + long long remSecs = year100UnixOffset % (24 * 3600); + long long remDays = year100UnixOffset / (24 * 3600); + + constexpr int daysPer400Years = 400 * 365 /*usual days per year*/ + 100 /*leap days */ - 3 /*no leap days for centuries not divisible by 400 */; + + int year = 100 + (remDays / daysPer400Years) * 400; + remDays %= 400; + + constexpr int daysPer100Years = 100 * 365 /*usual days per year*/ + 25 /*leap days */ - 1 /*no leap days for centuries not divisible by 400 */; + + int addCenturies = remDays / daysPer100Years; + if (addCenturies == 4) + --addCenturies; + + year += addCenturies * 100; + remDays -= addCenturies * daysPer100Years; + + constexpr int daysPer4Years = 4 * 365 /*usual days per year*/ + 1 /*leap day */; + + + + constexpr int daysPer100Years = 100 * 365 /*usual days per year*/ + 25 /*leap days */ - 1 /*no leap days for centuries not divisible by 400 */; + constexpr int daysPer100Years = 100 * 365 /*usual days per year*/ + 25 /*leap days */ - 1 /*no leap days for centuries not divisible by 400 */; + constexpr int daysPer100Years = 100 * 365 /*usual days per year*/ + 25 /*leap days */ - 1 /*no leap days for centuries not divisible by 400 */; + constexpr int daysPer100Years = 100 * 365 /*usual days per year*/ + 25 /*leap days */; + + + +} +#endif + + inline TimeComp getUtcTime(time_t utc) { if (utc == -1) //failure code from std::time(nullptr) return TimeComp(); + std::tm ctc = {}; if (::gmtime_r(&utc, &ctc) == nullptr) return TimeComp(); @@ -178,6 +223,7 @@ time_t utcToTimeT(const TimeComp& tc) //returns -1 on error if (tc == TimeComp()) return -1; + std::tm ctc = impl::toClibTimeComponents(tc); ctc.tm_isdst = 0; //"Zero (0) to indicate that standard time is in effect" => unused by _mkgmtime, but take no chances return ::timegm(&ctc); |