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