time.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/time.h
  3. // Purpose: Miscellaneous time-related functions.
  4. // Author: Vadim Zeitlin
  5. // Created: 2011-11-26
  6. // Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_TIME_H_
  10. #define _WX_TIME_H_
  11. #include "wx/longlong.h"
  12. // Returns the difference between UTC and local time in seconds.
  13. WXDLLIMPEXP_BASE int wxGetTimeZone();
  14. // Get number of seconds since local time 00:00:00 Jan 1st 1970.
  15. extern long WXDLLIMPEXP_BASE wxGetLocalTime();
  16. // Get number of seconds since GMT 00:00:00, Jan 1st 1970.
  17. extern long WXDLLIMPEXP_BASE wxGetUTCTime();
  18. #if wxUSE_LONGLONG
  19. typedef wxLongLong wxMilliClock_t;
  20. inline long wxMilliClockToLong(wxLongLong ll) { return ll.ToLong(); }
  21. #else
  22. typedef double wxMilliClock_t;
  23. inline long wxMilliClockToLong(double d) { return wx_truncate_cast(long, d); }
  24. #endif // wxUSE_LONGLONG
  25. // Get number of milliseconds since local time 00:00:00 Jan 1st 1970
  26. extern wxMilliClock_t WXDLLIMPEXP_BASE wxGetLocalTimeMillis();
  27. #if wxUSE_LONGLONG
  28. // Get the number of milliseconds or microseconds since the Epoch.
  29. wxLongLong WXDLLIMPEXP_BASE wxGetUTCTimeMillis();
  30. wxLongLong WXDLLIMPEXP_BASE wxGetUTCTimeUSec();
  31. #endif // wxUSE_LONGLONG
  32. #define wxGetCurrentTime() wxGetLocalTime()
  33. // on some really old systems gettimeofday() doesn't have the second argument,
  34. // define wxGetTimeOfDay() to hide this difference
  35. #ifdef HAVE_GETTIMEOFDAY
  36. #ifdef WX_GETTIMEOFDAY_NO_TZ
  37. #define wxGetTimeOfDay(tv) gettimeofday(tv)
  38. #else
  39. #define wxGetTimeOfDay(tv) gettimeofday((tv), NULL)
  40. #endif
  41. #endif // HAVE_GETTIMEOFDAY
  42. /* Two wrapper functions for thread safety */
  43. #ifdef HAVE_LOCALTIME_R
  44. #define wxLocaltime_r localtime_r
  45. #else
  46. WXDLLIMPEXP_BASE struct tm *wxLocaltime_r(const time_t*, struct tm*);
  47. #if wxUSE_THREADS && !defined(__WINDOWS__) && !defined(__WATCOMC__)
  48. // On Windows, localtime _is_ threadsafe!
  49. #warning using pseudo thread-safe wrapper for localtime to emulate localtime_r
  50. #endif
  51. #endif
  52. #ifdef HAVE_GMTIME_R
  53. #define wxGmtime_r gmtime_r
  54. #else
  55. WXDLLIMPEXP_BASE struct tm *wxGmtime_r(const time_t*, struct tm*);
  56. #if wxUSE_THREADS && !defined(__WINDOWS__) && !defined(__WATCOMC__)
  57. // On Windows, gmtime _is_ threadsafe!
  58. #warning using pseudo thread-safe wrapper for gmtime to emulate gmtime_r
  59. #endif
  60. #endif
  61. #endif // _WX_TIME_H_