]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: datetime.h | |
e54c96f1 | 3 | // Purpose: interface of wxDateTime |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxDateTime | |
11 | @wxheader{datetime.h} | |
7c913512 | 12 | |
23324ae1 | 13 | wxDateTime class represents an absolute moment in the time. |
7c913512 | 14 | |
b9da294f BP |
15 | The type @c wxDateTime_t is typedefed as <tt>unsigned short</tt> and is |
16 | used to contain the number of years, hours, minutes, seconds and | |
17 | milliseconds. | |
18 | ||
19 | ||
20 | @section datetime_constants Constants | |
21 | ||
22 | Global constant wxDefaultDateTime and synonym for it wxInvalidDateTime are | |
23 | defined. This constant will be different from any valid wxDateTime object. | |
24 | ||
25 | All the following constants are defined inside wxDateTime class (i.e., to | |
26 | refer to them you should prepend their names with "wxDateTime::"). | |
27 | ||
28 | Time zone symbolic names: | |
29 | ||
30 | @code | |
31 | enum TZ | |
32 | { | |
33 | // the time in the current time zone | |
34 | Local, | |
35 | ||
36 | // zones from GMT (= Greenwhich Mean Time): they're guaranteed to be | |
37 | // consequent numbers, so writing something like `GMT0 + offset' is | |
38 | // safe if abs(offset) <= 12 | |
39 | ||
40 | // underscore stands for minus | |
41 | GMT_12, GMT_11, GMT_10, GMT_9, GMT_8, GMT_7, | |
42 | GMT_6, GMT_5, GMT_4, GMT_3, GMT_2, GMT_1, | |
43 | GMT0, | |
44 | GMT1, GMT2, GMT3, GMT4, GMT5, GMT6, | |
45 | GMT7, GMT8, GMT9, GMT10, GMT11, GMT12, GMT13, | |
46 | // Note that GMT12 and GMT_12 are not the same: there is a difference | |
47 | // of exactly one day between them | |
48 | ||
49 | // some symbolic names for TZ | |
50 | ||
51 | // Europe | |
f09b5681 BP |
52 | WET = GMT0, // Western Europe Time |
53 | WEST = GMT1, // Western Europe Summer Time | |
54 | CET = GMT1, // Central Europe Time | |
55 | CEST = GMT2, // Central Europe Summer Time | |
56 | EET = GMT2, // Eastern Europe Time | |
57 | EEST = GMT3, // Eastern Europe Summer Time | |
58 | MSK = GMT3, // Moscow Time | |
59 | MSD = GMT4, // Moscow Summer Time | |
b9da294f BP |
60 | |
61 | // US and Canada | |
f09b5681 BP |
62 | AST = GMT_4, // Atlantic Standard Time |
63 | ADT = GMT_3, // Atlantic Daylight Time | |
64 | EST = GMT_5, // Eastern Standard Time | |
65 | EDT = GMT_4, // Eastern Daylight Saving Time | |
66 | CST = GMT_6, // Central Standard Time | |
67 | CDT = GMT_5, // Central Daylight Saving Time | |
68 | MST = GMT_7, // Mountain Standard Time | |
69 | MDT = GMT_6, // Mountain Daylight Saving Time | |
70 | PST = GMT_8, // Pacific Standard Time | |
71 | PDT = GMT_7, // Pacific Daylight Saving Time | |
72 | HST = GMT_10, // Hawaiian Standard Time | |
73 | AKST = GMT_9, // Alaska Standard Time | |
74 | AKDT = GMT_8, // Alaska Daylight Saving Time | |
b9da294f BP |
75 | |
76 | // Australia | |
77 | ||
f09b5681 BP |
78 | A_WST = GMT8, // Western Standard Time |
79 | A_CST = GMT13 + 1, // Central Standard Time (+9.5) | |
80 | A_EST = GMT10, // Eastern Standard Time | |
81 | A_ESST = GMT11, // Eastern Summer Time | |
b9da294f BP |
82 | |
83 | // New Zealand | |
f09b5681 BP |
84 | NZST = GMT12, // Standard Time |
85 | NZDT = GMT13, // Daylight Saving Time | |
b9da294f BP |
86 | |
87 | // Universal Coordinated Time = the new and politically correct name | |
88 | // for GMT | |
89 | UTC = GMT0 | |
90 | }; | |
91 | @endcode | |
92 | ||
93 | Month names: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec and | |
94 | Inv_Month for an invalid month are the values of @c wxDateTime::Month enum. | |
95 | ||
96 | Likewise, Sun, Mon, Tue, Wed, Thu, Fri, Sat, and Inv_WeekDay are the values | |
97 | in @c wxDateTime::WeekDay enum. | |
98 | ||
99 | Finally, Inv_Year is defined to be an invalid value for year parameter. | |
100 | ||
101 | GetMonthName() and GetWeekDayName() functions use the following flags: | |
102 | ||
103 | @code | |
104 | enum NameFlags | |
105 | { | |
106 | Name_Full = 0x01, // return full name | |
107 | Name_Abbr = 0x02 // return abbreviated name | |
108 | }; | |
109 | @endcode | |
110 | ||
111 | Several functions accept an extra parameter specifying the calendar to use | |
112 | (although most of them only support now the Gregorian calendar). This | |
113 | parameters is one of the following values: | |
114 | ||
115 | @code | |
116 | enum Calendar | |
117 | { | |
118 | Gregorian, // calendar currently in use in Western countries | |
119 | Julian // calendar in use since -45 until the 1582 (or later) | |
120 | }; | |
121 | @endcode | |
122 | ||
123 | Date calculations often depend on the country and wxDateTime allows to set | |
124 | the country whose conventions should be used using SetCountry(). It takes | |
125 | one of the following values as parameter: | |
126 | ||
127 | @code | |
128 | enum Country | |
129 | { | |
130 | Country_Unknown, // no special information for this country | |
131 | Country_Default, // set the default country with SetCountry() method | |
132 | // or use the default country with any other | |
133 | ||
134 | Country_WesternEurope_Start, | |
135 | Country_EEC = Country_WesternEurope_Start, | |
136 | France, | |
137 | Germany, | |
138 | UK, | |
139 | Country_WesternEurope_End = UK, | |
140 | ||
141 | Russia, | |
142 | ||
143 | USA | |
144 | }; | |
145 | @endcode | |
146 | ||
147 | Different parts of the world use different conventions for the week start. | |
148 | In some countries, the week starts on Sunday, while in others -- on Monday. | |
149 | The ISO standard doesn't address this issue, so we support both conventions | |
150 | in the functions whose result depends on it (GetWeekOfYear() and | |
151 | GetWeekOfMonth()). | |
152 | ||
153 | The desired behvaiour may be specified by giving one of the following | |
154 | constants as argument to these functions: | |
155 | ||
156 | @code | |
157 | enum WeekFlags | |
158 | { | |
159 | Default_First, // Sunday_First for US, Monday_First for the rest | |
160 | Monday_First, // week starts with a Monday | |
161 | Sunday_First // week starts with a Sunday | |
162 | }; | |
163 | @endcode | |
164 | ||
165 | ||
166 | @section datetime_static Static Functions | |
167 | ||
168 | All static functions either set or return the static variables of | |
169 | wxDateSpan (the country), return the current moment, year, month or number | |
170 | of days in it, or do some general calendar-related actions. | |
171 | ||
172 | Please note that although several function accept an extra Calendar | |
173 | parameter, it is currently ignored as only the Gregorian calendar is | |
174 | supported. Future versions will support other calendars. | |
175 | ||
176 | @beginWxPythonOnly | |
177 | These methods are standalone functions named | |
178 | "wxDateTime_<StaticMethodName>" in wxPython. | |
179 | @endWxPythonOnly | |
180 | ||
181 | ||
182 | @section datetime_formatting Date Formatting and Parsing | |
183 | ||
184 | The date formatting and parsing functions convert wxDateTime objects to and | |
185 | from text. The conversions to text are mostly trivial: you can either do it | |
186 | using the default date and time representations for the current locale | |
187 | (FormatDate() and FormatTime()), using the international standard | |
188 | representation defined by ISO 8601 (FormatISODate(), FormatISOTime() and | |
189 | FormatISOCombined()) or by specifying any format at all and using Format() | |
190 | directly. | |
191 | ||
192 | The conversions from text are more interesting, as there are much more | |
193 | possibilities to care about. The simplest cases can be taken care of with | |
194 | ParseFormat() which can parse any date in the given (rigid) format. | |
195 | ParseRfc822Date() is another function for parsing dates in predefined | |
196 | format -- the one of RFC 822 which (still...) defines the format of email | |
197 | messages on the Internet. This format can not be described with | |
198 | @c strptime(3)-like format strings used by Format(), hence the need for a | |
199 | separate function. | |
200 | ||
201 | But the most interesting functions are ParseTime(), ParseDate() and | |
202 | ParseDateTime(). They try to parse the date and time (or only one of them) | |
203 | in 'free' format, i.e. allow them to be specified in any of possible ways. | |
204 | These functions will usually be used to parse the (interactive) user input | |
205 | which is not bound to be in any predefined format. As an example, | |
206 | ParseDateTime() can parse the strings such as "tomorrow", "March first" and | |
207 | even "next Sunday". | |
208 | ||
209 | Finally notice that each of the parsing functions is available in several | |
210 | overloads: if the input string is a narrow (@c char *) string, then a | |
211 | narrow pointer is returned. If the input string is a wide string, a wide | |
212 | char pointer is returned. Finally, if the input parameter is a wxString, a | |
213 | narrow char pointer is also returned for backwards compatibility but there | |
214 | is also an additional argument of wxString::const_iterator type in which, | |
215 | if it is not @NULL, an iterator pointing to the end of the scanned string | |
216 | part is returned. | |
217 | ||
218 | ||
23324ae1 FM |
219 | @library{wxbase} |
220 | @category{data} | |
7c913512 | 221 | |
65874118 | 222 | @stdobjects |
b9da294f | 223 | - ::wxDefaultDateTime |
65874118 | 224 | |
b9da294f | 225 | @see @ref overview_datetime, wxTimeSpan, wxDateSpan, wxCalendarCtrl |
23324ae1 | 226 | */ |
7c913512 | 227 | class wxDateTime |
23324ae1 FM |
228 | { |
229 | public: | |
230 | /** | |
b9da294f BP |
231 | @name Constructors, Assignment Operators and Setters |
232 | ||
233 | Constructors and various Set() methods are collected here. If you | |
234 | construct a date object from separate values for day, month and year, | |
235 | you should use IsValid() method to check that the values were correct | |
236 | as constructors can not return an error code. | |
23324ae1 | 237 | */ |
b9da294f | 238 | //@{ |
23324ae1 FM |
239 | |
240 | /** | |
b9da294f BP |
241 | Default constructor. Use one of the Set() functions to initialize the |
242 | object later. | |
243 | */ | |
244 | wxDateTime(); | |
245 | /** | |
246 | Same as Set(). | |
3c4f71cc | 247 | |
b9da294f BP |
248 | @beginWxPythonOnly |
249 | This constructor is named "wxDateTimeFromTimeT" in wxPython. | |
250 | @endWxPythonOnly | |
251 | */ | |
252 | wxDateTime& wxDateTime(time_t timet); | |
253 | /** | |
254 | Same as Set(). | |
3c4f71cc | 255 | |
b9da294f BP |
256 | @beginWxPythonOnly Unsupported. @endWxPythonOnly |
257 | */ | |
258 | wxDateTime& wxDateTime(const struct tm& tm); | |
259 | /** | |
260 | Same as Set(). | |
3c4f71cc | 261 | |
b9da294f BP |
262 | @beginWxPythonOnly |
263 | This constructor is named "wxDateTimeFromJDN" in wxPython. | |
264 | @endWxPythonOnly | |
265 | */ | |
266 | wxDateTime& wxDateTime(double jdn); | |
267 | /** | |
268 | Same as Set(). | |
3c4f71cc | 269 | |
b9da294f BP |
270 | @beginWxPythonOnly |
271 | This constructor is named "wxDateTimeFromHMS" in wxPython. | |
272 | @endWxPythonOnly | |
273 | */ | |
274 | wxDateTime& wxDateTime(wxDateTime_t hour, wxDateTime_t minute = 0, | |
275 | wxDateTime_t second = 0, wxDateTime_t millisec = 0); | |
276 | /** | |
277 | Same as Set(). | |
3c4f71cc | 278 | |
b9da294f BP |
279 | @beginWxPythonOnly |
280 | This constructor is named "wxDateTimeFromDMY" in wxPython. | |
281 | @endWxPythonOnly | |
282 | */ | |
283 | wxDateTime(wxDateTime_t day, Month month = Inv_Month, | |
284 | int year = Inv_Year, wxDateTime_t hour = 0, | |
285 | wxDateTime_t minute = 0, wxDateTime_t second = 0, | |
286 | wxDateTime_t millisec = 0); | |
3c4f71cc | 287 | |
b9da294f BP |
288 | /** |
289 | Reset time to midnight (00:00:00) without changing the date. | |
290 | */ | |
291 | wxDateTime& ResetTime(); | |
3c4f71cc | 292 | |
b9da294f BP |
293 | /** |
294 | Constructs the object from @a timet value holding the number of seconds | |
295 | since Jan 1, 1970. | |
3c4f71cc | 296 | |
b9da294f BP |
297 | @beginWxPythonOnly |
298 | This method is named "SetTimeT" in wxPython. | |
299 | @endWxPythonOnly | |
300 | */ | |
301 | wxDateTime& Set(time_t timet); | |
302 | /** | |
303 | Sets the date and time from the broken down representation in the | |
304 | standard @a tm structure. | |
3c4f71cc | 305 | |
b9da294f BP |
306 | @beginWxPythonOnly Unsupported. @endWxPythonOnly |
307 | */ | |
308 | wxDateTime& Set(const struct tm& tm); | |
309 | /** | |
310 | Sets the date from the so-called Julian Day Number. | |
3c4f71cc | 311 | |
b9da294f BP |
312 | By definition, the Julian Day Number, usually abbreviated as JDN, of a |
313 | particular instant is the fractional number of days since 12 hours | |
314 | Universal Coordinated Time (Greenwich mean noon) on January 1 of the | |
315 | year -4712 in the Julian proleptic calendar. | |
3c4f71cc | 316 | |
b9da294f BP |
317 | @beginWxPythonOnly |
318 | This method is named "SetJDN" in wxPython. | |
319 | @endWxPythonOnly | |
23324ae1 | 320 | */ |
b9da294f BP |
321 | wxDateTime& Set(double jdn); |
322 | /** | |
323 | Sets the date to be equal to Today() and the time from supplied | |
324 | parameters. | |
23324ae1 | 325 | |
b9da294f BP |
326 | @beginWxPythonOnly |
327 | This method is named "SetHMS" in wxPython. | |
328 | @endWxPythonOnly | |
329 | */ | |
330 | wxDateTime& Set(wxDateTime_t hour, wxDateTime_t minute = 0, | |
331 | wxDateTime_t second = 0, wxDateTime_t millisec = 0); | |
23324ae1 | 332 | /** |
b9da294f | 333 | Sets the date and time from the parameters. |
23324ae1 | 334 | */ |
b9da294f BP |
335 | wxDateTime& Set(wxDateTime_t day, Month month = Inv_Month, |
336 | int year = Inv_Year, wxDateTime_t hour = 0, | |
337 | wxDateTime_t minute = 0, wxDateTime_t second = 0, | |
338 | wxDateTime_t millisec = 0); | |
23324ae1 FM |
339 | |
340 | /** | |
b9da294f BP |
341 | Sets the day without changing other date components. |
342 | */ | |
343 | wxDateTime& SetDay(short unsigned int); | |
3c4f71cc | 344 | |
b9da294f BP |
345 | /** |
346 | Sets the date from the date and time in DOS format. | |
347 | */ | |
348 | wxDateTime& SetFromDOS(unsigned long ddt); | |
3c4f71cc | 349 | |
b9da294f BP |
350 | /** |
351 | Sets the hour without changing other date components. | |
23324ae1 | 352 | */ |
b9da294f | 353 | wxDateTime& SetHour(short unsigned int); |
23324ae1 | 354 | |
b9da294f BP |
355 | /** |
356 | Sets the millisecond without changing other date components. | |
357 | */ | |
358 | wxDateTime& SetMillisecond(short unsigned int); | |
23324ae1 FM |
359 | |
360 | /** | |
b9da294f BP |
361 | Sets the minute without changing other date components. |
362 | */ | |
363 | wxDateTime& SetMinute(short unsigned int); | |
3c4f71cc | 364 | |
b9da294f BP |
365 | /** |
366 | Sets the month without changing other date components. | |
367 | */ | |
368 | wxDateTime& SetMonth(Month month); | |
3c4f71cc | 369 | |
b9da294f BP |
370 | /** |
371 | Sets the second without changing other date components. | |
372 | */ | |
373 | wxDateTime& SetSecond(short unsigned int); | |
3c4f71cc | 374 | |
b9da294f BP |
375 | /** |
376 | Sets the date and time of to the current values. Same as assigning the | |
377 | result of Now() to this object. | |
378 | */ | |
379 | wxDateTime& SetToCurrent(); | |
3c4f71cc | 380 | |
b9da294f BP |
381 | /** |
382 | Sets the year without changing other date components. | |
383 | */ | |
384 | wxDateTime& SetYear(int year); | |
3c4f71cc | 385 | |
b9da294f BP |
386 | /** |
387 | Same as Set(). | |
388 | */ | |
389 | wxDateTime& operator=(time_t timet); | |
390 | /** | |
391 | Same as Set(). | |
392 | */ | |
393 | wxDateTime& operator=(const struct tm& tm); | |
3c4f71cc | 394 | |
b9da294f | 395 | //@} |
3c4f71cc | 396 | |
3c4f71cc | 397 | |
3c4f71cc | 398 | |
b9da294f BP |
399 | /** |
400 | @name Accessors | |
3c4f71cc | 401 | |
b9da294f BP |
402 | Here are the trivial accessors. Other functions, which might have to |
403 | perform some more complicated calculations to find the answer are under | |
404 | the "Date Arithmetics" section. | |
405 | */ | |
406 | //@{ | |
3c4f71cc | 407 | |
b9da294f BP |
408 | /** |
409 | Returns the date and time in DOS format. | |
410 | */ | |
411 | long unsigned int GetAsDOS() const; | |
3c4f71cc | 412 | |
b9da294f BP |
413 | /** |
414 | Returns the century of this date. | |
415 | */ | |
416 | int GetCentury(const TimeZone& tz = Local) const; | |
3c4f71cc | 417 | |
1a21919b BP |
418 | /** |
419 | Returns the object having the same date component as this one but time | |
420 | of 00:00:00. | |
421 | ||
1e24c2af | 422 | @since 2.8.2 |
1a21919b BP |
423 | |
424 | @see ResetTime() | |
425 | */ | |
426 | wxDateTime GetDateOnly() const; | |
427 | ||
b9da294f BP |
428 | /** |
429 | Returns the day in the given timezone (local one by default). | |
430 | */ | |
431 | short unsigned int GetDay(const TimeZone& tz = Local) const; | |
3c4f71cc | 432 | |
b9da294f | 433 | /** |
1a21919b | 434 | Returns the day of the year (in 1-366 range) in the given timezone |
b9da294f | 435 | (local one by default). |
23324ae1 | 436 | */ |
b9da294f | 437 | short unsigned int GetDayOfYear(const TimeZone& tz = Local) const; |
23324ae1 | 438 | |
1a21919b BP |
439 | /** |
440 | Returns the hour in the given timezone (local one by default). | |
441 | */ | |
442 | short unsigned int GetHour(const TimeZone& tz = Local) const; | |
443 | ||
b9da294f BP |
444 | /** |
445 | Returns the milliseconds in the given timezone (local one by default). | |
446 | */ | |
447 | short unsigned int GetMillisecond(const TimeZone& tz = Local) const; | |
23324ae1 FM |
448 | |
449 | /** | |
b9da294f BP |
450 | Returns the minute in the given timezone (local one by default). |
451 | */ | |
452 | short unsigned int GetMinute(const TimeZone& tz = Local) const; | |
3c4f71cc | 453 | |
b9da294f BP |
454 | /** |
455 | Returns the month in the given timezone (local one by default). | |
456 | */ | |
457 | Month GetMonth(const TimeZone& tz = Local) const; | |
3c4f71cc | 458 | |
b9da294f BP |
459 | /** |
460 | Returns the seconds in the given timezone (local one by default). | |
461 | */ | |
462 | short unsigned int GetSecond(const TimeZone& tz = Local) const; | |
3c4f71cc | 463 | |
b9da294f | 464 | /** |
1a21919b BP |
465 | Returns the number of seconds since Jan 1, 1970. An assert failure will |
466 | occur if the date is not in the range covered by @c time_t type. | |
b9da294f BP |
467 | */ |
468 | time_t GetTicks() const; | |
3c4f71cc | 469 | |
b9da294f | 470 | /** |
1a21919b | 471 | Returns broken down representation of the date and time. |
b9da294f | 472 | */ |
1a21919b | 473 | Tm GetTm(const TimeZone& tz = Local) const; |
3c4f71cc | 474 | |
b9da294f | 475 | /** |
1a21919b | 476 | Returns the week day in the given timezone (local one by default). |
b9da294f | 477 | */ |
1a21919b | 478 | WeekDay GetWeekDay(const TimeZone& tz = Local) const; |
3c4f71cc | 479 | |
b9da294f | 480 | /** |
1a21919b BP |
481 | Returns the ordinal number of the week in the month (in 1-5 range). |
482 | ||
483 | As GetWeekOfYear(), this function supports both conventions for the | |
484 | week start. See the description of these @c WeekFlags in the | |
485 | @ref datetime_constants section. | |
b9da294f BP |
486 | */ |
487 | wxDateTime_t GetWeekOfMonth(WeekFlags flags = Monday_First, | |
488 | const TimeZone& tz = Local) const; | |
3c4f71cc | 489 | |
b9da294f | 490 | /** |
1a21919b BP |
491 | Returns the number of the week of the year this date is in. The first |
492 | week of the year is, according to international standards, the one | |
493 | containing Jan 4 or, equivalently, the first week which has Thursday in | |
494 | this year. Both of these definitions are the same as saying that the | |
495 | first week of the year must contain more than half of its days in this | |
496 | year. Accordingly, the week number will always be in 1-53 range (52 for | |
497 | non-leap years). | |
498 | ||
499 | The function depends on the @ref datetime_constants "week start" | |
500 | convention specified by the @a flags argument but its results for | |
b9da294f BP |
501 | @c Sunday_First are not well-defined as the ISO definition quoted above |
502 | applies to the weeks starting on Monday only. | |
503 | */ | |
504 | wxDateTime_t GetWeekOfYear(WeekFlags flags = Monday_First, | |
505 | const TimeZone& tz = Local) const; | |
3c4f71cc | 506 | |
b9da294f BP |
507 | /** |
508 | Returns the year in the given timezone (local one by default). | |
509 | */ | |
510 | int GetYear(const TimeZone& tz = Local) const; | |
3c4f71cc | 511 | |
b9da294f | 512 | /** |
1a21919b BP |
513 | Returns @true if the given date is later than the date of adoption of |
514 | the Gregorian calendar in the given country (and hence the Gregorian | |
515 | calendar calculations make sense for it). | |
b9da294f BP |
516 | */ |
517 | bool IsGregorianDate(GregorianAdoption country = Gr_Standard) const; | |
3c4f71cc | 518 | |
b9da294f BP |
519 | /** |
520 | Returns @true if the object represents a valid time moment. | |
521 | */ | |
522 | bool IsValid() const; | |
3c4f71cc | 523 | |
b9da294f BP |
524 | /** |
525 | Returns @true is this day is not a holiday in the given country. | |
526 | */ | |
527 | bool IsWorkDay(Country country = Country_Default) const; | |
3c4f71cc | 528 | |
b9da294f | 529 | //@} |
3c4f71cc | 530 | |
3c4f71cc | 531 | |
3c4f71cc | 532 | |
b9da294f BP |
533 | /** |
534 | @name Date Comparison | |
3c4f71cc | 535 | |
b9da294f BP |
536 | There are several functions to allow date comparison. To supplement |
537 | them, a few global operators, etc taking wxDateTime are defined. | |
538 | */ | |
539 | //@{ | |
3c4f71cc | 540 | |
b9da294f BP |
541 | /** |
542 | Returns @true if this date precedes the given one. | |
543 | */ | |
544 | bool IsEarlierThan(const wxDateTime& datetime) const; | |
3c4f71cc | 545 | |
b9da294f BP |
546 | /** |
547 | Returns @true if the two dates are strictly identical. | |
548 | */ | |
549 | bool IsEqualTo(const wxDateTime& datetime) const; | |
3c4f71cc | 550 | |
b9da294f BP |
551 | /** |
552 | Returns @true if the date is equal to another one up to the given time | |
1a21919b BP |
553 | interval, i.e. if the absolute difference between the two dates is less |
554 | than this interval. | |
b9da294f BP |
555 | */ |
556 | bool IsEqualUpTo(const wxDateTime& dt, const wxTimeSpan& ts) const; | |
3c4f71cc | 557 | |
b9da294f BP |
558 | /** |
559 | Returns @true if this date is later than the given one. | |
560 | */ | |
561 | bool IsLaterThan(const wxDateTime& datetime) const; | |
3c4f71cc | 562 | |
b9da294f BP |
563 | /** |
564 | Returns @true if the date is the same without comparing the time parts. | |
23324ae1 | 565 | */ |
b9da294f | 566 | bool IsSameDate(const wxDateTime& dt) const; |
23324ae1 | 567 | |
b9da294f BP |
568 | /** |
569 | Returns @true if the time is the same (although dates may differ). | |
570 | */ | |
571 | bool IsSameTime(const wxDateTime& dt) const; | |
23324ae1 FM |
572 | |
573 | /** | |
1a21919b | 574 | Returns @true if this date lies strictly between the two given dates. |
b9da294f BP |
575 | |
576 | @see IsBetween() | |
23324ae1 | 577 | */ |
b9da294f BP |
578 | bool IsStrictlyBetween(const wxDateTime& t1, |
579 | const wxDateTime& t2) const; | |
23324ae1 FM |
580 | |
581 | /** | |
1a21919b BP |
582 | Returns @true if IsStrictlyBetween() is @true or if the date is equal |
583 | to one of the limit values. | |
3c4f71cc | 584 | |
b9da294f BP |
585 | @see IsStrictlyBetween() |
586 | */ | |
587 | bool IsBetween(const wxDateTime& t1, const wxDateTime& t2) const; | |
3c4f71cc | 588 | |
b9da294f | 589 | //@} |
3c4f71cc | 590 | |
3c4f71cc | 591 | |
3c4f71cc | 592 | |
b9da294f BP |
593 | /** |
594 | @name Date Arithmetics | |
3c4f71cc | 595 | |
b9da294f BP |
596 | These functions carry out |
597 | @ref overview_datetime_arithmetics "arithmetics" on the wxDateTime | |
598 | objects. As explained in the overview, either wxTimeSpan or wxDateSpan | |
599 | may be added to wxDateTime, hence all functions are overloaded to | |
600 | accept both arguments. | |
3c4f71cc | 601 | |
b9da294f BP |
602 | Also, both Add() and Subtract() have both const and non-const version. |
603 | The first one returns a new object which represents the sum/difference | |
604 | of the original one with the argument while the second form modifies | |
605 | the object to which it is applied. The operators "-=" and "+=" are | |
606 | defined to be equivalent to the second forms of these functions. | |
23324ae1 | 607 | */ |
b9da294f | 608 | //@{ |
23324ae1 | 609 | |
b9da294f BP |
610 | /** |
611 | Adds the given date span to this object. | |
1a21919b BP |
612 | |
613 | @beginWxPythonOnly | |
614 | This method is named "AddDS" in wxPython. | |
615 | @endWxPythonOnly | |
616 | */ | |
617 | wxDateTime Add(const wxDateSpan& diff) const; | |
618 | /** | |
619 | Adds the given date span to this object. | |
620 | ||
621 | @beginWxPythonOnly | |
622 | This method is named "AddDS" in wxPython. | |
623 | @endWxPythonOnly | |
b9da294f BP |
624 | */ |
625 | wxDateTime Add(const wxDateSpan& diff); | |
1a21919b BP |
626 | /** |
627 | Adds the given time span to this object. | |
23324ae1 | 628 | |
1a21919b BP |
629 | @beginWxPythonOnly |
630 | This method is named "AddTS" in wxPython. | |
631 | @endWxPythonOnly | |
632 | */ | |
633 | wxDateTime Add(const wxTimeSpan& diff) const; | |
23324ae1 | 634 | /** |
1a21919b BP |
635 | Adds the given time span to this object. |
636 | ||
637 | @beginWxPythonOnly | |
638 | This method is named "AddTS" in wxPython. | |
639 | @endWxPythonOnly | |
b9da294f | 640 | */ |
1a21919b | 641 | wxDateTime& Add(const wxTimeSpan& diff); |
3c4f71cc | 642 | |
b9da294f | 643 | /** |
1a21919b BP |
644 | Subtracts the given time span from this object. |
645 | ||
646 | @beginWxPythonOnly | |
647 | This method is named "SubtractTS" in wxPython. | |
648 | @endWxPythonOnly | |
b9da294f | 649 | */ |
1a21919b BP |
650 | wxDateTime Subtract(const wxTimeSpan& diff) const; |
651 | /** | |
652 | Subtracts the given time span from this object. | |
3c4f71cc | 653 | |
1a21919b BP |
654 | @beginWxPythonOnly |
655 | This method is named "SubtractTS" in wxPython. | |
656 | @endWxPythonOnly | |
657 | */ | |
658 | wxDateTime& Subtract(const wxTimeSpan& diff); | |
659 | /** | |
660 | Subtracts the given date span from this object. | |
661 | ||
662 | @beginWxPythonOnly | |
663 | This method is named "SubtractDS" in wxPython. | |
664 | @endWxPythonOnly | |
665 | */ | |
666 | wxDateTime Subtract(const wxDateSpan& diff) const; | |
667 | /** | |
668 | Subtracts the given date span from this object. | |
669 | ||
670 | @beginWxPythonOnly | |
671 | This method is named "SubtractDS" in wxPython. | |
672 | @endWxPythonOnly | |
673 | */ | |
674 | wxDateTime& Subtract(const wxDateSpan& diff); | |
b9da294f | 675 | /** |
1a21919b BP |
676 | Subtracts another date from this one and returns the difference between |
677 | them as a wxTimeSpan. | |
b9da294f BP |
678 | */ |
679 | wxTimeSpan Subtract(const wxDateTime& dt) const; | |
3c4f71cc | 680 | |
1a21919b BP |
681 | /** |
682 | Adds the given date span to this object. | |
683 | */ | |
684 | wxDateTime operator+=(const wxDateSpan& diff); | |
685 | /** | |
686 | Subtracts the given date span from this object. | |
687 | */ | |
688 | wxDateTime& operator-=(const wxDateSpan& diff); | |
689 | /** | |
690 | Adds the given time span to this object. | |
691 | */ | |
692 | wxDateTime& operator+=(const wxTimeSpan& diff); | |
693 | /** | |
694 | Subtracts the given time span from this object. | |
695 | */ | |
696 | wxDateTime& operator-=(const wxTimeSpan& diff); | |
697 | ||
b9da294f | 698 | //@} |
3c4f71cc | 699 | |
3c4f71cc | 700 | |
3c4f71cc | 701 | |
b9da294f BP |
702 | /** |
703 | @name Date Formatting and Parsing | |
3c4f71cc | 704 | |
b9da294f | 705 | See @ref datetime_formatting |
23324ae1 | 706 | */ |
b9da294f | 707 | //@{ |
23324ae1 FM |
708 | |
709 | /** | |
1a21919b BP |
710 | This function does the same as the standard ANSI C @c strftime(3) |
711 | function. Please see its description for the meaning of @a format | |
712 | parameter. | |
713 | ||
714 | It also accepts a few wxWidgets-specific extensions: you can optionally | |
715 | specify the width of the field to follow using @c printf(3)-like syntax | |
716 | and the format specification @c "%l" can be used to get the number of | |
717 | milliseconds. | |
3c4f71cc | 718 | |
4cc4bfaf | 719 | @see ParseFormat() |
23324ae1 | 720 | */ |
4cc4bfaf | 721 | wxString Format(const wxChar* format = wxDefaultDateTimeFormat, |
328f5751 | 722 | const TimeZone& tz = Local) const; |
23324ae1 FM |
723 | |
724 | /** | |
1a21919b BP |
725 | Identical to calling Format() with @c "%x" argument (which means |
726 | "preferred date representation for the current locale"). | |
23324ae1 | 727 | */ |
328f5751 | 728 | wxString FormatDate() const; |
23324ae1 FM |
729 | |
730 | /** | |
731 | Returns the combined date-time representation in the ISO 8601 format | |
1a21919b BP |
732 | @c "YYYY-MM-DDTHH:MM:SS". The @a sep parameter default value produces |
733 | the result exactly corresponding to the ISO standard, but it can also | |
734 | be useful to use a space as seprator if a more human-readable combined | |
735 | date-time representation is needed. | |
3c4f71cc | 736 | |
1a21919b | 737 | @see FormatISODate(), FormatISOTime(), ParseISOCombined() |
23324ae1 | 738 | */ |
328f5751 | 739 | wxString FormatISOCombined(char sep = 'T') const; |
23324ae1 FM |
740 | |
741 | /** | |
742 | This function returns the date representation in the ISO 8601 format | |
1a21919b | 743 | @c "YYYY-MM-DD". |
23324ae1 | 744 | */ |
328f5751 | 745 | wxString FormatISODate() const; |
23324ae1 FM |
746 | |
747 | /** | |
748 | This function returns the time representation in the ISO 8601 format | |
1a21919b | 749 | @c "HH:MM:SS". |
23324ae1 | 750 | */ |
328f5751 | 751 | wxString FormatISOTime() const; |
23324ae1 FM |
752 | |
753 | /** | |
1a21919b BP |
754 | Identical to calling Format() with @c "%X" argument (which means |
755 | "preferred time representation for the current locale"). | |
23324ae1 | 756 | */ |
328f5751 | 757 | wxString FormatTime() const; |
23324ae1 FM |
758 | |
759 | /** | |
1a21919b BP |
760 | This function is like ParseDateTime(), but it only allows the date to |
761 | be specified. It is thus less flexible then ParseDateTime(), but also | |
762 | has less chances to misinterpret the user input. | |
763 | ||
764 | @returns @NULL if the conversion failed, otherwise return the pointer | |
765 | to the character which stopped the scan. | |
23324ae1 | 766 | */ |
b9da294f BP |
767 | const char* ParseDate(const wxString& date, |
768 | wxString::const_iterator* end = NULL); | |
23324ae1 | 769 | /** |
1a21919b BP |
770 | This function is like ParseDateTime(), but it only allows the date to |
771 | be specified. It is thus less flexible then ParseDateTime(), but also | |
772 | has less chances to misinterpret the user input. | |
23324ae1 | 773 | |
1a21919b BP |
774 | @returns @NULL if the conversion failed, otherwise return the pointer |
775 | to the character which stopped the scan. | |
23324ae1 | 776 | */ |
b9da294f | 777 | const char* ParseDate(const char* date); |
23324ae1 | 778 | /** |
1a21919b BP |
779 | This function is like ParseDateTime(), but it only allows the date to |
780 | be specified. It is thus less flexible then ParseDateTime(), but also | |
781 | has less chances to misinterpret the user input. | |
23324ae1 | 782 | |
1a21919b BP |
783 | @returns @NULL if the conversion failed, otherwise return the pointer |
784 | to the character which stopped the scan. | |
23324ae1 | 785 | */ |
4cc4bfaf | 786 | const wchar_t* ParseDate(const wchar_t* date); |
23324ae1 | 787 | |
23324ae1 | 788 | /** |
1a21919b BP |
789 | Parses the string @a datetime containing the date and time in free |
790 | format. This function tries as hard as it can to interpret the given | |
791 | string as date and time. Unlike ParseRfc822Date(), it will accept | |
792 | anything that may be accepted and will only reject strings which can | |
793 | not be parsed in any way at all. | |
794 | ||
795 | @returns @NULL if the conversion failed, otherwise return the pointer | |
796 | to the character which stopped the scan. | |
23324ae1 | 797 | */ |
4cc4bfaf FM |
798 | const char* ParseDateTime(const wxString& datetime, |
799 | wxString::const_iterator* end = NULL); | |
b9da294f | 800 | /** |
1a21919b BP |
801 | Parses the string @a datetime containing the date and time in free |
802 | format. This function tries as hard as it can to interpret the given | |
803 | string as date and time. Unlike ParseRfc822Date(), it will accept | |
804 | anything that may be accepted and will only reject strings which can | |
805 | not be parsed in any way at all. | |
b9da294f | 806 | |
1a21919b BP |
807 | @returns @NULL if the conversion failed, otherwise return the pointer |
808 | to the character which stopped the scan. | |
b9da294f | 809 | */ |
4cc4bfaf | 810 | const char* ParseDateTime(const char* datetime); |
b9da294f | 811 | /** |
1a21919b BP |
812 | Parses the string @a datetime containing the date and time in free |
813 | format. This function tries as hard as it can to interpret the given | |
814 | string as date and time. Unlike ParseRfc822Date(), it will accept | |
815 | anything that may be accepted and will only reject strings which can | |
816 | not be parsed in any way at all. | |
b9da294f | 817 | |
1a21919b BP |
818 | @returns @NULL if the conversion failed, otherwise return the pointer |
819 | to the character which stopped the scan. | |
b9da294f | 820 | */ |
4cc4bfaf | 821 | const wchar_t* ParseDateTime(const wchar_t* datetime); |
23324ae1 | 822 | |
23324ae1 | 823 | /** |
4cc4bfaf | 824 | This function parses the string @a date according to the given |
1a21919b BP |
825 | @e format. The system @c strptime(3) function is used whenever |
826 | available, but even if it is not, this function is still implemented, | |
827 | although support for locale-dependent format specifiers such as | |
828 | @c "%c", @c "%x" or @c "%X" may not be perfect and GNU extensions such | |
829 | as @c "%z" and @c "%Z" are not implemented. This function does handle | |
830 | the month and weekday names in the current locale on all platforms, | |
831 | however. | |
832 | ||
833 | Please see the description of the ANSI C function @c strftime(3) for | |
834 | the syntax of the format string. | |
835 | ||
836 | The @a dateDef parameter is used to fill in the fields which could not | |
837 | be determined from the format string. For example, if the format is | |
838 | @c "%d" (the day of the month), the month and the year are taken from | |
839 | @a dateDef. If it is not specified, Today() is used as the default | |
840 | date. | |
841 | ||
842 | @returns @NULL if the conversion failed, otherwise return the pointer | |
843 | to the character which stopped the scan. | |
23324ae1 | 844 | */ |
4cc4bfaf | 845 | const char* ParseFormat(const wxString& date, |
b9da294f BP |
846 | const wxString& format = wxDefaultDateTimeFormat, |
847 | const wxDateTime& dateDef = wxDefaultDateTime, | |
848 | wxString::const_iterator* end = NULL); | |
849 | /** | |
1a21919b BP |
850 | This function parses the string @a date according to the given |
851 | @e format. The system @c strptime(3) function is used whenever | |
852 | available, but even if it is not, this function is still implemented, | |
853 | although support for locale-dependent format specifiers such as | |
854 | @c "%c", @c "%x" or @c "%X" may not be perfect and GNU extensions such | |
855 | as @c "%z" and @c "%Z" are not implemented. This function does handle | |
856 | the month and weekday names in the current locale on all platforms, | |
857 | however. | |
858 | ||
859 | Please see the description of the ANSI C function @c strftime(3) for | |
860 | the syntax of the format string. | |
861 | ||
862 | The @a dateDef parameter is used to fill in the fields which could not | |
863 | be determined from the format string. For example, if the format is | |
864 | @c "%d" (the day of the month), the month and the year are taken from | |
865 | @a dateDef. If it is not specified, Today() is used as the default | |
866 | date. | |
b9da294f | 867 | |
1a21919b BP |
868 | @returns @NULL if the conversion failed, otherwise return the pointer |
869 | to the character which stopped the scan. | |
b9da294f | 870 | */ |
4cc4bfaf | 871 | const char* ParseFormat(const char* date, |
b9da294f BP |
872 | const wxString& format = wxDefaultDateTimeFormat, |
873 | const wxDateTime& dateDef = wxDefaultDateTime); | |
874 | /** | |
1a21919b BP |
875 | This function parses the string @a date according to the given |
876 | @e format. The system @c strptime(3) function is used whenever | |
877 | available, but even if it is not, this function is still implemented, | |
878 | although support for locale-dependent format specifiers such as | |
879 | @c "%c", @c "%x" or @c "%X" may not be perfect and GNU extensions such | |
880 | as @c "%z" and @c "%Z" are not implemented. This function does handle | |
881 | the month and weekday names in the current locale on all platforms, | |
882 | however. | |
883 | ||
884 | Please see the description of the ANSI C function @c strftime(3) for | |
885 | the syntax of the format string. | |
886 | ||
887 | The @a dateDef parameter is used to fill in the fields which could not | |
888 | be determined from the format string. For example, if the format is | |
889 | @c "%d" (the day of the month), the month and the year are taken from | |
890 | @a dateDef. If it is not specified, Today() is used as the default | |
891 | date. | |
b9da294f | 892 | |
1a21919b BP |
893 | @returns @NULL if the conversion failed, otherwise return the pointer |
894 | to the character which stopped the scan. | |
b9da294f | 895 | */ |
4cc4bfaf | 896 | const wchar_t* ParseFormat(const wchar_t* date, |
b9da294f BP |
897 | const wxString& format = wxDefaultDateTimeFormat, |
898 | const wxDateTime& dateDef = wxDefaultDateTime); | |
23324ae1 FM |
899 | |
900 | /** | |
1a21919b BP |
901 | This function parses the string containing the date and time in ISO |
902 | 8601 combined format @c "YYYY-MM-DDTHH:MM:SS". The separator between | |
903 | the date and time parts must be equal to @a sep for the function to | |
904 | succeed. | |
905 | ||
906 | @returns @true if the entire string was parsed successfully, @false | |
907 | otherwise. | |
23324ae1 FM |
908 | */ |
909 | bool ParseISOCombined(const wxString& date, char sep = 'T'); | |
910 | ||
911 | /** | |
1a21919b BP |
912 | This function parses the date in ISO 8601 format @c "YYYY-MM-DD". |
913 | ||
914 | @returns @true if the entire string was parsed successfully, @false | |
915 | otherwise. | |
23324ae1 FM |
916 | */ |
917 | bool ParseISODate(const wxString& date); | |
918 | ||
919 | /** | |
1a21919b BP |
920 | This function parses the time in ISO 8601 format @c "HH:MM:SS". |
921 | ||
922 | @returns @true if the entire string was parsed successfully, @false | |
923 | otherwise. | |
23324ae1 FM |
924 | */ |
925 | bool ParseISOTime(const wxString& date); | |
926 | ||
23324ae1 | 927 | /** |
1a21919b BP |
928 | Parses the string @a date looking for a date formatted according to the |
929 | RFC 822 in it. The exact description of this format may, of course, be | |
930 | found in the RFC (section 5), but, briefly, this is the format used in | |
931 | the headers of Internet email messages and one of the most common | |
932 | strings expressing date in this format may be something like | |
933 | @c "Sat, 18 Dec 1999 00:48:30 +0100". | |
934 | ||
23324ae1 | 935 | Returns @NULL if the conversion failed, otherwise return the pointer to |
1a21919b BP |
936 | the character immediately following the part of the string which could |
937 | be parsed. If the entire string contains only the date in RFC 822 | |
938 | format, the returned pointer will be pointing to a @c NUL character. | |
939 | ||
940 | This function is intentionally strict, it will return an error for any | |
941 | string which is not RFC 822 compliant. If you need to parse date | |
942 | formatted in more free ways, you should use ParseDateTime() or | |
23324ae1 FM |
943 | ParseDate() instead. |
944 | */ | |
4cc4bfaf | 945 | const char* ParseRfc822Date(const wxString& date, |
1a21919b | 946 | wxString::const_iterator* end = NULL); |
b9da294f | 947 | /** |
1a21919b BP |
948 | Parses the string @a date looking for a date formatted according to the |
949 | RFC 822 in it. The exact description of this format may, of course, be | |
950 | found in the RFC (section 5), but, briefly, this is the format used in | |
951 | the headers of Internet email messages and one of the most common | |
952 | strings expressing date in this format may be something like | |
953 | @c "Sat, 18 Dec 1999 00:48:30 +0100". | |
954 | ||
955 | Returns @NULL if the conversion failed, otherwise return the pointer to | |
956 | the character immediately following the part of the string which could | |
957 | be parsed. If the entire string contains only the date in RFC 822 | |
958 | format, the returned pointer will be pointing to a @c NUL character. | |
959 | ||
960 | This function is intentionally strict, it will return an error for any | |
961 | string which is not RFC 822 compliant. If you need to parse date | |
962 | formatted in more free ways, you should use ParseDateTime() or | |
963 | ParseDate() instead. | |
b9da294f | 964 | */ |
4cc4bfaf | 965 | const char* ParseRfc822Date(const char* date); |
b9da294f | 966 | /** |
1a21919b BP |
967 | Parses the string @a date looking for a date formatted according to the |
968 | RFC 822 in it. The exact description of this format may, of course, be | |
969 | found in the RFC (section 5), but, briefly, this is the format used in | |
970 | the headers of Internet email messages and one of the most common | |
971 | strings expressing date in this format may be something like | |
972 | @c "Sat, 18 Dec 1999 00:48:30 +0100". | |
973 | ||
974 | Returns @NULL if the conversion failed, otherwise return the pointer to | |
975 | the character immediately following the part of the string which could | |
976 | be parsed. If the entire string contains only the date in RFC 822 | |
977 | format, the returned pointer will be pointing to a @c NUL character. | |
978 | ||
979 | This function is intentionally strict, it will return an error for any | |
980 | string which is not RFC 822 compliant. If you need to parse date | |
981 | formatted in more free ways, you should use ParseDateTime() or | |
982 | ParseDate() instead. | |
b9da294f | 983 | */ |
4cc4bfaf | 984 | const wchar_t* ParseRfc822Date(const wchar_t* date); |
23324ae1 | 985 | |
23324ae1 | 986 | /** |
1a21919b BP |
987 | This functions is like ParseDateTime(), but only allows the time to be |
988 | specified in the input string. | |
989 | ||
990 | @returns @NULL if the conversion failed, otherwise return the pointer | |
991 | to the character which stopped the scan. | |
23324ae1 | 992 | */ |
4cc4bfaf | 993 | const char* ParseTime(const wxString& time, |
b9da294f | 994 | wxString::const_iterator* end = NULL); |
23324ae1 | 995 | /** |
1a21919b BP |
996 | This functions is like ParseDateTime(), but only allows the time to be |
997 | specified in the input string. | |
3c4f71cc | 998 | |
1a21919b BP |
999 | @returns @NULL if the conversion failed, otherwise return the pointer |
1000 | to the character which stopped the scan. | |
23324ae1 | 1001 | */ |
b9da294f | 1002 | const char* ParseTime(const char* time); |
23324ae1 | 1003 | /** |
1a21919b BP |
1004 | This functions is like ParseDateTime(), but only allows the time to be |
1005 | specified in the input string. | |
23324ae1 | 1006 | |
1a21919b BP |
1007 | @returns @NULL if the conversion failed, otherwise return the pointer |
1008 | to the character which stopped the scan. | |
23324ae1 | 1009 | */ |
b9da294f BP |
1010 | const wchar_t* ParseTime(const wchar_t* time); |
1011 | ||
1012 | //@} | |
23324ae1 | 1013 | |
3c4f71cc | 1014 | |
23324ae1 FM |
1015 | |
1016 | /** | |
b9da294f | 1017 | @name Calendar Calculations |
23324ae1 | 1018 | |
b9da294f BP |
1019 | The functions in this section perform the basic calendar calculations, |
1020 | mostly related to the week days. They allow to find the given week day | |
1021 | in the week with given number (either in the month or in the year) and | |
1022 | so on. | |
23324ae1 | 1023 | |
b9da294f BP |
1024 | None of the functions in this section modify the time part of the |
1025 | wxDateTime, they only work with the date part of it. | |
23324ae1 | 1026 | */ |
b9da294f | 1027 | //@{ |
23324ae1 FM |
1028 | |
1029 | /** | |
1a21919b BP |
1030 | Returns the copy of this object to which SetToLastMonthDay() was |
1031 | applied. | |
23324ae1 | 1032 | */ |
b9da294f BP |
1033 | wxDateTime GetLastMonthDay(Month month = Inv_Month, |
1034 | int year = Inv_Year) const; | |
23324ae1 FM |
1035 | |
1036 | /** | |
b9da294f BP |
1037 | Returns the copy of this object to which SetToLastWeekDay() was |
1038 | applied. | |
23324ae1 | 1039 | */ |
1a21919b | 1040 | wxDateTime GetLastWeekDay(WeekDay weekday, Month month = Inv_Month, |
b9da294f | 1041 | int year = Inv_Year); |
23324ae1 FM |
1042 | |
1043 | /** | |
b9da294f BP |
1044 | Returns the copy of this object to which SetToNextWeekDay() was |
1045 | applied. | |
23324ae1 | 1046 | */ |
b9da294f | 1047 | wxDateTime GetNextWeekDay(WeekDay weekday) const; |
23324ae1 FM |
1048 | |
1049 | /** | |
b9da294f BP |
1050 | Returns the copy of this object to which SetToPrevWeekDay() was |
1051 | applied. | |
23324ae1 | 1052 | */ |
b9da294f | 1053 | wxDateTime GetPrevWeekDay(WeekDay weekday) const; |
23324ae1 | 1054 | |
1a21919b BP |
1055 | /** |
1056 | Returns the copy of this object to which SetToWeekDay() was applied. | |
1057 | */ | |
1058 | wxDateTime GetWeekDay(WeekDay weekday, int n = 1, Month month = Inv_Month, | |
1059 | int year = Inv_Year) const; | |
1060 | ||
23324ae1 | 1061 | /** |
b9da294f BP |
1062 | Returns the copy of this object to which SetToWeekDayInSameWeek() was |
1063 | applied. | |
23324ae1 | 1064 | */ |
b9da294f BP |
1065 | wxDateTime GetWeekDayInSameWeek(WeekDay weekday, |
1066 | WeekFlags flags = Monday_First) const; | |
23324ae1 | 1067 | |
1a21919b BP |
1068 | /** |
1069 | Returns the copy of this object to which SetToYearDay() was applied. | |
1070 | */ | |
1071 | wxDateTime GetYearDay(wxDateTime_t yday) const; | |
1072 | ||
23324ae1 | 1073 | /** |
b9da294f BP |
1074 | Sets the date to the last day in the specified month (the current one |
1075 | by default). | |
1076 | ||
1077 | @returns The reference to the modified object itself. | |
23324ae1 FM |
1078 | */ |
1079 | wxDateTime SetToLastMonthDay(Month month = Inv_Month, | |
1080 | int year = Inv_Year); | |
1081 | ||
1082 | /** | |
1083 | The effect of calling this function is the same as of calling | |
1a21919b BP |
1084 | @c SetToWeekDay(-1, weekday, month, year). The date will be set to the |
1085 | last @a weekday in the given month and year (the current ones by | |
1086 | default). Always returns @true. | |
23324ae1 FM |
1087 | */ |
1088 | bool SetToLastWeekDay(WeekDay weekday, Month month = Inv_Month, | |
1089 | int year = Inv_Year); | |
1090 | ||
1091 | /** | |
1a21919b BP |
1092 | Sets the date so that it will be the first @a weekday following the |
1093 | current date. | |
b9da294f BP |
1094 | |
1095 | @returns The reference to the modified object itself. | |
23324ae1 | 1096 | */ |
1d497b99 | 1097 | wxDateTime& SetToNextWeekDay(WeekDay weekday); |
23324ae1 FM |
1098 | |
1099 | /** | |
4cc4bfaf | 1100 | Sets the date so that it will be the last @a weekday before the current |
23324ae1 | 1101 | date. |
b9da294f BP |
1102 | |
1103 | @returns The reference to the modified object itself. | |
23324ae1 | 1104 | */ |
1d497b99 | 1105 | wxDateTime& SetToPrevWeekDay(WeekDay weekday); |
23324ae1 FM |
1106 | |
1107 | /** | |
4cc4bfaf | 1108 | Sets the date to the @e n-th @a weekday in the given month of the given |
1a21919b BP |
1109 | year (the current month and year are used by default). The parameter |
1110 | @a n may be either positive (counting from the beginning of the month) | |
1111 | or negative (counting from the end of it). | |
b9da294f BP |
1112 | |
1113 | For example, SetToWeekDay(2, wxDateTime::Wed) will set the date to the | |
23324ae1 | 1114 | second Wednesday in the current month and |
b9da294f BP |
1115 | SetToWeekDay(-1, wxDateTime::Sun) will set the date to the last Sunday |
1116 | in the current month. | |
1117 | ||
1118 | @returns @true if the date was modified successfully, @false otherwise | |
1119 | meaning that the specified date doesn't exist. | |
23324ae1 FM |
1120 | */ |
1121 | bool SetToWeekDay(WeekDay weekday, int n = 1, | |
b9da294f | 1122 | Month month = Inv_Month, int year = Inv_Year); |
23324ae1 FM |
1123 | |
1124 | /** | |
b9da294f BP |
1125 | Adjusts the date so that it will still lie in the same week as before, |
1126 | but its week day will be the given one. | |
1127 | ||
1128 | @returns The reference to the modified object itself. | |
23324ae1 FM |
1129 | */ |
1130 | wxDateTime SetToWeekDayInSameWeek(WeekDay weekday, | |
1131 | WeekFlags flags = Monday_First); | |
1132 | ||
23324ae1 | 1133 | /** |
1a21919b BP |
1134 | Sets the date to the day number @a yday in the same year (i.e., unlike |
1135 | the other functions, this one does not use the current year). The day | |
1136 | number should be in the range 1-366 for the leap years and 1-365 for | |
23324ae1 | 1137 | the other ones. |
1a21919b BP |
1138 | |
1139 | @returns The reference to the modified object itself. | |
23324ae1 | 1140 | */ |
1a21919b | 1141 | wxDateTime& SetToYearDay(wxDateTime_t yday); |
23324ae1 | 1142 | |
b9da294f BP |
1143 | //@} |
1144 | ||
1145 | ||
1146 | ||
23324ae1 | 1147 | /** |
b9da294f BP |
1148 | @name Astronomical/Historical Functions |
1149 | ||
1150 | Some degree of support for the date units used in astronomy and/or | |
1151 | history is provided. You can construct a wxDateTime object from a | |
1152 | JDN and you may also get its JDN, MJD or Rata Die number from it. | |
1153 | ||
1a21919b | 1154 | Related functions in other groups: wxDateTime(double), Set(double) |
23324ae1 | 1155 | */ |
b9da294f BP |
1156 | //@{ |
1157 | ||
1158 | /** | |
1159 | Synonym for GetJulianDayNumber(). | |
1160 | */ | |
1161 | double GetJDN() const; | |
1162 | ||
1163 | /** | |
1a21919b | 1164 | Returns the JDN corresponding to this date. Beware of rounding errors! |
b9da294f BP |
1165 | |
1166 | @see GetModifiedJulianDayNumber() | |
1167 | */ | |
1168 | double GetJulianDayNumber() const; | |
1169 | ||
1170 | /** | |
1171 | Synonym for GetModifiedJulianDayNumber(). | |
1172 | */ | |
1173 | double GetMJD() const; | |
1174 | ||
1175 | /** | |
1a21919b BP |
1176 | Returns the @e "Modified Julian Day Number" (MJD) which is, by |
1177 | definition, is equal to JDN - 2400000.5. The MJDs are simpler to work | |
1178 | with as the integral MJDs correspond to midnights of the dates in the | |
1179 | Gregorian calendar and not the noons like JDN. The MJD 0 represents | |
1180 | Nov 17, 1858. | |
b9da294f BP |
1181 | */ |
1182 | double GetModifiedJulianDayNumber() const; | |
1183 | ||
1184 | /** | |
1185 | Return the @e Rata Die number of this date. | |
1a21919b BP |
1186 | |
1187 | By definition, the Rata Die number is a date specified as the number of | |
1188 | days relative to a base date of December 31 of the year 0. Thus January | |
1189 | 1 of the year 1 is Rata Die day 1. | |
b9da294f BP |
1190 | */ |
1191 | double GetRataDie() const; | |
1192 | ||
1193 | //@} | |
1194 | ||
1195 | ||
1196 | ||
1197 | /** | |
1198 | @name Time Zone and DST Support | |
1199 | ||
1200 | Please see the @ref overview_datetime_timezones "time zone overview" | |
1201 | for more information about time zones. Normally, these functions should | |
1202 | be rarely used. | |
1203 | ||
1a21919b | 1204 | Related functions in other groups: GetBeginDST(), GetEndDST() |
b9da294f BP |
1205 | */ |
1206 | //@{ | |
1207 | ||
1208 | /** | |
1209 | Transform the date from the given time zone to the local one. If | |
1210 | @a noDST is @true, no DST adjustments will be made. | |
1211 | ||
1212 | @returns The date in the local time zone. | |
1213 | */ | |
1214 | wxDateTime FromTimezone(const TimeZone& tz, bool noDST = false) const; | |
1215 | ||
1216 | /** | |
1217 | Returns @true if the DST is applied for this date in the given country. | |
1a21919b BP |
1218 | |
1219 | @see GetBeginDST(), GetEndDST() | |
b9da294f BP |
1220 | */ |
1221 | int IsDST(Country country = Country_Default) const; | |
1222 | ||
1223 | /** | |
1224 | Same as FromTimezone() but modifies the object in place. | |
1225 | */ | |
1226 | wxDateTime MakeFromTimezone(const TimeZone& tz, bool noDST = false); | |
1227 | ||
1228 | /** | |
1229 | Modifies the object in place to represent the date in another time | |
1230 | zone. If @a noDST is @true, no DST adjustments will be made. | |
1231 | */ | |
1232 | wxDateTime MakeTimezone(const TimeZone& tz, bool noDST = false); | |
1233 | ||
1234 | /** | |
1235 | This is the same as calling MakeTimezone() with the argument @c GMT0. | |
1236 | */ | |
1237 | wxDateTime& MakeUTC(bool noDST = false); | |
23324ae1 FM |
1238 | |
1239 | /** | |
b9da294f BP |
1240 | Transform the date to the given time zone. If @a noDST is @true, no DST |
1241 | adjustments will be made. | |
3c4f71cc | 1242 | |
b9da294f BP |
1243 | @returns The date in the new time zone. |
1244 | */ | |
1245 | wxDateTime ToTimezone(const TimeZone& tz, bool noDST = false) const; | |
1246 | ||
1247 | /** | |
1248 | This is the same as calling ToTimezone() with the argument @c GMT0. | |
1249 | */ | |
1250 | wxDateTime ToUTC(bool noDST = false) const; | |
3c4f71cc | 1251 | |
b9da294f | 1252 | //@} |
3c4f71cc | 1253 | |
3c4f71cc | 1254 | |
3c4f71cc | 1255 | |
3c4f71cc | 1256 | |
3c4f71cc | 1257 | |
b9da294f BP |
1258 | /** |
1259 | Converts the year in absolute notation (i.e. a number which can be | |
1260 | negative, positive or zero) to the year in BC/AD notation. For the | |
1261 | positive years, nothing is done, but the year 0 is year 1 BC and so for | |
1262 | other years there is a difference of 1. | |
3c4f71cc | 1263 | |
b9da294f | 1264 | This function should be used like this: |
3c4f71cc | 1265 | |
b9da294f BP |
1266 | @code |
1267 | wxDateTime dt(...); | |
1268 | int y = dt.GetYear(); | |
1269 | printf("The year is %d%s", wxDateTime::ConvertYearToBC(y), y > 0 ? "AD" : "BC"); | |
1270 | @endcode | |
1271 | */ | |
1272 | static int ConvertYearToBC(int year); | |
3c4f71cc | 1273 | |
b9da294f BP |
1274 | /** |
1275 | Returns the translations of the strings @c AM and @c PM used for time | |
1276 | formatting for the current locale. Either of the pointers may be @NULL | |
1277 | if the corresponding value is not needed. | |
1278 | */ | |
1279 | static void GetAmPmStrings(wxString* am, wxString* pm); | |
3c4f71cc | 1280 | |
b9da294f BP |
1281 | /** |
1282 | Get the beginning of DST for the given country in the given year | |
1283 | (current one by default). This function suffers from limitations | |
1284 | described in the @ref overview_datetime_dst "DST overview". | |
3c4f71cc | 1285 | |
b9da294f BP |
1286 | @see GetEndDST() |
1287 | */ | |
1288 | static wxDateTime GetBeginDST(int year = Inv_Year, | |
1289 | Country country = Country_Default); | |
3c4f71cc | 1290 | |
b9da294f BP |
1291 | /** |
1292 | Returns the end of DST for the given country in the given year (current | |
1293 | one by default). | |
3c4f71cc | 1294 | |
b9da294f BP |
1295 | @see GetBeginDST() |
1296 | */ | |
1297 | static wxDateTime GetEndDST(int year = Inv_Year, | |
1298 | Country country = Country_Default); | |
3c4f71cc | 1299 | |
b9da294f BP |
1300 | /** |
1301 | Get the current century, i.e. first two digits of the year, in given | |
1302 | calendar (only Gregorian is currently supported). | |
1303 | */ | |
1304 | static int GetCentury(int year); | |
3c4f71cc | 1305 | |
b9da294f BP |
1306 | /** |
1307 | Returns the current default country. The default country is used for | |
1308 | DST calculations, for example. | |
3c4f71cc | 1309 | |
b9da294f BP |
1310 | @see SetCountry() |
1311 | */ | |
1312 | static Country GetCountry(); | |
3c4f71cc | 1313 | |
b9da294f BP |
1314 | /** |
1315 | Get the current month in given calendar (only Gregorian is currently | |
1316 | supported). | |
1317 | */ | |
1318 | static Month GetCurrentMonth(Calendar cal = Gregorian); | |
3c4f71cc | 1319 | |
b9da294f BP |
1320 | /** |
1321 | Get the current year in given calendar (only Gregorian is currently | |
1322 | supported). | |
23324ae1 | 1323 | */ |
b9da294f BP |
1324 | static int GetCurrentYear(Calendar cal = Gregorian); |
1325 | ||
1326 | /** | |
1327 | Gets the full (default) or abbreviated (specify @c Name_Abbr name of | |
1328 | the given month. | |
23324ae1 | 1329 | |
b9da294f BP |
1330 | @see GetWeekDayName() |
1331 | */ | |
1332 | static wxString GetMonthName(Month month, NameFlags flags = Name_Full); | |
23324ae1 FM |
1333 | |
1334 | /** | |
b9da294f BP |
1335 | Returns the number of days in the given year. The only supported value |
1336 | for @a cal currently is @c Gregorian. | |
1337 | ||
1338 | @beginWxPythonOnly | |
1339 | This method is named "GetNumberOfDaysInYear" in wxPython. | |
1340 | @endWxPythonOnly | |
23324ae1 | 1341 | */ |
b9da294f | 1342 | static wxDateTime_t GetNumberOfDays(int year, Calendar cal = Gregorian); |
23324ae1 FM |
1343 | |
1344 | /** | |
b9da294f BP |
1345 | Returns the number of days in the given month of the given year. The |
1346 | only supported value for @a cal currently is @c Gregorian. | |
1347 | ||
1348 | @beginWxPythonOnly | |
1349 | This method is named "GetNumberOfDaysInMonth" in wxPython. | |
1350 | @endWxPythonOnly | |
1351 | */ | |
1a21919b | 1352 | static wxDateTime_t GetNumberOfDays(Month month, int year = Inv_Year, |
b9da294f | 1353 | Calendar cal = Gregorian); |
3c4f71cc | 1354 | |
b9da294f BP |
1355 | /** |
1356 | Returns the current time. | |
1357 | */ | |
1358 | static time_t GetTimeNow(); | |
3c4f71cc | 1359 | |
b9da294f BP |
1360 | /** |
1361 | Returns the current time broken down using the buffer whose adress is | |
1362 | passed to the function with @a tm to store the result. | |
1363 | */ | |
1364 | static struct tm* GetTmNow(struct tm *tm); | |
3c4f71cc | 1365 | |
b9da294f BP |
1366 | /** |
1367 | Returns the current time broken down. Note that this function returns a | |
1368 | pointer to a static buffer that's reused by calls to this function and | |
1369 | certain C library functions (e.g. localtime). If there is any chance | |
1370 | your code might be used in a multi-threaded application, you really | |
1371 | should use GetTmNow(struct tm *) instead. | |
1372 | */ | |
1373 | static struct tm* GetTmNow(); | |
3c4f71cc | 1374 | |
b9da294f BP |
1375 | /** |
1376 | Gets the full (default) or abbreviated (specify @c Name_Abbr) name of | |
1377 | the given week day. | |
3c4f71cc | 1378 | |
b9da294f BP |
1379 | @see GetMonthName() |
1380 | */ | |
1381 | static wxString GetWeekDayName(WeekDay weekday, | |
1382 | NameFlags flags = Name_Full); | |
3c4f71cc | 1383 | |
b9da294f BP |
1384 | /** |
1385 | Returns @true if DST was used n the given year (the current one by | |
1386 | default) in the given country. | |
1387 | */ | |
1388 | static bool IsDSTApplicable(int year = Inv_Year, | |
1389 | Country country = Country_Default); | |
3c4f71cc | 1390 | |
b9da294f BP |
1391 | /** |
1392 | Returns @true if the @a year is a leap one in the specified calendar. | |
1393 | This functions supports Gregorian and Julian calendars. | |
1394 | */ | |
1a21919b | 1395 | static bool IsLeapYear(int year = Inv_Year, Calendar cal = Gregorian); |
3c4f71cc | 1396 | |
b9da294f BP |
1397 | /** |
1398 | This function returns @true if the specified (or default) country is | |
1399 | one of Western European ones. It is used internally by wxDateTime to | |
1400 | determine the DST convention and date and time formatting rules. | |
23324ae1 | 1401 | */ |
b9da294f BP |
1402 | static bool IsWestEuropeanCountry(Country country = Country_Default); |
1403 | ||
1404 | /** | |
1405 | Returns the object corresponding to the current time. | |
1406 | ||
1407 | Example: | |
23324ae1 | 1408 | |
b9da294f BP |
1409 | @code |
1410 | wxDateTime now = wxDateTime::Now(); | |
1411 | printf("Current time in Paris:\t%s\n", now.Format("%c", wxDateTime::CET).c_str()); | |
1412 | @endcode | |
1413 | ||
1414 | @note This function is accurate up to seconds. UNow() should be used | |
1415 | for better precision, but it is less efficient and might not be | |
1416 | available on all platforms. | |
1417 | ||
1418 | @see Today() | |
1419 | */ | |
1420 | static wxDateTime Now(); | |
23324ae1 FM |
1421 | |
1422 | /** | |
b9da294f BP |
1423 | Sets the country to use by default. This setting influences the DST |
1424 | calculations, date formatting and other things. | |
1425 | ||
1426 | The possible values for @a country parameter are enumerated in the | |
1427 | @ref datetime_constants section. | |
1428 | ||
1429 | @see GetCountry() | |
23324ae1 | 1430 | */ |
b9da294f | 1431 | static void SetCountry(Country country); |
23324ae1 FM |
1432 | |
1433 | /** | |
1a21919b BP |
1434 | Set the date to the given @a weekday in the week number @a numWeek of |
1435 | the given @a year . The number should be in range 1-53. | |
1436 | ||
1437 | Note that the returned date may be in a different year than the one | |
1438 | passed to this function because both the week 1 and week 52 or 53 (for | |
1439 | leap years) contain days from different years. See GetWeekOfYear() for | |
1440 | the explanation of how the year weeks are counted. | |
23324ae1 | 1441 | */ |
b9da294f BP |
1442 | static wxDateTime SetToWeekOfYear(int year, wxDateTime_t numWeek, |
1443 | WeekDay weekday = Mon); | |
23324ae1 FM |
1444 | |
1445 | /** | |
b9da294f BP |
1446 | Returns the object corresponding to the midnight of the current day |
1447 | (i.e. the same as Now(), but the time part is set to 0). | |
3c4f71cc | 1448 | |
4cc4bfaf | 1449 | @see Now() |
23324ae1 FM |
1450 | */ |
1451 | static wxDateTime Today(); | |
1452 | ||
1453 | /** | |
1454 | Returns the object corresponding to the current time including the | |
b9da294f BP |
1455 | milliseconds if a function to get time with such precision is available |
1456 | on the current platform (supported under most Unices and Win32). | |
3c4f71cc | 1457 | |
4cc4bfaf | 1458 | @see Now() |
23324ae1 | 1459 | */ |
4cc4bfaf | 1460 | static wxDateTime UNow(); |
4cc4bfaf | 1461 | }; |
23324ae1 | 1462 | |
65874118 FM |
1463 | /** |
1464 | Global instance of an empty wxDateTime object. | |
1465 | ||
1a21919b BP |
1466 | @todo Would it be better to rename this wxNullDateTime so it's consistent |
1467 | with the rest of the "empty/invalid/null" global objects? | |
65874118 | 1468 | */ |
1a21919b | 1469 | const wxDateTime wxDefaultDateTime; |
65874118 | 1470 | |
23324ae1 | 1471 | |
e54c96f1 | 1472 | |
23324ae1 FM |
1473 | /** |
1474 | @class wxDateTimeWorkDays | |
1475 | @wxheader{datetime.h} | |
7c913512 | 1476 | |
1a21919b | 1477 | @todo Write wxDateTimeWorkDays documentation. |
7c913512 | 1478 | |
23324ae1 | 1479 | @library{wxbase} |
1a21919b | 1480 | @category{data} |
23324ae1 | 1481 | */ |
7c913512 | 1482 | class wxDateTimeWorkDays |
23324ae1 FM |
1483 | { |
1484 | public: | |
7c913512 | 1485 | |
23324ae1 FM |
1486 | }; |
1487 | ||
1488 | ||
e54c96f1 | 1489 | |
23324ae1 FM |
1490 | /** |
1491 | @class wxDateSpan | |
1492 | @wxheader{datetime.h} | |
7c913512 | 1493 | |
23324ae1 FM |
1494 | This class is a "logical time span" and is useful for implementing program |
1495 | logic for such things as "add one month to the date" which, in general, | |
1496 | doesn't mean to add 60*60*24*31 seconds to it, but to take the same date | |
1497 | the next month (to understand that this is indeed different consider adding | |
1498 | one month to Feb, 15 -- we want to get Mar, 15, of course). | |
7c913512 | 1499 | |
23324ae1 FM |
1500 | When adding a month to the date, all lesser components (days, hours, ...) |
1501 | won't be changed unless the resulting date would be invalid: for example, | |
1502 | Jan 31 + 1 month will be Feb 28, not (non-existing) Feb 31. | |
7c913512 | 1503 | |
23324ae1 | 1504 | Because of this feature, adding and subtracting back again the same |
1a21919b | 1505 | wxDateSpan will @b not, in general, give back the original date: Feb 28 - 1 |
23324ae1 | 1506 | month will be Jan 28, not Jan 31! |
7c913512 | 1507 | |
23324ae1 FM |
1508 | wxDateSpan objects can be either positive or negative. They may be |
1509 | multiplied by scalars which multiply all deltas by the scalar: i.e. | |
1a21919b BP |
1510 | 2*(1 month and 1 day) is 2 months and 2 days. They can be added together |
1511 | with wxDateTime or wxTimeSpan, but the type of result is different for each | |
23324ae1 | 1512 | case. |
7c913512 | 1513 | |
1a21919b BP |
1514 | @warning If you specify both weeks and days, the total number of days added |
1515 | will be 7*weeks + days! See also GetTotalDays(). | |
7c913512 | 1516 | |
1a21919b BP |
1517 | Equality operators are defined for wxDateSpans. Two wxDateSpans are equal |
1518 | if and only if they both give the same target date when added to @b every | |
1519 | source date. Thus wxDateSpan::Months(1) is not equal to | |
1520 | wxDateSpan::Days(30), because they don't give the same date when added to | |
1521 | Feb 1st. But wxDateSpan::Days(14) is equal to wxDateSpan::Weeks(2). | |
7c913512 | 1522 | |
1a21919b BP |
1523 | Finally, notice that for adding hours, minutes and so on you don't need |
1524 | this class at all: wxTimeSpan will do the job because there are no | |
1525 | subtleties associated with those (we don't support leap seconds). | |
7c913512 | 1526 | |
23324ae1 FM |
1527 | @library{wxbase} |
1528 | @category{data} | |
7c913512 | 1529 | |
b9da294f | 1530 | @see @ref overview_datetime, wxDateTime |
23324ae1 | 1531 | */ |
7c913512 | 1532 | class wxDateSpan |
23324ae1 FM |
1533 | { |
1534 | public: | |
1535 | /** | |
1a21919b BP |
1536 | Constructs the date span object for the given number of years, months, |
1537 | weeks and days. Note that the weeks and days add together if both are | |
1538 | given. | |
23324ae1 | 1539 | */ |
1a21919b | 1540 | wxDateSpan(int years = 0, int months = 0, int weeks = 0, int days = 0); |
23324ae1 | 1541 | |
23324ae1 | 1542 | /** |
1a21919b BP |
1543 | Returns the sum of two date spans. |
1544 | ||
1545 | @returns A new wxDateSpan object with the result. | |
23324ae1 | 1546 | */ |
1a21919b BP |
1547 | wxDateSpan Add(const wxDateSpan& other) const; |
1548 | /** | |
1549 | Adds the given wxDateSpan to this wxDateSpan and returns a reference | |
1550 | to itself. | |
1551 | */ | |
1552 | wxDateSpan& Add(const wxDateSpan& other); | |
23324ae1 FM |
1553 | |
1554 | /** | |
1555 | Returns a date span object corresponding to one day. | |
3c4f71cc | 1556 | |
4cc4bfaf | 1557 | @see Days() |
23324ae1 | 1558 | */ |
4cc4bfaf | 1559 | static wxDateSpan Day(); |
23324ae1 FM |
1560 | |
1561 | /** | |
1562 | Returns a date span object corresponding to the given number of days. | |
3c4f71cc | 1563 | |
4cc4bfaf | 1564 | @see Day() |
23324ae1 FM |
1565 | */ |
1566 | static wxDateSpan Days(int days); | |
1567 | ||
1568 | /** | |
1a21919b BP |
1569 | Returns the number of days (not counting the weeks component) in this |
1570 | date span. | |
3c4f71cc | 1571 | |
4cc4bfaf | 1572 | @see GetTotalDays() |
23324ae1 | 1573 | */ |
328f5751 | 1574 | int GetDays() const; |
23324ae1 FM |
1575 | |
1576 | /** | |
1a21919b BP |
1577 | Returns the number of the months (not counting the years) in this date |
1578 | span. | |
23324ae1 | 1579 | */ |
328f5751 | 1580 | int GetMonths() const; |
23324ae1 FM |
1581 | |
1582 | /** | |
1a21919b BP |
1583 | Returns the combined number of days in this date span, counting both |
1584 | weeks and days. This doesn't take months or years into account. | |
3c4f71cc | 1585 | |
4cc4bfaf | 1586 | @see GetWeeks(), GetDays() |
23324ae1 | 1587 | */ |
328f5751 | 1588 | int GetTotalDays() const; |
23324ae1 FM |
1589 | |
1590 | /** | |
1591 | Returns the number of weeks in this date span. | |
3c4f71cc | 1592 | |
4cc4bfaf | 1593 | @see GetTotalDays() |
23324ae1 | 1594 | */ |
328f5751 | 1595 | int GetWeeks() const; |
23324ae1 FM |
1596 | |
1597 | /** | |
1598 | Returns the number of years in this date span. | |
1599 | */ | |
328f5751 | 1600 | int GetYears() const; |
23324ae1 FM |
1601 | |
1602 | /** | |
1603 | Returns a date span object corresponding to one month. | |
3c4f71cc | 1604 | |
4cc4bfaf | 1605 | @see Months() |
23324ae1 FM |
1606 | */ |
1607 | static wxDateSpan Month(); | |
1608 | ||
1609 | /** | |
1610 | Returns a date span object corresponding to the given number of months. | |
3c4f71cc | 1611 | |
4cc4bfaf | 1612 | @see Month() |
23324ae1 FM |
1613 | */ |
1614 | static wxDateSpan Months(int mon); | |
1615 | ||
23324ae1 | 1616 | /** |
1a21919b BP |
1617 | Returns the product of the date span by the specified @a factor. The |
1618 | product is computed by multiplying each of the components by the | |
1619 | @a factor. | |
1620 | ||
1621 | @returns A new wxDateSpan object with the result. | |
23324ae1 | 1622 | */ |
1a21919b BP |
1623 | wxDateSpan Multiply(int factor) const; |
1624 | /** | |
1625 | Multiplies this date span by the specified @a factor. The product is | |
1626 | computed by multiplying each of the components by the @a factor. | |
1627 | ||
1628 | @returns A reference to this wxDateSpan object modified in place. | |
1629 | */ | |
1630 | wxDateSpan& Multiply(int factor); | |
23324ae1 | 1631 | |
23324ae1 FM |
1632 | /** |
1633 | Changes the sign of this date span. | |
3c4f71cc | 1634 | |
4cc4bfaf | 1635 | @see Negate() |
23324ae1 | 1636 | */ |
1a21919b | 1637 | wxDateSpan& Neg(); |
23324ae1 FM |
1638 | |
1639 | /** | |
1a21919b | 1640 | Returns a date span with the opposite sign. |
3c4f71cc | 1641 | |
4cc4bfaf | 1642 | @see Neg() |
23324ae1 | 1643 | */ |
328f5751 | 1644 | wxDateSpan Negate() const; |
23324ae1 FM |
1645 | |
1646 | /** | |
1a21919b BP |
1647 | Sets the number of days (without modifying any other components) in |
1648 | this date span. | |
23324ae1 | 1649 | */ |
1d497b99 | 1650 | wxDateSpan& SetDays(int n); |
23324ae1 FM |
1651 | |
1652 | /** | |
1a21919b BP |
1653 | Sets the number of months (without modifying any other components) in |
1654 | this date span. | |
23324ae1 | 1655 | */ |
1d497b99 | 1656 | wxDateSpan& SetMonths(int n); |
23324ae1 FM |
1657 | |
1658 | /** | |
1a21919b BP |
1659 | Sets the number of weeks (without modifying any other components) in |
1660 | this date span. | |
23324ae1 | 1661 | */ |
1d497b99 | 1662 | wxDateSpan& SetWeeks(int n); |
23324ae1 FM |
1663 | |
1664 | /** | |
1a21919b BP |
1665 | Sets the number of years (without modifying any other components) in |
1666 | this date span. | |
23324ae1 | 1667 | */ |
1d497b99 | 1668 | wxDateSpan& SetYears(int n); |
23324ae1 | 1669 | |
23324ae1 | 1670 | /** |
1a21919b BP |
1671 | Returns the difference of two date spans. |
1672 | ||
1673 | @returns A new wxDateSpan object with the result. | |
1674 | */ | |
1675 | wxDateSpan Subtract(const wxDateSpan& other) const; | |
1676 | /** | |
1677 | Subtracts the given wxDateSpan to this wxDateSpan and returns a | |
1678 | reference to itself. | |
23324ae1 | 1679 | */ |
1a21919b | 1680 | wxDateSpan& Subtract(const wxDateSpan& other); |
23324ae1 FM |
1681 | |
1682 | /** | |
1683 | Returns a date span object corresponding to one week. | |
3c4f71cc | 1684 | |
4cc4bfaf | 1685 | @see Weeks() |
23324ae1 FM |
1686 | */ |
1687 | static wxDateSpan Week(); | |
1688 | ||
1689 | /** | |
1690 | Returns a date span object corresponding to the given number of weeks. | |
3c4f71cc | 1691 | |
4cc4bfaf | 1692 | @see Week() |
23324ae1 FM |
1693 | */ |
1694 | static wxDateSpan Weeks(int weeks); | |
1695 | ||
1696 | /** | |
1697 | Returns a date span object corresponding to one year. | |
3c4f71cc | 1698 | |
4cc4bfaf | 1699 | @see Years() |
23324ae1 FM |
1700 | */ |
1701 | static wxDateSpan Year(); | |
1702 | ||
1703 | /** | |
1704 | Returns a date span object corresponding to the given number of years. | |
3c4f71cc | 1705 | |
4cc4bfaf | 1706 | @see Year() |
23324ae1 FM |
1707 | */ |
1708 | static wxDateSpan Years(int years); | |
1709 | ||
1a21919b BP |
1710 | /** |
1711 | Adds the given wxDateSpan to this wxDateSpan and returns the result. | |
1712 | */ | |
1713 | wxDateSpan& operator+=(const wxDateSpan& other); | |
1714 | ||
1715 | /** | |
1716 | Subtracts the given wxDateSpan to this wxDateSpan and returns the | |
1717 | result. | |
1718 | */ | |
1719 | wxDateSpan& operator-=(const wxDateSpan& other); | |
1720 | ||
1721 | /** | |
1722 | Changes the sign of this date span. | |
1723 | ||
1724 | @see Negate() | |
1725 | */ | |
1726 | wxDateSpan& operator-(); | |
1727 | ||
1728 | /** | |
1729 | Multiplies this date span by the specified @a factor. The product is | |
1730 | computed by multiplying each of the components by the @a factor. | |
1731 | ||
1732 | @returns A reference to this wxDateSpan object modified in place. | |
1733 | */ | |
1734 | wxDateSpan& operator*=(int factor); | |
1735 | ||
23324ae1 FM |
1736 | /** |
1737 | Returns @true if this date span is different from the other one. | |
1738 | */ | |
1d497b99 | 1739 | bool operator!=(const wxDateSpan&) const; |
23324ae1 FM |
1740 | |
1741 | /** | |
1a21919b BP |
1742 | Returns @true if this date span is equal to the other one. Two date |
1743 | spans are considered equal if and only if they have the same number of | |
1744 | years and months and the same total number of days (counting both days | |
1745 | and weeks). | |
23324ae1 | 1746 | */ |
1d497b99 | 1747 | bool operator==(const wxDateSpan&) const; |
23324ae1 FM |
1748 | }; |
1749 | ||
1750 | ||
e54c96f1 | 1751 | |
23324ae1 FM |
1752 | /** |
1753 | @class wxTimeSpan | |
1754 | @wxheader{datetime.h} | |
7c913512 | 1755 | |
23324ae1 | 1756 | wxTimeSpan class represents a time interval. |
7c913512 | 1757 | |
23324ae1 FM |
1758 | @library{wxbase} |
1759 | @category{data} | |
7c913512 | 1760 | |
b9da294f | 1761 | @see @ref overview_datetime, wxDateTime |
23324ae1 | 1762 | */ |
7c913512 | 1763 | class wxTimeSpan |
23324ae1 FM |
1764 | { |
1765 | public: | |
23324ae1 | 1766 | /** |
1a21919b | 1767 | Default constructor, constructs a zero timespan. |
23324ae1 FM |
1768 | */ |
1769 | wxTimeSpan(); | |
1a21919b BP |
1770 | /** |
1771 | Constructs timespan from separate values for each component, with the | |
1772 | date set to 0. Hours are not restricted to 0-24 range, neither are | |
1773 | minutes, seconds or milliseconds. | |
1774 | */ | |
7c913512 | 1775 | wxTimeSpan(long hours, long min, long sec, long msec); |
23324ae1 FM |
1776 | |
1777 | /** | |
1a21919b | 1778 | Returns the absolute value of the timespan: does not modify the object. |
23324ae1 | 1779 | */ |
328f5751 | 1780 | wxTimeSpan Abs() const; |
23324ae1 FM |
1781 | |
1782 | /** | |
1a21919b | 1783 | Returns the sum of two time spans. |
3c4f71cc | 1784 | |
1a21919b | 1785 | @returns A new wxDateSpan object with the result. |
23324ae1 | 1786 | */ |
1a21919b | 1787 | wxTimeSpan Add(const wxTimeSpan& diff) const; |
23324ae1 | 1788 | /** |
1a21919b BP |
1789 | Adds the given wxTimeSpan to this wxTimeSpan and returns a reference |
1790 | to itself. | |
23324ae1 | 1791 | */ |
1a21919b | 1792 | wxTimeSpan& Add(const wxTimeSpan& diff); |
23324ae1 FM |
1793 | |
1794 | /** | |
1795 | Returns the timespan for one day. | |
1796 | */ | |
4cc4bfaf | 1797 | static wxTimespan Day(); |
23324ae1 FM |
1798 | |
1799 | /** | |
1800 | Returns the timespan for the given number of days. | |
1801 | */ | |
1802 | static wxTimespan Days(long days); | |
1803 | ||
1804 | /** | |
1a21919b BP |
1805 | Returns the string containing the formatted representation of the time |
1806 | span. The following format specifiers are allowed after %: | |
3c4f71cc | 1807 | |
1a21919b BP |
1808 | - @c H - Number of Hours |
1809 | - @c M - Number of Minutes | |
1810 | - @c S - Number of Seconds | |
1811 | - @c l - Number of Milliseconds | |
1812 | - @c D - Number of Days | |
1813 | - @c E - Number of Weeks | |
1814 | - @c % - The percent character | |
3c4f71cc | 1815 | |
1a21919b BP |
1816 | Note that, for example, the number of hours in the description above is |
1817 | not well defined: it can be either the total number of hours (for | |
1818 | example, for a time span of 50 hours this would be 50) or just the hour | |
1819 | part of the time span, which would be 2 in this case as 50 hours is | |
1820 | equal to 2 days and 2 hours. | |
3c4f71cc | 1821 | |
1a21919b BP |
1822 | wxTimeSpan resolves this ambiguity in the following way: if there had |
1823 | been, indeed, the @c %D format specified preceding the @c %H, then it | |
1824 | is interpreted as 2. Otherwise, it is 50. | |
3c4f71cc | 1825 | |
1a21919b BP |
1826 | The same applies to all other format specifiers: if they follow a |
1827 | specifier of larger unit, only the rest part is taken, otherwise the | |
1828 | full value is used. | |
23324ae1 | 1829 | */ |
1d497b99 | 1830 | wxString Format(const wxString& = wxDefaultTimeSpanFormat) const; |
23324ae1 | 1831 | |
23324ae1 FM |
1832 | /** |
1833 | Returns the difference in number of days. | |
1834 | */ | |
328f5751 | 1835 | int GetDays() const; |
23324ae1 FM |
1836 | |
1837 | /** | |
1838 | Returns the difference in number of hours. | |
1839 | */ | |
328f5751 | 1840 | int GetHours() const; |
23324ae1 FM |
1841 | |
1842 | /** | |
1843 | Returns the difference in number of milliseconds. | |
1844 | */ | |
328f5751 | 1845 | wxLongLong GetMilliseconds() const; |
23324ae1 FM |
1846 | |
1847 | /** | |
1848 | Returns the difference in number of minutes. | |
1849 | */ | |
328f5751 | 1850 | int GetMinutes() const; |
23324ae1 FM |
1851 | |
1852 | /** | |
1853 | Returns the difference in number of seconds. | |
1854 | */ | |
328f5751 | 1855 | wxLongLong GetSeconds() const; |
23324ae1 FM |
1856 | |
1857 | /** | |
1858 | Returns the internal representation of timespan. | |
1859 | */ | |
328f5751 | 1860 | wxLongLong GetValue() const; |
23324ae1 FM |
1861 | |
1862 | /** | |
1863 | Returns the difference in number of weeks. | |
1864 | */ | |
328f5751 | 1865 | int GetWeeks() const; |
23324ae1 FM |
1866 | |
1867 | /** | |
1868 | Returns the timespan for one hour. | |
1869 | */ | |
1870 | static wxTimespan Hour(); | |
1871 | ||
1872 | /** | |
1873 | Returns the timespan for the given number of hours. | |
1874 | */ | |
1875 | static wxTimespan Hours(long hours); | |
1876 | ||
1877 | /** | |
1878 | Returns @true if two timespans are equal. | |
1879 | */ | |
328f5751 | 1880 | bool IsEqualTo(const wxTimeSpan& ts) const; |
23324ae1 FM |
1881 | |
1882 | /** | |
1a21919b BP |
1883 | Compares two timespans: works with the absolute values, i.e. -2 hours |
1884 | is longer than 1 hour. Also, it will return @false if the timespans are | |
1885 | equal in absolute value. | |
23324ae1 | 1886 | */ |
328f5751 | 1887 | bool IsLongerThan(const wxTimeSpan& ts) const; |
23324ae1 FM |
1888 | |
1889 | /** | |
1890 | Returns @true if the timespan is negative. | |
1891 | */ | |
328f5751 | 1892 | bool IsNegative() const; |
23324ae1 FM |
1893 | |
1894 | /** | |
1895 | Returns @true if the timespan is empty. | |
1896 | */ | |
328f5751 | 1897 | bool IsNull() const; |
23324ae1 FM |
1898 | |
1899 | /** | |
1900 | Returns @true if the timespan is positive. | |
1901 | */ | |
328f5751 | 1902 | bool IsPositive() const; |
23324ae1 FM |
1903 | |
1904 | /** | |
1a21919b BP |
1905 | Compares two timespans: works with the absolute values, i.e. 1 hour is |
1906 | shorter than -2 hours. Also, it will return @false if the timespans are | |
1907 | equal in absolute value. | |
23324ae1 | 1908 | */ |
328f5751 | 1909 | bool IsShorterThan(const wxTimeSpan& ts) const; |
23324ae1 FM |
1910 | |
1911 | /** | |
1912 | Returns the timespan for one millisecond. | |
1913 | */ | |
1914 | static wxTimespan Millisecond(); | |
1915 | ||
1916 | /** | |
1917 | Returns the timespan for the given number of milliseconds. | |
1918 | */ | |
1919 | static wxTimespan Milliseconds(long ms); | |
1920 | ||
1921 | /** | |
1922 | Returns the timespan for one minute. | |
1923 | */ | |
1924 | static wxTimespan Minute(); | |
1925 | ||
1926 | /** | |
1927 | Returns the timespan for the given number of minutes. | |
1928 | */ | |
1929 | static wxTimespan Minutes(long min); | |
1930 | ||
23324ae1 | 1931 | /** |
1a21919b | 1932 | Returns the product of this time span by @a n. |
23324ae1 | 1933 | |
1a21919b | 1934 | @returns A new wxTimeSpan object with the result. |
23324ae1 | 1935 | */ |
1a21919b | 1936 | wxTimeSpan Multiply(int n) const; |
23324ae1 | 1937 | /** |
1a21919b BP |
1938 | Multiplies this time span by @a n. |
1939 | ||
1940 | @returns A reference to this wxTimeSpan object modified in place. | |
23324ae1 | 1941 | */ |
1a21919b | 1942 | wxTimeSpan& Multiply(int n); |
23324ae1 FM |
1943 | |
1944 | /** | |
1a21919b | 1945 | Negate the value of the timespan. |
3c4f71cc | 1946 | |
1a21919b BP |
1947 | @see Negate() |
1948 | */ | |
1949 | wxTimeSpan& Neg(); | |
3c4f71cc | 1950 | |
1a21919b BP |
1951 | /** |
1952 | Returns timespan with inverted sign. | |
3c4f71cc | 1953 | |
1a21919b | 1954 | @see Neg() |
23324ae1 | 1955 | */ |
1a21919b | 1956 | wxTimeSpan Negate() const; |
23324ae1 FM |
1957 | |
1958 | /** | |
1959 | Returns the timespan for one second. | |
1960 | */ | |
1961 | static wxTimespan Second(); | |
1962 | ||
1963 | /** | |
1964 | Returns the timespan for the given number of seconds. | |
1965 | */ | |
1966 | static wxTimespan Seconds(long sec); | |
1967 | ||
1968 | /** | |
1a21919b | 1969 | Returns the difference of two time spans. |
3c4f71cc | 1970 | |
1a21919b | 1971 | @returns A new wxDateSpan object with the result. |
23324ae1 | 1972 | */ |
1a21919b | 1973 | wxTimeSpan Subtract(const wxTimeSpan& diff) const; |
23324ae1 | 1974 | /** |
1a21919b BP |
1975 | Subtracts the given wxTimeSpan to this wxTimeSpan and returns a |
1976 | reference to itself. | |
23324ae1 | 1977 | */ |
1a21919b | 1978 | wxTimeSpan& Subtract(const wxTimeSpan& diff); |
23324ae1 FM |
1979 | |
1980 | /** | |
1a21919b BP |
1981 | Returns the timespan for one week. |
1982 | */ | |
1983 | static wxTimespan Week(); | |
3c4f71cc | 1984 | |
1a21919b BP |
1985 | /** |
1986 | Returns the timespan for the given number of weeks. | |
1987 | */ | |
1988 | static wxTimespan Weeks(long weeks); | |
3c4f71cc | 1989 | |
1a21919b BP |
1990 | /** |
1991 | Adds the given wxTimeSpan to this wxTimeSpan and returns the result. | |
1992 | */ | |
1993 | wxTimeSpan& operator+=(const wxTimeSpan& diff); | |
3c4f71cc | 1994 | |
1a21919b BP |
1995 | /** |
1996 | Multiplies this time span by @a n. | |
3c4f71cc | 1997 | |
1a21919b | 1998 | @returns A reference to this wxTimeSpan object modified in place. |
23324ae1 | 1999 | */ |
1a21919b | 2000 | wxTimeSpan& operator*=(int n); |
23324ae1 FM |
2001 | |
2002 | /** | |
1a21919b BP |
2003 | Negate the value of the timespan. |
2004 | ||
2005 | @see Negate() | |
23324ae1 | 2006 | */ |
1a21919b | 2007 | wxTimeSpan& operator-(); |
23324ae1 FM |
2008 | |
2009 | /** | |
1a21919b BP |
2010 | Subtracts the given wxTimeSpan to this wxTimeSpan and returns the |
2011 | result. | |
23324ae1 | 2012 | */ |
1a21919b | 2013 | wxTimeSpan& operator-=(const wxTimeSpan& diff); |
23324ae1 FM |
2014 | }; |
2015 | ||
2016 | ||
e54c96f1 | 2017 | |
23324ae1 FM |
2018 | /** |
2019 | @class wxDateTimeHolidayAuthority | |
2020 | @wxheader{datetime.h} | |
7c913512 | 2021 | |
1a21919b | 2022 | @todo Write wxDateTimeHolidayAuthority documentation. |
7c913512 | 2023 | |
23324ae1 | 2024 | @library{wxbase} |
1a21919b | 2025 | @category{misc} |
23324ae1 | 2026 | */ |
7c913512 | 2027 | class wxDateTimeHolidayAuthority |
23324ae1 FM |
2028 | { |
2029 | public: | |
7c913512 | 2030 | |
23324ae1 | 2031 | }; |
e54c96f1 | 2032 |