]>
Commit | Line | Data |
---|---|---|
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> | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
2f02cb89 VZ |
13 | #ifndef _WX_DATETIME_H |
14 | #define _WX_DATETIME_H | |
0979c962 VZ |
15 | |
16 | #ifdef __GNUG__ | |
17 | #pragma interface "datetime.h" | |
18 | #endif | |
19 | ||
e421922f VZ |
20 | #if wxUSE_DATETIME |
21 | ||
0979c962 | 22 | #include <time.h> |
b76b015e | 23 | #include <limits.h> // for INT_MIN |
0979c962 VZ |
24 | |
25 | #include "wx/longlong.h" | |
26 | ||
27 | class WXDLLEXPORT wxDateTime; | |
28 | class WXDLLEXPORT wxTimeSpan; | |
29 | class WXDLLEXPORT wxDateSpan; | |
30 | ||
dc84437e | 31 | // a hack: don't use inline functions in debug builds - we don't care about |
2f02cb89 VZ |
32 | // performances and this only leads to increased rebuild time (because every |
33 | // time an inline method is changed, all files including the header must be | |
34 | // rebuilt) | |
dc84437e VZ |
35 | |
36 | // For Mingw32, causes a link error. (VZ: why?) | |
f6bcfd97 | 37 | #if defined( __WXDEBUG__) && !defined(__MINGW32__) |
dc84437e VZ |
38 | #define wxDATETIME_DONT_INLINE |
39 | ||
f6bcfd97 | 40 | #undef inline |
2f02cb89 | 41 | #define inline |
dc84437e VZ |
42 | #else |
43 | // just in case | |
44 | #undef wxDATETIME_DONT_INLINE | |
2f02cb89 VZ |
45 | #endif // Debug |
46 | ||
5b781a67 SC |
47 | // not all c-runtimes are based on 1/1/1970 being (time_t) 0 |
48 | // set this to the corresponding value in seconds 1/1/1970 has on your | |
49 | // systems c-runtime | |
50 | ||
51 | #ifdef __WXMAC__ | |
52 | #if __MSL__ < 0x6000 | |
f5cd9787 | 53 | #define WX_TIME_BASE_OFFSET ( 2082844800L + 126144000L ) |
5b781a67 | 54 | #else |
f5cd9787 | 55 | #define WX_TIME_BASE_OFFSET 0 |
5b781a67 SC |
56 | #endif |
57 | #else | |
f5cd9787 | 58 | #define WX_TIME_BASE_OFFSET 0 |
5b781a67 | 59 | #endif |
0979c962 | 60 | /* |
f6bcfd97 | 61 | * TODO |
0979c962 | 62 | * |
299fcbfe | 63 | * + 1. Time zones with minutes (make TimeZone a class) |
4f6aed9c | 64 | * ? 2. getdate() function like under Solaris |
299fcbfe | 65 | * + 3. text conversion for wxDateSpan |
4f6aed9c VZ |
66 | * + 4. pluggable modules for the workdays calculations |
67 | * 5. wxDateTimeHolidayAuthority for Easter and other christian feasts | |
0979c962 VZ |
68 | */ |
69 | ||
70 | /* | |
299fcbfe | 71 | The three (main) classes declared in this header represent: |
0979c962 VZ |
72 | |
73 | 1. An absolute moment in the time (wxDateTime) | |
74 | 2. A difference between two moments in the time, positive or negative | |
75 | (wxTimeSpan) | |
76 | 3. A logical difference between two dates expressed in | |
77 | years/months/weeks/days (wxDateSpan) | |
78 | ||
79 | The following arithmetic operations are permitted (all others are not): | |
80 | ||
81 | addition | |
82 | -------- | |
83 | ||
84 | wxDateTime + wxTimeSpan = wxDateTime | |
85 | wxDateTime + wxDateSpan = wxDateTime | |
86 | wxTimeSpan + wxTimeSpan = wxTimeSpan | |
87 | wxDateSpan + wxDateSpan = wxDateSpan | |
88 | ||
f6bcfd97 | 89 | subtraction |
0979c962 VZ |
90 | ------------ |
91 | wxDateTime - wxDateTime = wxTimeSpan | |
cd0b1709 VZ |
92 | wxDateTime - wxTimeSpan = wxDateTime |
93 | wxDateTime - wxDateSpan = wxDateTime | |
0979c962 VZ |
94 | wxTimeSpan - wxTimeSpan = wxTimeSpan |
95 | wxDateSpan - wxDateSpan = wxDateSpan | |
96 | ||
97 | multiplication | |
98 | -------------- | |
99 | wxTimeSpan * number = wxTimeSpan | |
cd0b1709 | 100 | number * wxTimeSpan = wxTimeSpan |
0979c962 | 101 | wxDateSpan * number = wxDateSpan |
cd0b1709 | 102 | number * wxDateSpan = wxDateSpan |
0979c962 VZ |
103 | |
104 | unitary minus | |
105 | ------------- | |
106 | -wxTimeSpan = wxTimeSpan | |
107 | -wxDateSpan = wxDateSpan | |
cd0b1709 VZ |
108 | |
109 | For each binary operation OP (+, -, *) we have the following operatorOP=() as | |
f6bcfd97 | 110 | a method and the method with a symbolic name OPER (Add, Subtract, Multiply) |
cd0b1709 VZ |
111 | as a synonym for it and another const method with the same name which returns |
112 | the changed copy of the object and operatorOP() as a global function which is | |
113 | implemented in terms of the const version of OPEN. For the unary - we have | |
114 | operator-() as a method, Neg() as synonym for it and Negate() which returns | |
115 | the copy of the object with the changed sign. | |
0979c962 VZ |
116 | */ |
117 | ||
2ef31e80 VZ |
118 | // an invalid/default date time object which may be used as the default |
119 | // argument for arguments of type wxDateTime; it is also returned by all | |
120 | // functions returning wxDateTime on failure (this is why it is also called | |
121 | // wxInvalidDateTime) | |
122 | class WXDLLEXPORT wxDateTime; | |
123 | ||
56d0c5a6 | 124 | WXDLLEXPORT_DATA(extern const wxDateTime) wxDefaultDateTime; |
2ef31e80 VZ |
125 | #define wxInvalidDateTime wxDefaultDateTime |
126 | ||
0979c962 | 127 | // ---------------------------------------------------------------------------- |
cd0b1709 | 128 | // wxDateTime represents an absolute moment in the time |
0979c962 | 129 | // ---------------------------------------------------------------------------- |
b76b015e | 130 | |
0979c962 VZ |
131 | class WXDLLEXPORT wxDateTime |
132 | { | |
133 | public: | |
134 | // types | |
135 | // ------------------------------------------------------------------------ | |
136 | ||
cd0b1709 VZ |
137 | // a small unsigned integer type for storing things like minutes, |
138 | // seconds &c. It should be at least short (i.e. not char) to contain | |
139 | // the number of milliseconds - it may also be 'int' because there is | |
140 | // no size penalty associated with it in our code, we don't store any | |
141 | // data in this format | |
0979c962 VZ |
142 | typedef unsigned short wxDateTime_t; |
143 | ||
f0f951fa VZ |
144 | // constants |
145 | // ------------------------------------------------------------------------ | |
146 | ||
0979c962 | 147 | // the timezones |
b76b015e | 148 | enum TZ |
0979c962 VZ |
149 | { |
150 | // the time in the current time zone | |
151 | Local, | |
152 | ||
153 | // zones from GMT (= Greenwhich Mean Time): they're guaranteed to be | |
154 | // consequent numbers, so writing something like `GMT0 + offset' is | |
155 | // safe if abs(offset) <= 12 | |
156 | ||
157 | // underscore stands for minus | |
158 | GMT_12, GMT_11, GMT_10, GMT_9, GMT_8, GMT_7, | |
159 | GMT_6, GMT_5, GMT_4, GMT_3, GMT_2, GMT_1, | |
160 | GMT0, | |
161 | GMT1, GMT2, GMT3, GMT4, GMT5, GMT6, | |
162 | GMT7, GMT8, GMT9, GMT10, GMT11, GMT12, | |
163 | // Note that GMT12 and GMT_12 are not the same: there is a difference | |
164 | // of exactly one day between them | |
165 | ||
fcc3d7cb VZ |
166 | // some symbolic names for TZ |
167 | ||
168 | // Europe | |
169 | WET = GMT0, // Western Europe Time | |
170 | WEST = GMT1, // Western Europe Summer Time | |
171 | CET = GMT1, // Central Europe Time | |
172 | CEST = GMT2, // Central Europe Summer Time | |
173 | EET = GMT2, // Eastern Europe Time | |
174 | EEST = GMT3, // Eastern Europe Summer Time | |
175 | MSK = GMT3, // Moscow Time | |
176 | MSD = GMT4, // Moscow Summer Time | |
177 | ||
178 | // US and Canada | |
179 | AST = GMT_4, // Atlantic Standard Time | |
180 | ADT = GMT_3, // Atlantic Daylight Time | |
181 | EST = GMT_5, // Eastern Standard Time | |
182 | EDT = GMT_4, // Eastern Daylight Saving Time | |
183 | CST = GMT_6, // Central Standard Time | |
184 | CDT = GMT_5, // Central Daylight Saving Time | |
185 | MST = GMT_7, // Mountain Standard Time | |
186 | MDT = GMT_6, // Mountain Daylight Saving Time | |
187 | PST = GMT_8, // Pacific Standard Time | |
188 | PDT = GMT_7, // Pacific Daylight Saving Time | |
189 | HST = GMT_10, // Hawaiian Standard Time | |
190 | AKST = GMT_9, // Alaska Standard Time | |
191 | AKDT = GMT_8, // Alaska Daylight Saving Time | |
192 | ||
193 | // Australia | |
194 | ||
195 | A_WST = GMT8, // Western Standard Time | |
196 | A_CST = GMT12 + 1, // Central Standard Time (+9.5) | |
197 | A_EST = GMT10, // Eastern Standard Time | |
198 | A_ESST = GMT11, // Eastern Summer Time | |
199 | ||
200 | // TODO add more symbolic timezone names here | |
201 | ||
202 | // Universal Coordinated Time = the new and politically correct name | |
203 | // for GMT | |
0979c962 | 204 | UTC = GMT0 |
0979c962 VZ |
205 | }; |
206 | ||
207 | // the calendar systems we know about: notice that it's valid (for | |
208 | // this classes purpose anyhow) to work with any of these calendars | |
209 | // even with the dates before the historical appearance of the | |
210 | // calendar | |
211 | enum Calendar | |
212 | { | |
213 | Gregorian, // current calendar | |
214 | Julian // calendar in use since -45 until the 1582 (or later) | |
215 | ||
216 | // TODO Hebrew, Chinese, Maya, ... (just kidding) (or then may be not?) | |
217 | }; | |
218 | ||
219 | // these values only are used to identify the different dates of | |
220 | // adoption of the Gregorian calendar (see IsGregorian()) | |
221 | // | |
222 | // All data and comments taken verbatim from "The Calendar FAQ (v 2.0)" | |
223 |