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