-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathtimefn.hpp
76 lines (69 loc) · 2.58 KB
/
timefn.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef _RAR_TIMEFN_
#define _RAR_TIMEFN_
struct RarLocalTime
{
uint Year;
uint Month;
uint Day;
uint Hour;
uint Minute;
uint Second;
uint Reminder; // Part of time smaller than 1 second, represented in 1/REMINDER_PRECISION intervals.
uint wDay;
uint yDay;
};
class RarTime
{
private:
static const uint TICKS_PER_SECOND = 1000000000; // Internal precision.
// Internal time representation in 1/TICKS_PER_SECOND since 01.01.1601.
// We use nanoseconds here to handle the high precision Unix time.
// It allows dates up to July 2185.
//
// If we'll ever need to extend the date range, we can define a lower
// precision Windows version of TICKS_PER_SECOND. But then Unix and Windows
// versions can differ in least significant digits of "lt" time output
// for Unix archives.
// Alternatively we can introduce 'bool HighPrecision' set to true
// in SetUnixNS() and TicksPerSecond() instead of constant above.
// It might be more reliable than defining TicksPerSecond variable,
// which wouldn't survive memset of any structure hosting RarTime.
// We would need to eliminate all such memsets in the entire code first.
uint64 itime;
public:
// RarLocalTime::Reminder precision. Must be equal to TICKS_PER_SECOND.
// Unlike TICKS_PER_SECOND, it is a public field.
static const uint REMINDER_PRECISION = TICKS_PER_SECOND;
public:
RarTime() {Reset();}
bool operator == (const RarTime &rt) const {return itime==rt.itime;}
bool operator != (const RarTime &rt) const {return itime!=rt.itime;}
bool operator < (const RarTime &rt) const {return itime<rt.itime;}
bool operator <= (const RarTime &rt) const {return itime<rt.itime || itime==rt.itime;}
bool operator > (const RarTime &rt) const {return itime>rt.itime;}
bool operator >= (const RarTime &rt) const {return itime>rt.itime || itime==rt.itime;}
void GetLocal(RarLocalTime *lt);
void SetLocal(RarLocalTime *lt);
#ifdef _WIN_ALL
void GetWinFT(FILETIME *ft);
void SetWinFT(FILETIME *ft);
#endif
uint64 GetWin();
void SetWin(uint64 WinTime);
time_t GetUnix();
void SetUnix(time_t ut);
uint64 GetUnixNS();
void SetUnixNS(uint64 ns);
uint GetDos();
void SetDos(uint DosTime);
void GetText(wchar *DateStr,size_t MaxSize,bool FullMS);
void SetIsoText(const wchar *TimeText);
void SetAgeText(const wchar *TimeText);
void SetCurrentTime();
void Reset() {itime=0;}
bool IsSet() {return itime!=0;}
void Adjust(int64 ns);
};
const wchar *GetMonthName(uint Month);
bool IsLeapYear(uint Year);
#endif