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