Coverage Report

Created: 2025-04-11 06:56

/src/unrar/timefn.hpp
Line
Count
Source (jump to first uncovered line)
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
    // It allows dates up to July 2185.
26
    //
27
    // If we'll ever need to extend the date range, we can define a lower
28
    // precision Windows version of TICKS_PER_SECOND. But then Unix and Windows
29
    // versions can differ in least significant digits of "lt" time output
30
    // for Unix archives.
31
    // Alternatively we can introduce 'bool HighPrecision' set to true
32
    // in SetUnixNS() and TicksPerSecond() instead of constant above.
33
    // It might be more reliable than defining TicksPerSecond variable,
34
    // which wouldn't survive memset of any structure hosting RarTime.
35
    // We would need to eliminate all such memsets in the entire code first.
36
    uint64 itime;
37
  public:
38
    // RarLocalTime::Reminder precision. Must be equal to TICKS_PER_SECOND.
39
    // Unlike TICKS_PER_SECOND, it is a public field.
40
    static const uint REMINDER_PRECISION = TICKS_PER_SECOND;
41
  public:
42
570k
    RarTime() {Reset();}
43
0
    bool operator == (const RarTime &rt) const {return itime==rt.itime;}
44
0
    bool operator != (const RarTime &rt) const {return itime!=rt.itime;}
45
0
    bool operator < (const RarTime &rt)  const {return itime<rt.itime;}
46
0
    bool operator <= (const RarTime &rt) const {return itime<rt.itime || itime==rt.itime;}
47
0
    bool operator > (const RarTime &rt)  const {return itime>rt.itime;}
48
0
    bool operator >= (const RarTime &rt) const {return itime>rt.itime || itime==rt.itime;}
49
50
    void GetLocal(RarLocalTime *lt);
51
    void SetLocal(RarLocalTime *lt);
52
#ifdef _WIN_ALL
53
    void GetWinFT(FILETIME *ft);
54
    void SetWinFT(FILETIME *ft);
55
#endif
56
    uint64 GetWin();
57
    void SetWin(uint64 WinTime);
58
    time_t GetUnix();
59
    void SetUnix(time_t ut);
60
    uint64 GetUnixNS();
61
    void SetUnixNS(uint64 ns);
62
    uint GetDos();
63
    void SetDos(uint DosTime);
64
    void GetText(wchar *DateStr,size_t MaxSize,bool FullMS);
65
    void SetIsoText(const wchar *TimeText);
66
    void SetAgeText(const wchar *TimeText);
67
    void SetCurrentTime();
68
885k
    void Reset() {itime=0;}
69
469k
    bool IsSet() {return itime!=0;}
70
    void Adjust(int64 ns);
71
};
72
73
const wchar *GetMonthName(uint Month);
74
bool IsLeapYear(uint Year);
75
76
#endif