1 #ifndef _RAR_TIMEFN_
2 #define _RAR_TIMEFN_
3 
4 struct RarLocalTime
5 {
6   uint Year;
7   uint Month;
8   uint Day;
9   uint Hour;
10   uint Minute;
11   uint Second;
12   uint Reminder; // Part of time smaller than 1 second, represented in 1/REMINDER_PRECISION intervals.
13   uint wDay;
14   uint yDay;
15 };
16 
17 
18 class RarTime
19 {
20   private:
21     static const uint TICKS_PER_SECOND = 1000000000; // Internal precision.
22 
23     // Internal time representation in 1/TICKS_PER_SECOND since 01.01.1601.
24     // We use nanoseconds here to handle the high precision Unix time.
25     uint64 itime;
26   public:
27     // RarLocalTime::Reminder precision. Must be equal to TICKS_PER_SECOND.
28     // Unlike TICKS_PER_SECOND, it is a public field.
29     static const uint REMINDER_PRECISION = TICKS_PER_SECOND;
30   public:
RarTime()31     RarTime() {Reset();}
operator ==(RarTime & rt)32     bool operator == (RarTime &rt) {return itime==rt.itime;}
operator !=(RarTime & rt)33     bool operator != (RarTime &rt) {return itime!=rt.itime;}
operator <(RarTime & rt)34     bool operator < (RarTime &rt)  {return itime<rt.itime;}
operator <=(RarTime & rt)35     bool operator <= (RarTime &rt) {return itime<rt.itime || itime==rt.itime;}
operator >(RarTime & rt)36     bool operator > (RarTime &rt)  {return itime>rt.itime;}
operator >=(RarTime & rt)37     bool operator >= (RarTime &rt) {return itime>rt.itime || itime==rt.itime;}
38 
39     void GetLocal(RarLocalTime *lt);
40     void SetLocal(RarLocalTime *lt);
41 #ifdef _WIN_ALL
42     void GetWinFT(FILETIME *ft);
43     void SetWinFT(FILETIME *ft);
44 #endif
45     uint64 GetWin();
46     void SetWin(uint64 WinTime);
47     time_t GetUnix();
48     void SetUnix(time_t ut);
49     uint64 GetUnixNS();
50     void SetUnixNS(uint64 ns);
51     uint GetDos();
52     void SetDos(uint DosTime);
53     void GetText(wchar *DateStr,size_t MaxSize,bool FullMS);
54     void SetIsoText(const wchar *TimeText);
55     void SetAgeText(const wchar *TimeText);
56     void SetCurrentTime();
Reset()57     void Reset() {itime=0;}
IsSet()58     bool IsSet() {return itime!=0;}
59     void Adjust(int64 ns);
60 };
61 
62 const wchar *GetMonthName(int Month);
63 bool IsLeapYear(int Year);
64 
65 #endif
66