1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/other-licenses/7zstub/src/Windows/Time.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,66 @@ 1.4 +// Windows/Time.h 1.5 + 1.6 +#ifndef __WINDOWS_TIME_H 1.7 +#define __WINDOWS_TIME_H 1.8 + 1.9 +#include "Common/Types.h" 1.10 +#include "Windows/Defs.h" 1.11 + 1.12 +namespace NWindows { 1.13 +namespace NTime { 1.14 + 1.15 +inline bool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime) 1.16 +{ 1.17 + return BOOLToBool(::DosDateTimeToFileTime(UInt16(dosTime >> 16), 1.18 + UInt16(dosTime & 0xFFFF), &fileTime)); 1.19 +} 1.20 + 1.21 +const UInt32 kHighDosTime = 0xFF9FBF7D; 1.22 +const UInt32 kLowDosTime = 0x210000; 1.23 + 1.24 +inline bool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime) 1.25 +{ 1.26 + WORD datePart, timePart; 1.27 + if (!::FileTimeToDosDateTime(&fileTime, &datePart, &timePart)) 1.28 + { 1.29 + if (fileTime.dwHighDateTime >= 0x01C00000) // 2000 1.30 + dosTime = kHighDosTime; 1.31 + else 1.32 + dosTime = kLowDosTime; 1.33 + return false; 1.34 + } 1.35 + dosTime = (((UInt32)datePart) << 16) + timePart; 1.36 + return true; 1.37 +} 1.38 + 1.39 +const UInt32 kNumTimeQuantumsInSecond = 10000000; 1.40 +const UInt64 kUnixTimeStartValue = ((UInt64)kNumTimeQuantumsInSecond) * 60 * 60 * 24 * 134774; 1.41 + 1.42 +inline void UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime) 1.43 +{ 1.44 + UInt64 v = kUnixTimeStartValue + ((UInt64)unixTime) * kNumTimeQuantumsInSecond; 1.45 + fileTime.dwLowDateTime = (DWORD)v; 1.46 + fileTime.dwHighDateTime = (DWORD)(v >> 32); 1.47 +} 1.48 + 1.49 +inline bool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime) 1.50 +{ 1.51 + UInt64 winTime = (((UInt64)fileTime.dwHighDateTime) << 32) + fileTime.dwLowDateTime; 1.52 + if (winTime < kUnixTimeStartValue) 1.53 + { 1.54 + unixTime = 0; 1.55 + return false; 1.56 + } 1.57 + winTime = (winTime - kUnixTimeStartValue) / kNumTimeQuantumsInSecond; 1.58 + if (winTime > 0xFFFFFFFF) 1.59 + { 1.60 + unixTime = 0xFFFFFFFF; 1.61 + return false; 1.62 + } 1.63 + unixTime = (UInt32)winTime; 1.64 + return true; 1.65 +} 1.66 + 1.67 +}} 1.68 + 1.69 +#endif