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