]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/datetime.h
show the item for which the context menu is shown correctly
[wxWidgets.git] / include / wx / datetime.h
... / ...
CommitLineData
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>
10// Licence: wxWindows licence
11/////////////////////////////////////////////////////////////////////////////
12
13#ifndef _WX_DATETIME_H
14#define _WX_DATETIME_H
15
16#include "wx/defs.h"
17
18#if wxUSE_DATETIME
19
20#ifndef __WXWINCE__
21#include <time.h>
22#else
23#include "wx/msw/wince/time.h"
24#endif
25
26#include <limits.h> // for INT_MIN
27
28#include "wx/longlong.h"
29
30class WXDLLIMPEXP_BASE wxDateTime;
31class WXDLLIMPEXP_BASE wxTimeSpan;
32class WXDLLIMPEXP_BASE wxDateSpan;
33
34#include "wx/dynarray.h"
35
36// not all c-runtimes are based on 1/1/1970 being (time_t) 0
37// set this to the corresponding value in seconds 1/1/1970 has on your
38// systems c-runtime
39
40#if defined(__WXMAC__) && !defined(__DARWIN__) && __MSL__ < 0x6000
41 #define WX_TIME_BASE_OFFSET ( 2082844800L + 126144000L )
42#else
43 #define WX_TIME_BASE_OFFSET 0
44#endif
45/*
46 * TODO
47 *
48 * + 1. Time zones with minutes (make TimeZone a class)
49 * ? 2. getdate() function like under Solaris
50 * + 3. text conversion for wxDateSpan
51 * + 4. pluggable modules for the workdays calculations
52 * 5. wxDateTimeHolidayAuthority for Easter and other christian feasts
53 */
54
55/* Two wrapper functions for thread safety */
56#ifdef HAVE_LOCALTIME_R
57#define wxLocaltime_r localtime_r
58#else
59struct 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
69struct 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/*
77 The three (main) classes declared in this header represent:
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
95 subtraction
96 ------------
97 wxDateTime - wxDateTime = wxTimeSpan
98 wxDateTime - wxTimeSpan = wxDateTime
99 wxDateTime - wxDateSpan = wxDateTime
100 wxTimeSpan - wxTimeSpan = wxTimeSpan
101 wxDateSpan - wxDateSpan = wxDateSpan
102
103 multiplication
104 --------------
105 wxTimeSpan * number = wxTimeSpan
106 number * wxTimeSpan = wxTimeSpan
107 wxDateSpan * number = wxDateSpan
108 number * wxDateSpan = wxDateSpan
109
110 unitary minus
111 -------------
112 -wxTimeSpan = wxTimeSpan
113 -wxDateSpan = wxDateSpan
114
115 For each binary operation OP (+, -, *) we have the following operatorOP=() as
116 a method and the method with a symbolic name OPER (Add, Subtract, Multiply)
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.
122*/
123
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)
128class WXDLLIMPEXP_BASE wxDateTime;
129
130extern WXDLLIMPEXP_DATA_BASE(const wxChar*) wxDefaultDateTimeFormat;
131extern WXDLLIMPEXP_DATA_BASE(const wxChar*) wxDefaultTimeSpanFormat;
132extern WXDLLIMPEXP_DATA_BASE(const wxDateTime) wxDefaultDateTime;
133
134#define wxInvalidDateTime wxDefaultDateTime
135
136// ----------------------------------------------------------------------------
137// wxDateTime represents an absolute moment in the time
138// ----------------------------------------------------------------------------
139
140class WXDLLIMPEXP_BASE wxDateTime
141{
142public:
143 // types
144 // ------------------------------------------------------------------------
145
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
151 typedef unsigned short wxDateTime_t;
152
153 // constants
154 // ------------------------------------------------------------------------
155
156 // the timezones
157 enum TZ
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,
171 GMT7, GMT8, GMT9, GMT10, GMT11, GMT12,
172 // Note that GMT12 and GMT_12 are not the same: there is a difference
173 // of exactly one day between them
174
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
205 A_CST = GMT12 + 1, // Central Standard Time (+9.5)
206 A_EST = GMT10, // Eastern Standard Time
207 A_ESST = GMT11, // Eastern Summer Time
208
209 // TODO add more symbolic timezone names here
210
211 // Universal Coordinated Time = the new and politically correct name
212 // for GMT
213 UTC = GMT0
214 };
215
216 // the calendar systems we know about: notice that it's valid (for
217 // this classes purpose anyhow) to work with any of these calendars
218 // even with the dates before the historical appearance of the
219 // calendar
220 enum Calendar
221 {
222 Gregorian, // current calendar
223 Julian // calendar in use since -45 until the 1582 (or later)
224
225 // TODO Hebrew, Chinese, Maya, ... (just kidding) (or then may be not?)
226 };
227
228 // these values only are used to identify the different dates of
229 // adoption of the Gregorian calendar (see IsGregorian())
230 //
231 // All data and comments taken verbatim from "The Calendar FAQ (v 2.0)"
232