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