Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.6 KiB

  1. //
  2. // MODULE: SafeTime.h
  3. //
  4. // PURPOSE: threadsafe wrappers for some standard time-related calls.
  5. //
  6. // COMPANY: Saltmine Creative, Inc. (206)-284-7511 [email protected]
  7. //
  8. // AUTHOR: Joe Mabel
  9. //
  10. // ORIGINAL DATE: 10-12-98
  11. //
  12. // NOTES:
  13. // 1. gmtime, mktime, and localtime all use a single statically allocated tm structure
  14. // for the conversion. Each call to one of these routines destroys the result of the
  15. // previous call. Obviously, that's not threadsafe.
  16. // 2. Right now this only deals with localtime, because we're not using the other 2 fns.
  17. // If we need to use gmtime or mktime, they'll need to be built analogously, using the
  18. // same mutex.
  19. // 3. _tasctime uses a single, statically allocated buffer to hold its return string.
  20. // Each call to this function destroys the result of the previous call.
  21. //
  22. // Version Date By Comments
  23. //--------------------------------------------------------------------
  24. // V3.0 10-12-98 JM
  25. //
  26. #if !defined(AFX_SAFETIME_H__D5040393_61E9_11D2_960C_00C04FC22ADD__INCLUDED_)
  27. #define AFX_SAFETIME_H__D5040393_61E9_11D2_960C_00C04FC22ADD__INCLUDED_
  28. #if _MSC_VER >= 1000
  29. #pragma once
  30. #endif // _MSC_VER >= 1000
  31. #include <time.h>
  32. #include "apgtsstr.h"
  33. #include "MutexOwner.h"
  34. class CSafeTime
  35. {
  36. private:
  37. static CMutexOwner s_mx;
  38. time_t m_time;
  39. private:
  40. CSafeTime(); // do not instantiate;
  41. public:
  42. CSafeTime(time_t time);
  43. virtual ~CSafeTime();
  44. struct tm LocalTime();
  45. struct tm GMTime();
  46. CString StrLocalTime(LPCTSTR invalid_time =_T("Invalid Date/Time"));
  47. };
  48. #endif // !defined(AFX_SAFETIME_H__D5040393_61E9_11D2_960C_00C04FC22ADD__INCLUDED_)