diff --git a/MakeTimestamp/MakeTimestamp.cpp b/MakeTimestamp/MakeTimestamp.cpp index 94cefc4..100e6a6 100644 --- a/MakeTimestamp/MakeTimestamp.cpp +++ b/MakeTimestamp/MakeTimestamp.cpp @@ -7,7 +7,7 @@ int main(int argc, const char **argv) if (argc != 2) { fprintf(stderr, "Usage: MakeTimestamp \n"); - fprintf(stderr, "Outputs the current timestamp in 1904 epoch format"); + fprintf(stderr, "Outputs the current timestamp in 1904 UTC epoch format"); return -1; } @@ -25,14 +25,11 @@ int main(int argc, const char **argv) if (!SystemTimeToFileTime(&epochStart, &epochStartFT)) return 0; - SYSTEMTIME localTime; - GetLocalTime(&localTime); - - FILETIME localTimeFT; - SystemTimeToFileTime(&localTime, &localTimeFT); + FILETIME timestampFT; + GetSystemTimeAsFileTime(×tampFT); int64_t epochStart64 = (static_cast(epochStartFT.dwLowDateTime) & 0xffffffff) | (static_cast(epochStartFT.dwHighDateTime) << 32); - int64_t currentTime64 = (static_cast(localTimeFT.dwLowDateTime) & 0xffffffff) | (static_cast(localTimeFT.dwHighDateTime) << 32); + int64_t currentTime64 = (static_cast(timestampFT.dwLowDateTime) & 0xffffffff) | (static_cast(timestampFT.dwHighDateTime) << 32); int64_t timeDelta = (currentTime64 - epochStart64) / 10000000; FILE *f = nullptr; @@ -50,5 +47,5 @@ int main(int argc, const char **argv) fclose(f); - return 0; + return 0; } diff --git a/gpr2gpa/gpr2gpa.cpp b/gpr2gpa/gpr2gpa.cpp index fac20e3..0c25f9a 100644 --- a/gpr2gpa/gpr2gpa.cpp +++ b/gpr2gpa/gpr2gpa.cpp @@ -112,38 +112,43 @@ void ConvertToMSDOSTimestamp(int64_t timestamp, uint16_t &msdosDate, uint16_t &m int64_t epochStart64 = (static_cast(epochStartFT.dwLowDateTime) & 0xffffffff) | (static_cast(epochStartFT.dwHighDateTime) << 32); int64_t offsetDate64 = (epochStart64 + timestamp * 10000000); - FILETIME timestampFT; - timestampFT.dwLowDateTime = static_cast(offsetDate64 & 0xffffffff); - timestampFT.dwHighDateTime = static_cast((offsetDate64 >> 32) & 0xffffffff); + FILETIME utcTimestampFT; + utcTimestampFT.dwLowDateTime = static_cast(offsetDate64 & 0xffffffff); + utcTimestampFT.dwHighDateTime = static_cast((offsetDate64 >> 32) & 0xffffffff); - // We could use FileTimeToDosDateTime but we want to clamp - SYSTEMTIME timestampST; - FileTimeToSystemTime(×tampFT, ×tampST); + TIME_ZONE_INFORMATION tzInfo; + GetTimeZoneInformation(&tzInfo); - DWORD yearsSince1980 = timestampST.wYear - 1980; + SYSTEMTIME utcTimestampST; + FileTimeToSystemTime(&utcTimestampFT, &utcTimestampST); + + SYSTEMTIME localTimestampST; + SystemTimeToTzSpecificLocalTime(&tzInfo, &utcTimestampST, &localTimestampST); + + DWORD yearsSince1980 = localTimestampST.wYear - 1980; if (yearsSince1980 < 0) { // Time machine yearsSince1980 = 0; - timestampST.wSecond = 0; - timestampST.wMinute = 0; - timestampST.wHour = 0; - timestampST.wDay = 1; - timestampST.wMonth = 1; + localTimestampST.wSecond = 0; + localTimestampST.wMinute = 0; + localTimestampST.wHour = 0; + localTimestampST.wDay = 1; + localTimestampST.wMonth = 1; } else if (yearsSince1980 > 127) { // I was promised flying cars, but it's 2107 and you're still flying paper airplanes... yearsSince1980 = 127; - timestampST.wSecond = 59; - timestampST.wMinute = 59; - timestampST.wHour = 23; - timestampST.wDay = 31; - timestampST.wMonth = 12; + localTimestampST.wSecond = 59; + localTimestampST.wMinute = 59; + localTimestampST.wHour = 23; + localTimestampST.wDay = 31; + localTimestampST.wMonth = 12; } - msdosTime = (timestampST.wSecond / 2) | (timestampST.wMinute << 5) | (timestampST.wHour << 11); - msdosDate = timestampST.wDay | (timestampST.wMonth << 5) | (yearsSince1980 << 9); + msdosTime = (localTimestampST.wSecond / 2) | (localTimestampST.wMinute << 5) | (localTimestampST.wHour << 11); + msdosDate = localTimestampST.wDay | (localTimestampST.wMonth << 5) | (yearsSince1980 << 9); } void ExportZipFile(const char *path, const std::vector &entries, const PortabilityLayer::MacFileProperties &mfp)