other-licenses/7zstub/src/Windows/Time.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Windows/Time.h
michael@0 2
michael@0 3 #ifndef __WINDOWS_TIME_H
michael@0 4 #define __WINDOWS_TIME_H
michael@0 5
michael@0 6 #include "Common/Types.h"
michael@0 7 #include "Windows/Defs.h"
michael@0 8
michael@0 9 namespace NWindows {
michael@0 10 namespace NTime {
michael@0 11
michael@0 12 inline bool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime)
michael@0 13 {
michael@0 14 return BOOLToBool(::DosDateTimeToFileTime(UInt16(dosTime >> 16),
michael@0 15 UInt16(dosTime & 0xFFFF), &fileTime));
michael@0 16 }
michael@0 17
michael@0 18 const UInt32 kHighDosTime = 0xFF9FBF7D;
michael@0 19 const UInt32 kLowDosTime = 0x210000;
michael@0 20
michael@0 21 inline bool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime)
michael@0 22 {
michael@0 23 WORD datePart, timePart;
michael@0 24 if (!::FileTimeToDosDateTime(&fileTime, &datePart, &timePart))
michael@0 25 {
michael@0 26 if (fileTime.dwHighDateTime >= 0x01C00000) // 2000
michael@0 27 dosTime = kHighDosTime;
michael@0 28 else
michael@0 29 dosTime = kLowDosTime;
michael@0 30 return false;
michael@0 31 }
michael@0 32 dosTime = (((UInt32)datePart) << 16) + timePart;
michael@0 33 return true;
michael@0 34 }
michael@0 35
michael@0 36 const UInt32 kNumTimeQuantumsInSecond = 10000000;
michael@0 37 const UInt64 kUnixTimeStartValue = ((UInt64)kNumTimeQuantumsInSecond) * 60 * 60 * 24 * 134774;
michael@0 38
michael@0 39 inline void UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime)
michael@0 40 {
michael@0 41 UInt64 v = kUnixTimeStartValue + ((UInt64)unixTime) * kNumTimeQuantumsInSecond;
michael@0 42 fileTime.dwLowDateTime = (DWORD)v;
michael@0 43 fileTime.dwHighDateTime = (DWORD)(v >> 32);
michael@0 44 }
michael@0 45
michael@0 46 inline bool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime)
michael@0 47 {
michael@0 48 UInt64 winTime = (((UInt64)fileTime.dwHighDateTime) << 32) + fileTime.dwLowDateTime;
michael@0 49 if (winTime < kUnixTimeStartValue)
michael@0 50 {
michael@0 51 unixTime = 0;
michael@0 52 return false;
michael@0 53 }
michael@0 54 winTime = (winTime - kUnixTimeStartValue) / kNumTimeQuantumsInSecond;
michael@0 55 if (winTime > 0xFFFFFFFF)
michael@0 56 {
michael@0 57 unixTime = 0xFFFFFFFF;
michael@0 58 return false;
michael@0 59 }
michael@0 60 unixTime = (UInt32)winTime;
michael@0 61 return true;
michael@0 62 }
michael@0 63
michael@0 64 }}
michael@0 65
michael@0 66 #endif

mercurial