OSTime.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //
  2. // Copyright @ 2014 Hangzhou Topzen Ltd.
  3. // Author: Tang (tang@hztopzen.com) @ 2014-12
  4. //
  5. #ifndef __OSTIME_H
  6. #define __OSTIME_H
  7. #include "BaseTypes.h"
  8. #include "BaseHeaders.h"
  9. namespace tzc {
  10. struct DECLDLL OSTime {
  11. TZ_Uint32 year;
  12. TZ_Uint32 month;
  13. TZ_Uint32 day;
  14. TZ_Uint32 hour;
  15. TZ_Uint32 minute;
  16. TZ_Uint32 second;
  17. TZ_Uint32 usecond;
  18. OSTime();
  19. //
  20. // 64 60 48 44 38 32 26 20 0
  21. // |--|------|--|---|---|---|---|----------|
  22. // R Y M D h m s us
  23. //
  24. OSTime(TZ_Uint64 bt);
  25. //
  26. // "YYYY-MM-DD hh:mm:ss.usec"
  27. //
  28. OSTime(const std::string & st);
  29. OSTime(TZ_Uint32 syssec, TZ_Uint32 usec);
  30. static OSTime Now();
  31. static TZ_Uint64 GetOSTick();
  32. static TZ_Uint64 GetOSFreq();
  33. TZ_Uint64 ToUint64() const;
  34. std::string ToString(TZ_Uint32 level = 0) const;
  35. std::string ToStringISO() const;
  36. time_t Syssec() const;
  37. bool operator < (const OSTime & tt) const;
  38. bool operator == (const OSTime & tt) const;
  39. bool operator != (const OSTime & tt) const;
  40. private:
  41. bool timeIsValid(void);
  42. bool isLeapYear(void);
  43. };
  44. }; // namespace tzc
  45. #endif /* ----- #ifndef __TIME_H ----- */