aboutsummaryrefslogtreecommitdiff
path: root/CPP/Windows/TimeUtils.h
diff options
context:
space:
mode:
authorIgor Pavlov <87184205+ip7z@users.noreply.github.com>2022-06-20 00:00:00 +0000
committerIgor Pavlov <87184205+ip7z@users.noreply.github.com>2023-12-17 13:35:20 +0500
commita3e1d227377188734b82f023f96f8e25dc40f3e6 (patch)
tree23cad8d47eb23d26ea727b4f7f4a65124f724065 /CPP/Windows/TimeUtils.h
parentf19f813537c7aea1c20749c914e756b54a9c3cf5 (diff)
download7zip-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.h130
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
10inline UInt64 FILETIME_To_UInt64(const FILETIME &ft)
11{
12 return (((UInt64)ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
13}
14
15inline void FILETIME_Clear(FILETIME &ft)
16{
17 ft.dwLowDateTime = 0;
18 ft.dwHighDateTime = 0;
19}
20
21inline 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
9namespace NWindows { 78namespace NWindows {
10namespace NTime { 79namespace NTime {
11 80
12bool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime) throw(); 81bool DosTime_To_FileTime(UInt32 dosTime, FILETIME &fileTime) throw();
13bool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime) throw(); 82bool UtcFileTime_To_LocalDosTime(const FILETIME &utc, UInt32 &dosTime) throw();
83bool 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
16UInt64 UnixTimeToFileTime64(UInt32 unixTime) throw(); 86UInt64 UnixTime_To_FileTime64(UInt32 unixTime) throw();
17void UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime) throw(); 87void 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
20UInt64 UnixTime64ToFileTime64(Int64 unixTime) throw(); 90UInt64 UnixTime64_To_FileTime64(Int64 unixTime) throw(); // no check
21bool UnixTime64ToFileTime(Int64 unixTime, FILETIME &fileTime) throw(); 91bool UnixTime64_To_FileTime64(Int64 unixTime, UInt64 &fileTime) throw();
92bool UnixTime64_To_FileTime(Int64 unixTime, FILETIME &fileTime) throw();
22 93
23bool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime) throw(); 94Int64 FileTime64_To_UnixTime64(UInt64 ft64) throw();
24Int64 FileTimeToUnixTime64(const FILETIME &ft) throw(); 95bool FileTime_To_UnixTime(const FILETIME &fileTime, UInt32 &unixTime) throw();
96Int64 FileTime_To_UnixTime64(const FILETIME &ft) throw();
97Int64 FileTime_To_UnixTime64_and_Quantums(const FILETIME &ft, UInt32 &quantums) throw();
25 98
26bool GetSecondsSince1601(unsigned year, unsigned month, unsigned day, 99bool 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
102void GetCurUtc_FiTime(CFiTime &ft) throw();
103#ifdef _WIN32
104#define GetCurUtcFileTime GetCurUtc_FiTime
105#else
28void GetCurUtcFileTime(FILETIME &ft) throw(); 106void GetCurUtcFileTime(FILETIME &ft) throw();
107#endif
29 108
30}} 109}}
31 110
111inline 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
118inline void PropVariant_SetFrom_NtfsTime(NWindows::NCOM::CPropVariant &prop, const FILETIME &ft)
119{
120 prop.SetAsTimeFrom_FT_Prec(ft, k_PropVar_TimePrec_100ns);
121}
122
123inline 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
135inline 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