diff options
author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2022-06-20 00:00:00 +0000 |
---|---|---|
committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2023-12-17 13:35:20 +0500 |
commit | a3e1d227377188734b82f023f96f8e25dc40f3e6 (patch) | |
tree | 23cad8d47eb23d26ea727b4f7f4a65124f724065 /CPP/Windows/TimeUtils.h | |
parent | f19f813537c7aea1c20749c914e756b54a9c3cf5 (diff) | |
download | 7zip-22.00.tar.gz 7zip-22.00.tar.bz2 7zip-22.00.zip |
22.0022.00
Diffstat (limited to 'CPP/Windows/TimeUtils.h')
-rw-r--r-- | CPP/Windows/TimeUtils.h | 130 |
1 files changed, 122 insertions, 8 deletions
diff --git a/CPP/Windows/TimeUtils.h b/CPP/Windows/TimeUtils.h index d1d8c15..60ee739 100644 --- a/CPP/Windows/TimeUtils.h +++ b/CPP/Windows/TimeUtils.h | |||
@@ -5,28 +5,142 @@ | |||
5 | 5 | ||
6 | #include "../Common/MyTypes.h" | 6 | #include "../Common/MyTypes.h" |
7 | #include "../Common/MyWindows.h" | 7 | #include "../Common/MyWindows.h" |
8 | #include "PropVariant.h" | ||
9 | |||
10 | inline UInt64 FILETIME_To_UInt64(const FILETIME &ft) | ||
11 | { | ||
12 | return (((UInt64)ft.dwHighDateTime) << 32) + ft.dwLowDateTime; | ||
13 | } | ||
14 | |||
15 | inline void FILETIME_Clear(FILETIME &ft) | ||
16 | { | ||
17 | ft.dwLowDateTime = 0; | ||
18 | ft.dwHighDateTime = 0; | ||
19 | } | ||
20 | |||
21 | inline bool FILETIME_IsZero(const FILETIME &ft) | ||
22 | { | ||
23 | return (ft.dwHighDateTime == 0 && ft.dwLowDateTime == 0); | ||
24 | } | ||
25 | |||
26 | |||
27 | #ifdef _WIN32 | ||
28 | #define CFiTime FILETIME | ||
29 | #define Compare_FiTime ::CompareFileTime | ||
30 | inline void FiTime_To_FILETIME(const CFiTime &ts, FILETIME &ft) | ||
31 | { | ||
32 | ft = ts; | ||
33 | } | ||
34 | /* | ||
35 | inline void FILETIME_To_FiTime(const FILETIME &ft, CFiTime &ts) | ||
36 | { | ||
37 | ts = ft; | ||
38 | } | ||
39 | */ | ||
40 | inline void FiTime_Clear(CFiTime &ft) | ||
41 | { | ||
42 | ft.dwLowDateTime = 0; | ||
43 | ft.dwHighDateTime = 0; | ||
44 | } | ||
45 | #else | ||
46 | |||
47 | #include <sys/stat.h> | ||
48 | |||
49 | #if defined(_AIX) | ||
50 | #define CFiTime st_timespec | ||
51 | #else | ||
52 | #define CFiTime timespec | ||
53 | #endif | ||
54 | int Compare_FiTime(const CFiTime *a1, const CFiTime *a2); | ||
55 | bool FILETIME_To_timespec(const FILETIME &ft, CFiTime &ts); | ||
56 | void FiTime_To_FILETIME(const CFiTime &ts, FILETIME &ft); | ||
57 | void FiTime_To_FILETIME_ns100(const CFiTime &ts, FILETIME &ft, unsigned &ns100); | ||
58 | inline void FiTime_Clear(CFiTime &ft) | ||
59 | { | ||
60 | ft.tv_sec = 0; | ||
61 | ft.tv_nsec = 0; | ||
62 | } | ||
63 | |||
64 | #ifdef __APPLE__ | ||
65 | #define ST_MTIME(st) st.st_mtimespec | ||
66 | #define ST_ATIME(st) st.st_atimespec | ||
67 | #define ST_CTIME(st) st.st_ctimespec | ||
68 | #else | ||
69 | #define ST_MTIME(st) st.st_mtim | ||
70 | #define ST_ATIME(st) st.st_atim | ||
71 | #define ST_CTIME(st) st.st_ctim | ||
72 | #endif | ||
73 | |||
74 | #endif | ||
75 | |||
76 | // void FiTime_Normalize_With_Prec(CFiTime &ft, unsigned prec); | ||
8 | 77 | ||
9 | namespace NWindows { | 78 | namespace NWindows { |
10 | namespace NTime { | 79 | namespace NTime { |
11 | 80 | ||
12 | bool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime) throw(); | 81 | bool DosTime_To_FileTime(UInt32 dosTime, FILETIME &fileTime) throw(); |
13 | bool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime) throw(); | 82 | bool UtcFileTime_To_LocalDosTime(const FILETIME &utc, UInt32 &dosTime) throw(); |
83 | bool FileTime_To_DosTime(const FILETIME &fileTime, UInt32 &dosTime) throw(); | ||
14 | 84 | ||
15 | // UInt32 Unix Time : for dates 1970-2106 | 85 | // UInt32 Unix Time : for dates 1970-2106 |
16 | UInt64 UnixTimeToFileTime64(UInt32 unixTime) throw(); | 86 | UInt64 UnixTime_To_FileTime64(UInt32 unixTime) throw(); |
17 | void UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime) throw(); | 87 | void UnixTime_To_FileTime(UInt32 unixTime, FILETIME &fileTime) throw(); |
18 | 88 | ||
19 | // Int64 Unix Time : negative values for dates before 1970 | 89 | // Int64 Unix Time : negative values for dates before 1970 |
20 | UInt64 UnixTime64ToFileTime64(Int64 unixTime) throw(); | 90 | UInt64 UnixTime64_To_FileTime64(Int64 unixTime) throw(); // no check |
21 | bool UnixTime64ToFileTime(Int64 unixTime, FILETIME &fileTime) throw(); | 91 | bool UnixTime64_To_FileTime64(Int64 unixTime, UInt64 &fileTime) throw(); |
92 | bool UnixTime64_To_FileTime(Int64 unixTime, FILETIME &fileTime) throw(); | ||
22 | 93 | ||
23 | bool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime) throw(); | 94 | Int64 FileTime64_To_UnixTime64(UInt64 ft64) throw(); |
24 | Int64 FileTimeToUnixTime64(const FILETIME &ft) throw(); | 95 | bool FileTime_To_UnixTime(const FILETIME &fileTime, UInt32 &unixTime) throw(); |
96 | Int64 FileTime_To_UnixTime64(const FILETIME &ft) throw(); | ||
97 | Int64 FileTime_To_UnixTime64_and_Quantums(const FILETIME &ft, UInt32 &quantums) throw(); | ||
25 | 98 | ||
26 | bool GetSecondsSince1601(unsigned year, unsigned month, unsigned day, | 99 | bool GetSecondsSince1601(unsigned year, unsigned month, unsigned day, |
27 | unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds) throw(); | 100 | unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds) throw(); |
101 | |||
102 | void GetCurUtc_FiTime(CFiTime &ft) throw(); | ||
103 | #ifdef _WIN32 | ||
104 | #define GetCurUtcFileTime GetCurUtc_FiTime | ||
105 | #else | ||
28 | void GetCurUtcFileTime(FILETIME &ft) throw(); | 106 | void GetCurUtcFileTime(FILETIME &ft) throw(); |
107 | #endif | ||
29 | 108 | ||
30 | }} | 109 | }} |
31 | 110 | ||
111 | inline void PropVariant_SetFrom_UnixTime(NWindows::NCOM::CPropVariant &prop, UInt32 unixTime) | ||
112 | { | ||
113 | FILETIME ft; | ||
114 | NWindows::NTime::UnixTime_To_FileTime(unixTime, ft); | ||
115 | prop.SetAsTimeFrom_FT_Prec(ft, k_PropVar_TimePrec_Unix); | ||
116 | } | ||
117 | |||
118 | inline void PropVariant_SetFrom_NtfsTime(NWindows::NCOM::CPropVariant &prop, const FILETIME &ft) | ||
119 | { | ||
120 | prop.SetAsTimeFrom_FT_Prec(ft, k_PropVar_TimePrec_100ns); | ||
121 | } | ||
122 | |||
123 | inline void PropVariant_SetFrom_FiTime(NWindows::NCOM::CPropVariant &prop, const CFiTime &fts) | ||
124 | { | ||
125 | #ifdef _WIN32 | ||
126 | PropVariant_SetFrom_NtfsTime(prop, fts); | ||
127 | #else | ||
128 | unsigned ns100; | ||
129 | FILETIME ft; | ||
130 | FiTime_To_FILETIME_ns100(fts, ft, ns100); | ||
131 | prop.SetAsTimeFrom_FT_Prec_Ns100(ft, k_PropVar_TimePrec_1ns, ns100); | ||
132 | #endif | ||
133 | } | ||
134 | |||
135 | inline bool PropVariant_SetFrom_DosTime(NWindows::NCOM::CPropVariant &prop, UInt32 dosTime) | ||
136 | { | ||
137 | FILETIME localFileTime, utc; | ||
138 | if (!NWindows::NTime::DosTime_To_FileTime(dosTime, localFileTime)) | ||
139 | return false; | ||
140 | if (!LocalFileTimeToFileTime(&localFileTime, &utc)) | ||
141 | return false; | ||
142 | prop.SetAsTimeFrom_FT_Prec(utc, k_PropVar_TimePrec_DOS); | ||
143 | return true; | ||
144 | } | ||
145 | |||
32 | #endif | 146 | #endif |