1
0

timefn.hpp 1.9 KB

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