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