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