]>
Commit | Line | Data |
---|---|---|
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 | ||
13 | #ifndef _WX_DATETIME_H | |
14 | #define _WX_DATETIME_H | |
15 | ||
16 | #ifdef __GNUG__ | |
17 | #pragma interface "datetime.h" | |
18 | #endif | |
19 | ||
20 | #if wxUSE_DATETIME | |
21 | ||
22 | #include <time.h> | |
23 | #include <limits.h> // for INT_MIN | |
24 | ||
25 | #include "wx/longlong.h" | |
26 | ||
27 | class WXDLLEXPORT wxDateTime; | |
28 | class WXDLLEXPORT wxTimeSpan; | |
29 | class WXDLLEXPORT wxDateSpan; | |
30 | ||
31 | // a hack: don't use inline functions in debug builds - we don't care about | |
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) | |
35 | ||
36 | // For Mingw32, causes a link error. (VZ: why?) | |
37 | #if defined( __WXDEBUG__) && !defined(__MINGW32__) | |
38 | #define wxDATETIME_DONT_INLINE | |
39 | ||
40 | #undef inline | |
41 | #define inline | |
42 | #else | |
43 | // just in case | |
44 | #undef wxDATETIME_DONT_INLINE | |
45 | #endif // Debug | |
46 | ||
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 | |
53 | #define WX_TIME_BASE_OFFSET ( 2082844800L + 126144000L ) | |
54 | #else | |
55 | #define WX_TIME_BASE_OFFSET 0 | |
56 | #endif | |
57 | #else | |
58 | #define WX_TIME_BASE_OFFSET 0 | |
59 | #endif | |
60 | /* | |
61 | * TODO | |
62 | * | |
63 | * + 1. Time zones with minutes (make TimeZone a class) | |
64 | * ? 2. getdate() function like under Solaris | |
65 | * + 3. text conversion for wxDateSpan | |
66 | * + 4. pluggable modules for the workdays calculations | |
67 | * 5. wxDateTimeHolidayAuthority for Easter and other christian feasts | |
68 | */ | |
69 | ||
70 | /* | |
71 | The three (main) classes declared in this header represent: | |
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 | ||
89 | subtraction | |
90 | ------------ | |
91 | wxDateTime - wxDateTime = wxTimeSpan | |
92 | wxDateTime - wxTimeSpan = wxDateTime | |
93 | wxDateTime - wxDateSpan = wxDateTime | |
94 | wxTimeSpan - wxTimeSpan = wxTimeSpan | |
95 | wxDateSpan - wxDateSpan = wxDateSpan | |
96 | ||
97 | multiplication | |
98 | -------------- | |
99 | wxTimeSpan * number = wxTimeSpan | |
100 | number * wxTimeSpan = wxTimeSpan | |
101 | wxDateSpan * number = wxDateSpan | |
102 | number * wxDateSpan = wxDateSpan | |
103 | ||
104 | unitary minus | |
105 | ------------- | |
106 | -wxTimeSpan = wxTimeSpan | |
107 | -wxDateSpan = wxDateSpan | |
108 | ||
109 | For each binary operation OP (+, -, *) we have the following operatorOP=() as | |
110 | a method and the method with a symbolic name OPER (Add, Subtract, Multiply) | |
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. | |
116 | */ | |
117 | ||
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 | ||
124 | WXDLLEXPORT_DATA(extern const wxDateTime) wxDefaultDateTime; | |
125 | #define wxInvalidDateTime wxDefaultDateTime | |
126 | ||
127 | // ---------------------------------------------------------------------------- | |
128 | // wxDateTime represents an absolute moment in the time | |
129 | // ---------------------------------------------------------------------------- | |
130 | ||
131 | class WXDLLEXPORT wxDateTime | |
132 | { | |
133 | public: | |
134 | // types | |
135 | // ------------------------------------------------------------------------ | |
136 | ||
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 | |
142 | typedef unsigned short wxDateTime_t; | |
143 | ||
144 | // constants | |
145 | // ------------------------------------------------------------------------ | |
146 | ||
147 | // the timezones | |
148 | enum TZ | |
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 | ||
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 | |
204 | UTC = GMT0 | |
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 |