]> git.saurik.com Git - wxWidgets.git/blob - include/wx/time.h
Return the old file descriptor/pointer from wx(F)File::Detach().
[wxWidgets.git] / include / wx / time.h
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
10 #ifndef _WX_TIME_H_
11 #define _WX_TIME_H_
12
13 #include "wx/longlong.h"
14
15 // Returns the difference between UTC and local time in seconds.
16 WXDLLIMPEXP_BASE int wxGetTimeZone();
17
18 // Get number of seconds since local time 00:00:00 Jan 1st 1970.
19 extern long WXDLLIMPEXP_BASE wxGetLocalTime();
20
21 // Get number of seconds since GMT 00:00:00, Jan 1st 1970.
22 extern long WXDLLIMPEXP_BASE wxGetUTCTime();
23
24 #if wxUSE_LONGLONG
25 typedef wxLongLong wxMilliClock_t;
26 inline long wxMilliClockToLong(wxLongLong ll) { return ll.ToLong(); }
27 #else
28 typedef double wxMilliClock_t;
29 inline long wxMilliClockToLong(double d) { return wx_truncate_cast(long, d); }
30 #endif // wxUSE_LONGLONG
31
32 // Get number of milliseconds since local time 00:00:00 Jan 1st 1970
33 extern wxMilliClock_t WXDLLIMPEXP_BASE wxGetLocalTimeMillis();
34
35 #if wxUSE_LONGLONG
36
37 // Get the number of milliseconds or microseconds since the Epoch.
38 wxLongLong WXDLLIMPEXP_BASE wxGetUTCTimeMillis();
39 wxLongLong WXDLLIMPEXP_BASE wxGetUTCTimeUSec();
40
41 #endif // wxUSE_LONGLONG
42
43 #define wxGetCurrentTime() wxGetLocalTime()
44
45 // on some really old systems gettimeofday() doesn't have the second argument,
46 // define wxGetTimeOfDay() to hide this difference
47 #ifdef HAVE_GETTIMEOFDAY
48 #ifdef WX_GETTIMEOFDAY_NO_TZ
49 #define wxGetTimeOfDay(tv) gettimeofday(tv)
50 #else
51 #define wxGetTimeOfDay(tv) gettimeofday((tv), NULL)
52 #endif
53 #endif // HAVE_GETTIMEOFDAY
54
55 /* Two wrapper functions for thread safety */
56 #ifdef HAVE_LOCALTIME_R
57 #define wxLocaltime_r localtime_r
58 #else
59 WXDLLIMPEXP_BASE struct tm *wxLocaltime_r(const time_t*, struct tm*);
60 #if wxUSE_THREADS && !defined(__WINDOWS__) && !defined(__WATCOMC__)
61 // On Windows, localtime _is_ threadsafe!
62 #warning using pseudo thread-safe wrapper for localtime to emulate localtime_r
63 #endif
64 #endif
65
66 #ifdef HAVE_GMTIME_R
67 #define wxGmtime_r gmtime_r
68 #else
69 WXDLLIMPEXP_BASE struct tm *wxGmtime_r(const time_t*, struct tm*);
70 #if wxUSE_THREADS && !defined(__WINDOWS__) && !defined(__WATCOMC__)
71 // On Windows, gmtime _is_ threadsafe!
72 #warning using pseudo thread-safe wrapper for gmtime to emulate gmtime_r
73 #endif
74 #endif
75
76 #endif // _WX_TIME_H_