X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/34138703c3997ce676a1e713d9ff9eb020640da7..438959cca892a7651634cc3a7aad4819ac49b23c:/include/wx/time.h diff --git a/include/wx/time.h b/include/wx/time.h index 74461c55af..8b79d3ec57 100644 --- a/include/wx/time.h +++ b/include/wx/time.h @@ -1,97 +1,77 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: time.h -// Purpose: wxTime class, from NIHCL -// Author: Julian Smart, after K. E. Gorlen -// Modified by: -// Created: 01/02/97 -// RCS-ID: $Id$ -// Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/time.h +// Purpose: Miscellaneous time-related functions. +// Author: Vadim Zeitlin +// Created: 2011-11-26 +// RCS-ID: $Id: wxhead.h,v 1.12 2010-04-22 12:44:51 zeitlin Exp $ +// Copyright: (c) 2011 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// -#ifndef _WX_TIMEH__ -#define _WX_TIMEH__ +#ifndef _WX_TIME_H_ +#define _WX_TIME_H_ -#include "wx/object.h" +#include "wx/longlong.h" -#if USE_TIMEDATE +// Returns the difference between UTC and local time in seconds. +WXDLLIMPEXP_BASE int wxGetTimeZone(); -#ifdef __GNUG__ -#pragma interface "time.h" -#endif +// Get number of seconds since local time 00:00:00 Jan 1st 1970. +extern long WXDLLIMPEXP_BASE wxGetLocalTime(); + +// Get number of seconds since GMT 00:00:00, Jan 1st 1970. +extern long WXDLLIMPEXP_BASE wxGetUTCTime(); + +#if wxUSE_LONGLONG + typedef wxLongLong wxMilliClock_t; + inline long wxMilliClockToLong(wxLongLong ll) { return ll.ToLong(); } +#else + typedef double wxMilliClock_t; + inline long wxMilliClockToLong(double d) { return wx_truncate_cast(long, d); } +#endif // wxUSE_LONGLONG + +// Get number of milliseconds since local time 00:00:00 Jan 1st 1970 +extern wxMilliClock_t WXDLLIMPEXP_BASE wxGetLocalTimeMillis(); -class WXDLLEXPORT wxDate; +#if wxUSE_LONGLONG -typedef unsigned short hourTy; -typedef unsigned short minuteTy; -typedef unsigned short secondTy; -typedef unsigned long clockTy; +// Get the number of milliseconds or microseconds since the Epoch. +wxLongLong WXDLLIMPEXP_BASE wxGetUTCTimeMillis(); +wxLongLong WXDLLIMPEXP_BASE wxGetUTCTimeUSec(); -class WXDLLEXPORT wxTime: public wxObject -{ - DECLARE_DYNAMIC_CLASS(wxTime) - -public: // type definitions - enum tFormat { wx12h, wx24h }; - enum tPrecision { wxStdMinSec, wxStdMin }; -private: - static tFormat Format; - static tPrecision Precision; +#endif // wxUSE_LONGLONG - clockTy sec; /* seconds since 1/1/1901 */ +#define wxGetCurrentTime() wxGetLocalTime() - bool IsDST() const; - wxTime GetLocalTime() const; -private: // static member functions - static wxTime GetLocalTime(const wxDate& date, hourTy h=0, minuteTy m=0, secondTy s=0); - static wxTime GetBeginDST(unsigned year); - static wxTime GetEndDST(unsigned year); -public: - wxTime(); // current time - wxTime(clockTy s) { sec = s; } - wxTime(const wxTime& t) { (*this) = t ; } - wxTime(hourTy h, minuteTy m, secondTy s =0, bool dst =FALSE); - wxTime(const wxDate&, hourTy h =0, minuteTy m =0, secondTy s=0, bool dst =FALSE); - // Convert to string - operator char * (void); - operator wxDate() const; - bool operator<(const wxTime& t) const { return sec < t.sec; } - bool operator<=(const wxTime& t) const { return sec <= t.sec; } - bool operator>(const wxTime& t) const { return sec > t.sec; } - bool operator>=(const wxTime& t) const { return sec >= t.sec; } - bool operator==(const wxTime& t) const { return sec == t.sec; } - bool operator!=(const wxTime& t) const { return sec != t.sec; } - void operator=(const wxTime& t) { sec = t.sec; } - friend wxTime operator+(const wxTime& t, long s) { return wxTime(t.sec+s); } - friend wxTime operator+(long s, const wxTime& t) { return wxTime(t.sec+s); } - long operator-(const wxTime& t) const { return sec - t.sec; } - wxTime operator-(long s) const { return wxTime(sec-s); } - void operator+=(long s) { sec += s; } - void operator-=(long s) { sec -= s; } - bool IsBetween(const wxTime& a, const wxTime& b) const; - hourTy GetHour() const; // hour in local time - hourTy GetHourGMT() const; // hour in GMT - minuteTy GetMinute() const; // minute in local time - minuteTy GetMinuteGMT() const; // minute in GMT - secondTy GetSecond() const; // second in local time or GMT - clockTy GetSeconds() const { return sec; } - wxTime Max(const wxTime&) const; - wxTime Min(const wxTime&) const; - static void SetFormat(const tFormat lFormat = wx12h, - const tPrecision lPrecision = wxStdMinSec); - char *FormatTime() const; -/* - virtual int compare(const Object&) const; - virtual void deepenShallowCopy(); // {} - virtual unsigned hash() const; - virtual bool isEqual(const Object&) const; - virtual void printOn(ostream& strm =cout) const; - virtual const Class* species() const; -*/ -}; +// on some really old systems gettimeofday() doesn't have the second argument, +// define wxGetTimeOfDay() to hide this difference +#ifdef HAVE_GETTIMEOFDAY + #ifdef WX_GETTIMEOFDAY_NO_TZ + #define wxGetTimeOfDay(tv) gettimeofday(tv) + #else + #define wxGetTimeOfDay(tv) gettimeofday((tv), NULL) + #endif +#endif // HAVE_GETTIMEOFDAY + +/* Two wrapper functions for thread safety */ +#ifdef HAVE_LOCALTIME_R +#define wxLocaltime_r localtime_r +#else +WXDLLIMPEXP_BASE struct tm *wxLocaltime_r(const time_t*, struct tm*); +#if wxUSE_THREADS && !defined(__WINDOWS__) && !defined(__WATCOMC__) + // On Windows, localtime _is_ threadsafe! +#warning using pseudo thread-safe wrapper for localtime to emulate localtime_r +#endif +#endif +#ifdef HAVE_GMTIME_R +#define wxGmtime_r gmtime_r +#else +WXDLLIMPEXP_BASE struct tm *wxGmtime_r(const time_t*, struct tm*); +#if wxUSE_THREADS && !defined(__WINDOWS__) && !defined(__WATCOMC__) + // On Windows, gmtime _is_ threadsafe! +#warning using pseudo thread-safe wrapper for gmtime to emulate gmtime_r #endif - // USE_TIMEDATE #endif - // _WX_TIMEH__ +#endif // _WX_TIME_H_