]> git.saurik.com Git - wxWidgets.git/blame - include/wx/datetime.h
Removed dysfunctional wxPGPropery::PrepareValueForDialogEditing(); Replaced its funct...
[wxWidgets.git] / include / wx / datetime.h
CommitLineData
0979c962
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/datetime.h
3// Purpose: declarations of time/date related classes (wxDateTime,
4// wxTimeSpan)
5// Author: Vadim Zeitlin
6// Modified by:
7// Created: 10.02.99
8// RCS-ID: $Id$
9// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
65571936 10// Licence: wxWindows licence
0979c962
VZ
11/////////////////////////////////////////////////////////////////////////////
12
2f02cb89
VZ
13#ifndef _WX_DATETIME_H
14#define _WX_DATETIME_H
0979c962 15
2b5f62a0
VZ
16#include "wx/defs.h"
17
e421922f
VZ
18#if wxUSE_DATETIME
19
9b4da627
VZ
20#ifdef __WXWINCE__
21 #include "wx/msw/wince/time.h"
22#elif !defined(__WXPALMOS5__)
23 #include <time.h>
24#endif // OS
5e967044 25
b76b015e 26#include <limits.h> // for INT_MIN
0979c962
VZ
27
28#include "wx/longlong.h"
29
b5dbe15d
VS
30class WXDLLIMPEXP_FWD_BASE wxDateTime;
31class WXDLLIMPEXP_FWD_BASE wxTimeSpan;
32class WXDLLIMPEXP_FWD_BASE wxDateSpan;
154014d6
VZ
33#ifdef __WXMSW__
34struct _SYSTEMTIME;
35#endif
0979c962 36
df5168c4 37#include "wx/dynarray.h"
2f02cb89 38
5b781a67
SC
39// not all c-runtimes are based on 1/1/1970 being (time_t) 0
40// set this to the corresponding value in seconds 1/1/1970 has on your
41// systems c-runtime
42
92f89387
SC
43#define WX_TIME_BASE_OFFSET 0
44
0979c962 45/*
f6bcfd97 46 * TODO
0979c962 47 *
299fcbfe 48 * + 1. Time zones with minutes (make TimeZone a class)
4f6aed9c 49 * ? 2. getdate() function like under Solaris
299fcbfe 50 * + 3. text conversion for wxDateSpan
4f6aed9c
VZ
51 * + 4. pluggable modules for the workdays calculations
52 * 5. wxDateTimeHolidayAuthority for Easter and other christian feasts
0979c962
VZ
53 */
54
a452689b
SN
55/* Two wrapper functions for thread safety */
56#ifdef HAVE_LOCALTIME_R
57#define wxLocaltime_r localtime_r
58#else
56560c38 59WXDLLIMPEXP_BASE struct tm *wxLocaltime_r(const time_t*, struct tm*);
740af654 60#if wxUSE_THREADS && !defined(__WINDOWS__) && !defined(__WATCOMC__)
cf44a61c 61 // On Windows, localtime _is_ threadsafe!
a452689b
SN
62#warning using pseudo thread-safe wrapper for localtime to emulate localtime_r
63#endif
cf44a61c 64#endif
a452689b
SN
65
66#ifdef HAVE_GMTIME_R
67#define wxGmtime_r gmtime_r
68#else
56560c38 69WXDLLIMPEXP_BASE struct tm *wxGmtime_r(const time_t*, struct tm*);
740af654 70#if wxUSE_THREADS && !defined(__WINDOWS__) && !defined(__WATCOMC__)
cf44a61c 71 // On Windows, gmtime _is_ threadsafe!
a452689b
SN
72#warning using pseudo thread-safe wrapper for gmtime to emulate gmtime_r
73#endif
cf44a61c 74#endif
a452689b 75
0979c962 76/*
299fcbfe 77 The three (main) classes declared in this header represent:
0979c962
VZ
78
79 1. An absolute moment in the time (wxDateTime)
80 2. A difference between two moments in the time, positive or negative
81 (wxTimeSpan)
82 3. A logical difference between two dates expressed in
83 years/months/weeks/days (wxDateSpan)
84
85 The following arithmetic operations are permitted (all others are not):
86
87 addition
88 --------
89
90 wxDateTime + wxTimeSpan = wxDateTime
91 wxDateTime + wxDateSpan = wxDateTime
92 wxTimeSpan + wxTimeSpan = wxTimeSpan
93 wxDateSpan + wxDateSpan = wxDateSpan
94
f6bcfd97 95 subtraction
0979c962
VZ
96 ------------
97 wxDateTime - wxDateTime = wxTimeSpan
cd0b1709
VZ
98 wxDateTime - wxTimeSpan = wxDateTime
99 wxDateTime - wxDateSpan = wxDateTime
0979c962
VZ
100 wxTimeSpan - wxTimeSpan = wxTimeSpan
101 wxDateSpan - wxDateSpan = wxDateSpan
102
103 multiplication
104 --------------
105 wxTimeSpan * number = wxTimeSpan
cd0b1709 106 number * wxTimeSpan = wxTimeSpan
0979c962 107 wxDateSpan * number = wxDateSpan
cd0b1709 108 number * wxDateSpan = wxDateSpan
0979c962
VZ
109
110 unitary minus
111 -------------
112 -wxTimeSpan = wxTimeSpan
113 -wxDateSpan = wxDateSpan
cd0b1709
VZ
114
115 For each binary operation OP (+, -, *) we have the following operatorOP=() as
f6bcfd97 116 a method and the method with a symbolic name OPER (Add, Subtract, Multiply)
cd0b1709
VZ
117 as a synonym for it and another const method with the same name which returns
118 the changed copy of the object and operatorOP() as a global function which is
119 implemented in terms of the const version of OPEN. For the unary - we have
120 operator-() as a method, Neg() as synonym for it and Negate() which returns
121 the copy of the object with the changed sign.
0979c962
VZ
122*/
123
2ef31e80
VZ
124// an invalid/default date time object which may be used as the default
125// argument for arguments of type wxDateTime; it is also returned by all
126// functions returning wxDateTime on failure (this is why it is also called
127// wxInvalidDateTime)
b5dbe15d 128class WXDLLIMPEXP_FWD_BASE wxDateTime;
2ef31e80 129
71ebd60b
VZ
130extern WXDLLIMPEXP_DATA_BASE(const char *) wxDefaultDateTimeFormat;
131extern WXDLLIMPEXP_DATA_BASE(const char *) wxDefaultTimeSpanFormat;
bddd7a8d 132extern WXDLLIMPEXP_DATA_BASE(const wxDateTime) wxDefaultDateTime;
1aaf88d2 133
2ef31e80
VZ
134#define wxInvalidDateTime wxDefaultDateTime
135
0979c962 136// ----------------------------------------------------------------------------
cd0b1709 137// wxDateTime represents an absolute moment in the time
0979c962 138// ----------------------------------------------------------------------------
b76b015e 139
bddd7a8d 140class WXDLLIMPEXP_BASE wxDateTime
0979c962
VZ
141{
142public:
143 // types
144 // ------------------------------------------------------------------------
145
cd0b1709
VZ
146 // a small unsigned integer type for storing things like minutes,
147 // seconds &c. It should be at least short (i.e. not char) to contain
148 // the number of milliseconds - it may also be 'int' because there is
149 // no size penalty associated with it in our code, we don't store any
150 // data in this format
0979c962
VZ
151 typedef unsigned short wxDateTime_t;
152
f0f951fa
VZ
153 // constants
154 // ------------------------------------------------------------------------
155
0979c962 156 // the timezones
b76b015e 157 enum TZ
0979c962
VZ
158 {
159 // the time in the current time zone
160 Local,
161
162 // zones from GMT (= Greenwhich Mean Time): they're guaranteed to be
163 // consequent numbers, so writing something like `GMT0 + offset' is
164 // safe if abs(offset) <= 12
165
166 // underscore stands for minus
167 GMT_12, GMT_11, GMT_10, GMT_9, GMT_8, GMT_7,
168 GMT_6, GMT_5, GMT_4, GMT_3, GMT_2, GMT_1,
169 GMT0,
170 GMT1, GMT2, GMT3, GMT4, GMT5, GMT6,
34f90a1c 171 GMT7, GMT8, GMT9, GMT10, GMT11, GMT12, GMT13,
0979c962
VZ
172 // Note that GMT12 and GMT_12 are not the same: there is a difference
173 // of exactly one day between them
174
fcc3d7cb
VZ
175 // some symbolic names for TZ
176
177 // Europe
178 WET = GMT0, // Western Europe Time
179 WEST = GMT1, // Western Europe Summer Time
180 CET = GMT1, // Central Europe Time
181 CEST = GMT2, // Central Europe Summer Time
182 EET = GMT2, // Eastern Europe Time
183 EEST = GMT3, // Eastern Europe Summer Time
184 MSK = GMT3, // Moscow Time
185 MSD = GMT4, // Moscow Summer Time
186
187 // US and Canada
188 AST = GMT_4, // Atlantic Standard Time
189 ADT = GMT_3, // Atlantic Daylight Time
190 EST = GMT_5, // Eastern Standard Time
191 EDT = GMT_4, // Eastern Daylight Saving Time
192 CST = GMT_6, // Central Standard Time
193 CDT = GMT_5, // Central Daylight Saving Time
194 MST = GMT_7, // Mountain Standard Time
195 MDT = GMT_6, // Mountain Daylight Saving Time
196 PST = GMT_8, // Pacific Standard Time
197 PDT = GMT_7, // Pacific Daylight Saving Time
198 HST = GMT_10, // Hawaiian Standard Time
199 AKST = GMT_9, // Alaska Standard Time
200 AKDT = GMT_8, // Alaska Daylight Saving Time
201
202 // Australia
203
204 A_WST = GMT8, // Western Standard Time
34f90a1c 205 A_CST = GMT13 + 1, // Central Standard Time (+9.5)
fcc3d7cb
VZ
206 A_EST = GMT10, // Eastern Standard Time
207 A_ESST = GMT11, // Eastern Summer Time
208
34f90a1c
VZ
209 // New Zealand
210 NZST = GMT12, // Standard Time
211 NZDT = GMT13, // Daylight Saving Time
212
fcc3d7cb
VZ
213 // TODO add more symbolic timezone names here
214
215 // Universal Coordinated Time = the new and politically correct name
216 // for GMT
0979c962 217 UTC = GMT0
0979c962
VZ
218 };
219
220 // the calendar systems we know about: notice that it's valid (for
221 // this classes purpose anyhow) to work with any of these calendars
222 // even with the dates before the historical appearance of the
223 // calendar
224 enum Calendar
225 {
226 Gregorian, // current calendar
227 Julian // calendar in use since -45 until the 1582 (or later)
228
229 // TODO Hebrew, Chinese, Maya, ... (just kidding) (or then may be not?)
230 };
231
232 // these values only are used to identify the different dates of
233 // adoption of the Gregorian calendar (see IsGregorian())
234 //
235 // All data and comments taken verbatim from "The Calendar FAQ (v 2.0)"
236