1999-12-21 01:44:45 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: wx/time.h
|
|
|
|
// Purpose: wxTime class, from NIHCL: this class is deprecated, use
|
|
|
|
// wxDateTime instead
|
1998-05-20 14:01:55 +00:00
|
|
|
// Author: Julian Smart, after K. E. Gorlen
|
1999-12-21 01:44:45 +00:00
|
|
|
// Modified by: 18.12.99 by VZ to use the new wxDateTime class
|
1998-05-20 14:01:55 +00:00
|
|
|
// Created: 01/02/97
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) Julian Smart and Markus Holzem
|
1998-12-08 18:54:05 +00:00
|
|
|
// Licence: wxWindows licence
|
1999-12-21 01:44:45 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1998-08-15 00:23:28 +00:00
|
|
|
#ifndef _WX_TIMEH__
|
|
|
|
#define _WX_TIMEH__
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
#include "wx/defs.h"
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-01-24 14:57:09 +00:00
|
|
|
#if wxUSE_TIMEDATE
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
#include "wx/object.h"
|
|
|
|
#include "wx/datetime.h"
|
|
|
|
#include "wx/date.h"
|
|
|
|
|
2002-08-31 11:29:13 +00:00
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
1999-12-21 01:44:45 +00:00
|
|
|
#pragma interface "time.h"
|
1998-05-20 14:01:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
class WXDLLEXPORT wxDate;
|
|
|
|
|
|
|
|
typedef unsigned short hourTy;
|
|
|
|
typedef unsigned short minuteTy;
|
|
|
|
typedef unsigned short secondTy;
|
|
|
|
typedef unsigned long clockTy;
|
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
// seconds from 1/1/01 to 1/1/70
|
|
|
|
#define wxTIME_EPOCH_DIFF 2177452800UL
|
|
|
|
|
|
|
|
class WXDLLEXPORT wxTime : public wxObject
|
1998-05-20 14:01:55 +00:00
|
|
|
{
|
1999-12-21 01:44:45 +00:00
|
|
|
public:
|
|
|
|
// type definitions
|
1998-12-08 18:54:05 +00:00
|
|
|
enum tFormat { wx12h, wx24h };
|
|
|
|
enum tPrecision { wxStdMinSec, wxStdMin };
|
1999-12-21 01:44:45 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
// current time
|
|
|
|
wxTime() : m_time(wxDateTime::Now()) { }
|
|
|
|
wxTime(clockTy s) : m_time((time_t)(s - wxTIME_EPOCH_DIFF)) { }
|
|
|
|
void operator=(const wxTime& t) { m_time = t.m_time; }
|
2002-05-07 21:58:27 +00:00
|
|
|
wxTime(const wxTime& t) : wxObject() { *this = t; }
|
1999-12-21 01:44:45 +00:00
|
|
|
wxTime(hourTy h, minuteTy m, secondTy s = 0, bool WXUNUSED(dst) = FALSE)
|
|
|
|
: m_time(h, m, s) { }
|
|
|
|
|
|
|
|
wxTime(const wxDate& d, hourTy h = 0, minuteTy m = 0, secondTy s = 0,
|
|
|
|
bool WXUNUSED(dst) = FALSE)
|
|
|
|
: m_time(d.GetDay(), (wxDateTime::Month)d.GetMonth(), d.GetYear(),
|
|
|
|
h, m, s) { }
|
|
|
|
|
|
|
|
wxTime(const wxDateTime& time) : m_time(time) { }
|
|
|
|
|
|
|
|
// Convert to string
|
|
|
|
#ifndef __SALFORDC__
|
|
|
|
operator wxChar *() const { return FormatTime(); }
|
|
|
|
operator wxDate() const { return wxDate(m_time); }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool operator< (const wxTime& t) const { return m_time < t.m_time; }
|
|
|
|
bool operator<=(const wxTime& t) const { return m_time <= t.m_time; }
|
|
|
|
bool operator> (const wxTime& t) const { return m_time > t.m_time; }
|
|
|
|
bool operator>=(const wxTime& t) const { return m_time >= t.m_time; }
|
|
|
|
bool operator==(const wxTime& t) const { return m_time == t.m_time; }
|
|
|
|
bool operator!=(const wxTime& t) const { return m_time != t.m_time; }
|
|
|
|
|
|
|
|
friend wxTime WXDLLEXPORT operator+(const wxTime& t, long s)
|
2000-01-05 15:35:04 +00:00
|
|
|
{ return wxTime(t.m_time + wxTimeSpan::Seconds((int)s)); }
|
1999-12-21 01:44:45 +00:00
|
|
|
friend wxTime WXDLLEXPORT operator+(long s, const wxTime& t)
|
2000-01-05 15:35:04 +00:00
|
|
|
{ return wxTime(t.m_time + wxTimeSpan::Seconds((int)s)); }
|
1999-12-21 01:44:45 +00:00
|
|
|
|
|
|
|
long operator-(const wxTime& t) const
|
|
|
|
{ return (m_time - t.m_time).GetValue().ToLong(); }
|
|
|
|
wxTime operator-(long s) const
|
2000-01-05 15:35:04 +00:00
|
|
|
{ return wxTime(m_time - wxTimeSpan::Seconds((int)s)); }
|
|
|
|
void operator+=(long s) { m_time += wxTimeSpan::Seconds((int)s); }
|
|
|
|
void operator-=(long s) { m_time -= wxTimeSpan::Seconds((int)s); }
|
1999-12-21 01:44:45 +00:00
|
|
|
bool IsBetween(const wxTime& a, const wxTime& b) const
|
|
|
|
{ return *this >= a && *this <= b; }
|
|
|
|
|
|
|
|
// Get day
|
|
|
|
int GetDay() const { return m_time.GetDay(); }
|
|
|
|
// Get month
|
|
|
|
int GetMonth() const { return m_time.GetMonth(); }
|
|
|
|
// Get year
|
|
|
|
int GetYear() const { return m_time.GetYear(); }
|
|
|
|
// Get day of week (0=Sunday 6=Saturday)
|
|
|
|
int GetDayOfWeek() const { return m_time.GetWeekDay(); }
|
|
|
|
|
|
|
|
hourTy GetHour() const { return (hourTy)m_time.GetHour(); }
|
|
|
|
hourTy GetHourGMT() const { return (hourTy)m_time.GetHour(wxDateTime::GMT0); }
|
|
|
|
minuteTy GetMinute() const { return (hourTy)m_time.GetMinute(); }
|
|
|
|
minuteTy GetMinuteGMT() const { return (hourTy)m_time.GetMinute(wxDateTime::GMT0); }
|
|
|
|
secondTy GetSecond() const { return (hourTy)m_time.GetSecond(); }
|
|
|
|
secondTy GetSecondGMT() const { return (hourTy)m_time.GetSecond(wxDateTime::GMT0); }
|
|
|
|
|
|
|
|
clockTy GetSeconds() const { return (clockTy)m_time.GetValue().ToLong(); }
|
|
|
|
|
|
|
|
wxTime Max(const wxTime& t) const { return (t < *this) ? *this : t; }
|
|
|
|
wxTime Min(const wxTime& t) const { return (t > *this) ? *this : t; }
|
|
|
|
|
|
|
|
static void SetFormat(const tFormat lFormat = wx12h,
|
|
|
|
const tPrecision lPrecision = wxStdMinSec)
|
|
|
|
{
|
|
|
|
ms_Format = lFormat;
|
|
|
|
ms_Precision = lPrecision;
|
|
|
|
}
|
|
|
|
|
|
|
|
// (VZ: DANGER: returns pointer to static buffer)
|
|
|
|
wxChar *FormatTime() const
|
|
|
|
{
|
|
|
|
static const wxChar *formats[2][2] =
|
|
|
|
{
|
|
|
|
// wxStdMinSec wxStdMin
|
|
|
|
{ _T("%I:%M:%S %p"), _T("%I:%M %p") }, // wx12h
|
|
|
|
{ _T("%H:%M:%S"), _T("%H:%M") } // wx24h
|
|
|
|
};
|
|
|
|
|
2001-02-15 21:51:14 +00:00
|
|
|
wxStrncpy(ms_bufTime, m_time.Format(formats[ms_Format][ms_Precision]),
|
|
|
|
WXSIZEOF(ms_bufTime));
|
1999-12-21 01:44:45 +00:00
|
|
|
|
2001-02-15 21:51:14 +00:00
|
|
|
return ms_bufTime;
|
1999-12-21 01:44:45 +00:00
|
|
|
}
|
|
|
|
|
1998-05-20 14:01:55 +00:00
|
|
|
private:
|
1999-12-21 01:44:45 +00:00
|
|
|
static tFormat ms_Format;
|
|
|
|
static tPrecision ms_Precision;
|
2001-02-15 21:51:14 +00:00
|
|
|
static wxChar ms_bufTime[128];
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
#if 0 // old wxTime members unused any more
|
1998-12-08 18:54:05 +00:00
|
|
|
clockTy sec; /* seconds since 1/1/1901 */
|
1998-05-20 14:01:55 +00:00
|
|
|
|
1998-12-08 18:54:05 +00:00
|
|
|
bool IsDST() const;
|
|
|
|
wxTime GetLocalTime() const;
|
1999-12-21 01:44:45 +00:00
|
|
|
|
|
|
|
// static member functions
|
1998-12-08 18:54:05 +00:00
|
|
|
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);
|
1999-12-21 01:44:45 +00:00
|
|
|
#endif // 0
|
1998-12-08 18:54:05 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
wxDateTime m_time;
|
1999-01-19 11:00:22 +00:00
|
|
|
|
1999-12-21 01:44:45 +00:00
|
|
|
DECLARE_DYNAMIC_CLASS(wxTime)
|
1998-05-20 14:01:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
1998-09-25 13:28:52 +00:00
|
|
|
// wxUSE_TIMEDATE
|
1998-05-20 14:01:55 +00:00
|
|
|
#endif
|
1998-08-15 00:23:28 +00:00
|
|
|
// _WX_TIMEH__
|
1998-05-20 14:01:55 +00:00
|
|
|
|