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