]>
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> | |
65571936 | 10 | // Licence: wxWindows licence |
0979c962 VZ |
11 | ///////////////////////////////////////////////////////////////////////////// |
12 | ||
2f02cb89 VZ |
13 | #ifndef _WX_DATETIME_H |
14 | #define _WX_DATETIME_H | |
0979c962 | 15 | |
2b5f62a0 VZ |
16 | #include "wx/defs.h" |
17 | ||
e421922f VZ |
18 | #if wxUSE_DATETIME |
19 | ||
5e967044 | 20 | #ifndef __WXWINCE__ |
0979c962 | 21 | #include <time.h> |
5e967044 JS |
22 | #else |
23 | #include "wx/msw/wince/time.h" | |
24 | #endif | |
25 | ||
b76b015e | 26 | #include <limits.h> // for INT_MIN |
0979c962 VZ |
27 | |
28 | #include "wx/longlong.h" | |
29 | ||
b5dbe15d VS |
30 | class WXDLLIMPEXP_FWD_BASE wxDateTime; |
31 | class WXDLLIMPEXP_FWD_BASE wxTimeSpan; | |
32 | class WXDLLIMPEXP_FWD_BASE wxDateSpan; | |
0979c962 | 33 | |
df5168c4 | 34 | #include "wx/dynarray.h" |
2f02cb89 | 35 | |
5b781a67 SC |
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 | ||
92f89387 SC |
40 | #define WX_TIME_BASE_OFFSET 0 |
41 | ||
0979c962 | 42 | /* |
f6bcfd97 | 43 | * TODO |
0979c962 | 44 | * |
299fcbfe | 45 | * + 1. Time zones with minutes (make TimeZone a class) |
4f6aed9c | 46 | * ? 2. getdate() function like under Solaris |
299fcbfe | 47 | * + 3. text conversion for wxDateSpan |
4f6aed9c VZ |
48 | * + 4. pluggable modules for the workdays calculations |
49 | * 5. wxDateTimeHolidayAuthority for Easter and other christian feasts | |
0979c962 VZ |
50 | */ |
51 | ||
a452689b SN |
52 | /* Two wrapper functions for thread safety */ |
53 | #ifdef HAVE_LOCALTIME_R | |
54 | #define wxLocaltime_r localtime_r | |
55 | #else | |
56560c38 | 56 | WXDLLIMPEXP_BASE struct tm *wxLocaltime_r(const time_t*, struct tm*); |
740af654 | 57 | #if wxUSE_THREADS && !defined(__WINDOWS__) && !defined(__WATCOMC__) |
cf44a61c | 58 | // On Windows, localtime _is_ threadsafe! |
a452689b SN |
59 | #warning using pseudo thread-safe wrapper for localtime to emulate localtime_r |
60 | #endif | |
cf44a61c | 61 | #endif |
a452689b SN |
62 | |
63 | #ifdef HAVE_GMTIME_R | |
64 | #define wxGmtime_r gmtime_r | |
65 | #else | |
56560c38 | 66 | WXDLLIMPEXP_BASE struct tm *wxGmtime_r(const time_t*, struct tm*); |
740af654 | 67 | #if wxUSE_THREADS && !defined(__WINDOWS__) && !defined(__WATCOMC__) |
cf44a61c | 68 | // On Windows, gmtime _is_ threadsafe! |
a452689b SN |
69 | #warning using pseudo thread-safe wrapper for gmtime to emulate gmtime_r |
70 | #endif | |
cf44a61c | 71 | #endif |
a452689b | 72 | |
0979c962 | 73 | /* |
299fcbfe | 74 | The three (main) classes declared in this header represent: |
0979c962 VZ |
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 | ||
f6bcfd97 | 92 | subtraction |
0979c962 VZ |
93 | ------------ |
94 | wxDateTime - wxDateTime = wxTimeSpan | |
cd0b1709 VZ |
95 | wxDateTime - wxTimeSpan = wxDateTime |
96 | wxDateTime - wxDateSpan = wxDateTime | |
0979c962 VZ |
97 | wxTimeSpan - wxTimeSpan = wxTimeSpan |
98 | wxDateSpan - wxDateSpan = wxDateSpan | |
99 | ||
100 | multiplication | |
101 | -------------- | |
102 | wxTimeSpan * number = wxTimeSpan | |
cd0b1709 | 103 | number * wxTimeSpan = wxTimeSpan |
0979c962 | 104 | wxDateSpan * number = wxDateSpan |
cd0b1709 | 105 | number * wxDateSpan = wxDateSpan |
0979c962 VZ |
106 | |
107 | unitary minus | |
108 | ------------- | |
109 | -wxTimeSpan = wxTimeSpan | |
110 | -wxDateSpan = wxDateSpan | |
cd0b1709 VZ |
111 | |
112 | For each binary operation OP (+, -, *) we have the following operatorOP=() as | |
f6bcfd97 | 113 | a method and the method with a symbolic name OPER (Add, Subtract, Multiply) |
cd0b1709 VZ |
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. | |
0979c962 VZ |
119 | */ |
120 | ||
2ef31e80 VZ |
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) | |
b5dbe15d | 125 | class WXDLLIMPEXP_FWD_BASE wxDateTime; |
2ef31e80 | 126 | |
71ebd60b VZ |
127 | extern WXDLLIMPEXP_DATA_BASE(const char *) wxDefaultDateTimeFormat; |
128 | extern WXDLLIMPEXP_DATA_BASE(const char *) wxDefaultTimeSpanFormat; | |
bddd7a8d | 129 | extern WXDLLIMPEXP_DATA_BASE(const wxDateTime) wxDefaultDateTime; |
1aaf88d2 | 130 | |
2ef31e80 VZ |
131 | #define wxInvalidDateTime wxDefaultDateTime |
132 | ||
0979c962 | 133 | // ---------------------------------------------------------------------------- |
cd0b1709 | 134 | // wxDateTime represents an absolute moment in the time |
0979c962 | 135 | // ---------------------------------------------------------------------------- |
b76b015e | 136 | |
bddd7a8d | 137 | class WXDLLIMPEXP_BASE wxDateTime |
0979c962 VZ |
138 | { |
139 | public: | |
140 | // types | |
141 | // ------------------------------------------------------------------------ | |
142 | ||
cd0b1709 VZ |
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 | |
0979c962 VZ |
148 | typedef unsigned short wxDateTime_t; |
149 | ||
f0f951fa VZ |
150 | // constants |
151 | // ------------------------------------------------------------------------ | |
152 | ||
0979c962 | 153 | // the timezones |
b76b015e | 154 | enum TZ |
0979c962 VZ |
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, | |
34f90a1c | 168 | GMT7, GMT8, GMT9, GMT10, GMT11, GMT12, GMT13, |
0979c962 VZ |
169 | // Note that GMT12 and GMT_12 are not the same: there is a difference |
170 | // of exactly one day between them | |
171 | ||
fcc3d7cb VZ |
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 | |
34f90a1c | 202 | A_CST = GMT13 + 1, // Central Standard Time (+9.5) |
fcc3d7cb VZ |
203 | A_EST = GMT10, // Eastern Standard Time |
204 | A_ESST = GMT11, // Eastern Summer Time | |
205 | ||
34f90a1c VZ |
206 | // New Zealand |
207 | NZST = GMT12, // Standard Time | |
208 | NZDT = GMT13, // Daylight Saving Time | |
209 | ||
fcc3d7cb VZ |
210 | // TODO add more symbolic timezone names here |
211 | ||
212 | // Universal Coordinated Time = the new and politically correct name | |
213 | // for GMT | |
0979c962 | 214 | UTC = GMT0 |
0979c962 VZ |
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 |