]> git.saurik.com Git - wxWidgets.git/blame - include/wx/datetime.h
using Run of base class
[wxWidgets.git] / include / wx / datetime.h
CommitLineData
0979c962
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/datetime.h
3// Purpose: declarations of time/date related classes (wxDateTime,
4// wxTimeSpan)
5// Author: Vadim Zeitlin
6// Modified by:
7// Created: 10.02.99
0979c962 8// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
65571936 9// Licence: wxWindows licence
0979c962
VZ
10/////////////////////////////////////////////////////////////////////////////
11
2f02cb89
VZ
12#ifndef _WX_DATETIME_H
13#define _WX_DATETIME_H
0979c962 14
2b5f62a0
VZ
15#include "wx/defs.h"
16
e421922f
VZ
17#if wxUSE_DATETIME
18
9b4da627
VZ
19#ifdef __WXWINCE__
20 #include "wx/msw/wince/time.h"
bd362275 21#else
9b4da627
VZ
22 #include <time.h>
23#endif // OS
5e967044 24
b76b015e 25#include <limits.h> // for INT_MIN
0979c962
VZ
26
27#include "wx/longlong.h"
254696bb 28#include "wx/anystr.h"
0979c962 29
b5dbe15d
VS
30class WXDLLIMPEXP_FWD_BASE wxDateTime;
31class WXDLLIMPEXP_FWD_BASE wxTimeSpan;
32class WXDLLIMPEXP_FWD_BASE wxDateSpan;
d98a58c5 33#ifdef __WINDOWS__
154014d6
VZ
34struct _SYSTEMTIME;
35#endif
0979c962 36
df5168c4 37#include "wx/dynarray.h"
2f02cb89 38
5b781a67
SC
39// not all c-runtimes are based on 1/1/1970 being (time_t) 0
40// set this to the corresponding value in seconds 1/1/1970 has on your
41// systems c-runtime
42
92f89387
SC
43#define WX_TIME_BASE_OFFSET 0
44
0979c962 45/*
f6bcfd97 46 * TODO
0979c962 47 *
299fcbfe 48 * + 1. Time zones with minutes (make TimeZone a class)
4f6aed9c 49 * ? 2. getdate() function like under Solaris
299fcbfe 50 * + 3. text conversion for wxDateSpan
4f6aed9c
VZ
51 * + 4. pluggable modules for the workdays calculations
52 * 5. wxDateTimeHolidayAuthority for Easter and other christian feasts
0979c962
VZ
53 */
54
55/*
299fcbfe 56 The three (main) classes declared in this header represent:
0979c962
VZ
57
58 1. An absolute moment in the time (wxDateTime)
59 2. A difference between two moments in the time, positive or negative
60 (wxTimeSpan)
61 3. A logical difference between two dates expressed in
62 years/months/weeks/days (wxDateSpan)
63
64 The following arithmetic operations are permitted (all others are not):
65
66 addition
67 --------
68
69 wxDateTime + wxTimeSpan = wxDateTime
70 wxDateTime + wxDateSpan = wxDateTime
71 wxTimeSpan + wxTimeSpan = wxTimeSpan
72 wxDateSpan + wxDateSpan = wxDateSpan
73
f6bcfd97 74 subtraction
0979c962
VZ
75 ------------
76 wxDateTime - wxDateTime = wxTimeSpan
cd0b1709
VZ
77 wxDateTime - wxTimeSpan = wxDateTime
78 wxDateTime - wxDateSpan = wxDateTime
0979c962
VZ
79 wxTimeSpan - wxTimeSpan = wxTimeSpan
80 wxDateSpan - wxDateSpan = wxDateSpan
81
82 multiplication
83 --------------
84 wxTimeSpan * number = wxTimeSpan
cd0b1709 85 number * wxTimeSpan = wxTimeSpan
0979c962 86 wxDateSpan * number = wxDateSpan
cd0b1709 87 number * wxDateSpan = wxDateSpan
0979c962
VZ
88
89 unitary minus
90 -------------
91 -wxTimeSpan = wxTimeSpan
92 -wxDateSpan = wxDateSpan
cd0b1709
VZ
93
94 For each binary operation OP (+, -, *) we have the following operatorOP=() as
f6bcfd97 95 a method and the method with a symbolic name OPER (Add, Subtract, Multiply)
cd0b1709
VZ
96 as a synonym for it and another const method with the same name which returns
97 the changed copy of the object and operatorOP() as a global function which is
98 implemented in terms of the const version of OPEN. For the unary - we have
99 operator-() as a method, Neg() as synonym for it and Negate() which returns
100 the copy of the object with the changed sign.
0979c962
VZ
101*/
102
2ef31e80
VZ
103// an invalid/default date time object which may be used as the default
104// argument for arguments of type wxDateTime; it is also returned by all
105// functions returning wxDateTime on failure (this is why it is also called
106// wxInvalidDateTime)
b5dbe15d 107class WXDLLIMPEXP_FWD_BASE wxDateTime;
2ef31e80 108
a243da29
PC
109extern WXDLLIMPEXP_DATA_BASE(const char) wxDefaultDateTimeFormat[];
110extern WXDLLIMPEXP_DATA_BASE(const char) wxDefaultTimeSpanFormat[];
bddd7a8d 111extern WXDLLIMPEXP_DATA_BASE(const wxDateTime) wxDefaultDateTime;
1aaf88d2 112
2ef31e80
VZ
113#define wxInvalidDateTime wxDefaultDateTime
114
48fd6e9d
FM
115
116// ----------------------------------------------------------------------------
117// conditional compilation
118// ----------------------------------------------------------------------------
119
dd36b5a3
VZ
120// if configure detected strftime(), we have it too
121#ifdef HAVE_STRFTIME
122 #define wxHAS_STRFTIME
123// suppose everyone else has strftime except Win CE unless VC8 is used
124#elif !defined(__WXWINCE__) || defined(__VISUALC8__)
125 #define wxHAS_STRFTIME
48fd6e9d
FM
126#endif
127
0979c962 128// ----------------------------------------------------------------------------
cd0b1709 129// wxDateTime represents an absolute moment in the time
0979c962 130// ----------------------------------------------------------------------------
b76b015e 131
bddd7a8d 132class WXDLLIMPEXP_BASE wxDateTime
0979c962
VZ
133{
134public:
135 // types
136 // ------------------------------------------------------------------------
137
cd0b1709
VZ
138 // a small unsigned integer type for storing things like minutes,
139 // seconds &c. It should be at least short (i.e. not char) to contain
140 // the number of milliseconds - it may also be 'int' because there is
141 // no size penalty associated with it in our code, we don't store any
142 // data in this format
0979c962
VZ
143 typedef unsigned short wxDateTime_t;
144
f0f951fa
VZ
145 // constants
146 // ------------------------------------------------------------------------
147
0979c962 148 // the timezones
b76b015e 149 enum TZ
0979c962
VZ
150 {
151 // the time in the current time zone
152 Local,
153
4c51a665 154 // zones from GMT (= Greenwich Mean Time): they're guaranteed to be
0979c962
VZ
155 // consequent numbers, so writing something like `GMT0 + offset' is
156 // safe if abs(offset) <= 12
157
158 // underscore stands for minus
159 GMT_12, GMT_11, GMT_10, GMT_9, GMT_8, GMT_7,
160 GMT_6, GMT_5, GMT_4, GMT_3, GMT_2, GMT_1,
161 GMT0,
162 GMT1, GMT2, GMT3, GMT4, GMT5, GMT6,
34f90a1c 163 GMT7, GMT8, GMT9, GMT10, GMT11, GMT12, GMT13,
0979c962
VZ
164 // Note that GMT12 and GMT_12 are not the same: there is a difference
165 // of exactly one day between them
166
fcc3d7cb
VZ
167 // some symbolic names for TZ
168
169 // Europe
170 WET = GMT0, // Western Europe Time
171 WEST = GMT1, // Western Europe Summer Time
172 CET = GMT1, // Central Europe Time
173 CEST = GMT2, // Central Europe Summer Time
174 EET = GMT2, // Eastern Europe Time
175 EEST = GMT3, // Eastern Europe Summer Time
176 MSK = GMT3, // Moscow Time
177 MSD = GMT4, // Moscow Summer Time
178
179 // US and Canada
180 AST = GMT_4, // Atlantic Standard Time
181 ADT = GMT_3, // Atlantic Daylight Time
182 EST = GMT_5, // Eastern Standard Time
183 EDT = GMT_4, // Eastern Daylight Saving Time
184 CST = GMT_6, // Central Standard Time
185 CDT = GMT_5, // Central Daylight Saving Time
186 MST = GMT_7, // Mountain Standard Time
187 MDT = GMT_6, // Mountain Daylight Saving Time
188 PST = GMT_8, // Pacific Standard Time
189 PDT = GMT_7, // Pacific Daylight Saving Time
190 HST = GMT_10, // Hawaiian Standard Time
191 AKST = GMT_9, // Alaska Standard Time
192 AKDT = GMT_8, // Alaska Daylight Saving Time
193
194 // Australia
195
196 A_WST = GMT8, // Western Standard Time
34f90a1c 197 A_CST = GMT13 + 1, // Central Standard Time (+9.5)
fcc3d7cb
VZ
198 A_EST = GMT10, // Eastern Standard Time
199 A_ESST = GMT11, // Eastern Summer Time
200
34f90a1c
VZ
201 // New Zealand
202 NZST = GMT12, // Standard Time
203 NZDT = GMT13, // Daylight Saving Time
204
fcc3d7cb
VZ
205 // TODO add more symbolic timezone names here
206
207 // Universal Coordinated Time = the new and politically correct name
208 // for GMT
0979c962 209 UTC = GMT0
0979c962
VZ
210 };
211
212 // the calendar systems we know about: notice that it's valid (for
213 // this classes purpose anyhow) to work with any of these calendars
214 // even with the dates before the historical appearance of the
215 // calendar
216 enum Calendar
217 {
218 Gregorian, // current calendar
219 Julian // calendar in use since -45 until the 1582 (or later)
220
221 // TODO Hebrew, Chinese, Maya, ... (just kidding) (or then may be not?)
222 };
223
224 // these values only are used to identify the different dates of
225 // adoption of the Gregorian calendar (see IsGregorian())
226 //
227 // All data and comments taken verbatim from "The Calendar FAQ (v 2.0)"
e9670814 228 // by Claus Tøndering, http://www.pip.dknet.dk/~c-t/calendar.html
0979c962
VZ
229 // except for the comments "we take".
230 //
231 // Symbol "->" should be read as "was followed by" in the comments
232 // which follow.
233 enum GregorianAdoption
234 {
235 Gr_Unknown, // no data for this country or it's too uncertain to use
236 Gr_Standard, // on the day 0 of Gregorian calendar: 15 Oct 1582
237
238 Gr_Alaska, // Oct 1867 when Alaska became part of the USA
239 Gr_Albania, // Dec 1912
240
241 Gr_Austria = Gr_Unknown, // Different regions on different dates
242 Gr_Austria_Brixen, // 5 Oct 1583 -> 16 Oct 1583
243 Gr_Austria_Salzburg = Gr_Austria_Brixen,
244 Gr_Austria_Tyrol = Gr_Austria_Brixen,
245 Gr_Austria_Carinthia, // 14 Dec 1583 -> 25 Dec 1583
246 Gr_Austria_Styria = Gr_Austria_Carinthia,
247
248 Gr_Belgium, // Then part of the Netherlands
249
250 Gr_Bulgaria = Gr_Unknown, // Unknown precisely (from 1915 to 1920)
251 Gr_Bulgaria_1, // 18 Mar 1916 -> 1 Apr 1916
252 Gr_Bulgaria_2, // 31 Mar 1916 -> 14 Apr 1916
253 Gr_Bulgaria_3, // 3 Sep 1920 -> 17 Sep 1920
254
255 Gr_Canada = Gr_Unknown, // Different regions followed the changes in
256 // Great Britain or France
257
258 Gr_China = Gr_Unknown, // Different authorities say:
259 Gr_China_1, // 18 Dec 1911 -> 1 Jan 1912
260 Gr_China_2, // 18 Dec 1928 -> 1 Jan 1929
261
262 Gr_Czechoslovakia, // (Bohemia and Moravia) 6 Jan 1584 -> 17 Jan 1584
263 Gr_Denmark, // (including Norway) 18 Feb 1700 -> 1 Mar 1700
264 Gr_Egypt, // 1875
265 Gr_Estonia, // 1918
266 Gr_Finland, // Then part of Sweden
267
268 Gr_France, // 9 Dec 1582 -> 20 Dec 1582
269 Gr_France_Alsace, // 4 Feb 1682 -> 16 Feb 1682
270 Gr_France_Lorraine, // 16 Feb 1760 -> 28 Feb 1760
271 Gr_France_Strasbourg, // February 1682
272
273 Gr_Germany = Gr_Unknown, // Different states on different dates:
274 Gr_Germany_Catholic, // 1583-1585 (we take 1584)
275 Gr_Germany_Prussia, // 22 Aug 1610 -> 2 Sep 1610
276 Gr_Germany_Protestant, // 18 Feb 1700 -> 1 Mar 1700
277
278 Gr_GreatBritain, // 2 Sep 1752 -> 14 Sep 1752 (use 'cal(1)')
279
280 Gr_Greece, // 9 Mar 1924 -> 23 Mar 1924
281 Gr_Hungary, // 21 Oct 1587 -> 1 Nov 1587
282 Gr_Ireland = Gr_GreatBritain,
283 Gr_Italy = Gr_Standard,
284
285 Gr_Japan = Gr_Unknown, // Different authorities say:
286 Gr_Japan_1, // 19 Dec 1872 -> 1 Jan 1873
287 Gr_Japan_2, // 19 Dec 1892 -> 1 Jan 1893
288 Gr_Japan_3, // 18 Dec 1918 -> 1 Jan 1919
289
290 Gr_Latvia, // 1915-1918 (we take 1915)
291 Gr_Lithuania, // 1915
292 Gr_Luxemburg, // 14 Dec 1582 -> 25 Dec 1582
293 Gr_Netherlands = Gr_Belgium, // (including Belgium) 1 Jan 1583
294
295 // this is too weird to take into account: the Gregorian calendar was
296 // introduced twice in Groningen, first time 28 Feb 1583 was followed
297 // by 11 Mar 1583, then it has gone back to Julian in the summer of
298 // 1584 and then 13 Dec 1700 -> 12 Jan 1701 - which is
299 // the date we take here
300 Gr_Netherlands_Groningen, // 13 Dec 1700 -> 12 Jan 1701
301 Gr_Netherlands_Gelderland, // 30 Jun 1700 -> 12 Jul 1700
302 Gr_Netherlands_Utrecht, // (and Overijssel) 30 Nov 1700->12 Dec 1700
303 Gr_Netherlands_Friesland, // (and Drenthe) 31 Dec 1700 -> 12 Jan 1701
304
305 Gr_Norway = Gr_Denmark, // Then part of Denmark
306 Gr_Poland = Gr_Standard,
307 Gr_Portugal = Gr_Standard,
308 Gr_Romania, // 31 Mar 1919 -> 14 Apr 1919
309 Gr_Russia, // 31 Jan 1918 -> 14 Feb 1918
310 Gr_Scotland = Gr_GreatBritain,
311 Gr_Spain = Gr_Standard,
312
313 // Sweden has a curious history. Sweden decided to make a gradual
314 // change from the Julian to the Gregorian calendar. By dropping every
315 // leap year from 1700 through 1740 the eleven superfluous days would
316 // be omitted and from 1 Mar 1740 they would be in sync with the
317 // Gregorian calendar. (But in the meantime they would be in sync with
318 // nobody!)
319 //
320 // So 1700 (which should have been a leap year in the Julian calendar)
321 // was not a leap year in Sweden. However, by mistake 1704 and 1708
322 // became leap years. This left Sweden out of synchronisation with
323 // both the Julian and the Gregorian world, so they decided to go back
324 // to the Julian calendar. In order to do this, they inserted an extra
325 // day in 1712, making that year a double leap year! So in 1712,
326 // February had 30 days in Sweden.
327 //
328 // Later, in 1753, Sweden changed to the Gregorian calendar by
329 // dropping 11 days like everyone else.
330 Gr_Sweden = Gr_Finland, // 17 Feb 1753 -> 1 Mar 1753
331
332 Gr_Switzerland = Gr_Unknown,// Different cantons used different dates
333 Gr_Switzerland_Catholic, // 1583, 1584 or 1597 (we take 1584)
334 Gr_Switzerland_Protestant, // 31 Dec 1700 -> 12 Jan 1701
335
336 Gr_Turkey, // 1 Jan 1927
337 Gr_USA = Gr_GreatBritain,
338 Gr_Wales = Gr_GreatBritain,
339 Gr_Yugoslavia // 1919
340 };
341
342 // the country parameter is used so far for calculating the start and
343 // the end of DST period and for deciding whether the date is a work
344 // day or not
345 //
346 // TODO move this to intl.h
5e967044
JS
347
348// Required for WinCE
349#ifdef USA
350#undef USA
351#endif
352
0979c962
VZ
353 enum Country
354 {
355 Country_Unknown, // no special information for this country
356 Country_Default, // set the default country with SetCountry() method
239446b4 357 // or use the default country with any other
0979c962
VZ
358
359 // TODO add more countries (for this we must know about DST and/or
360 // holidays for this country)
239446b4
VZ
361
362 // Western European countries: we assume that they all follow the same
363 // DST rules (true or false?)
364 Country_WesternEurope_Start,
365 Country_EEC = Country_WesternEurope_Start,
0979c962 366 France,
239446b4
VZ
367 Germany,
368 UK,
369 Country_WesternEurope_End = UK,
370
371 Russia,
0979c962
VZ
372 USA
373 };
0979c962
VZ
374 // symbolic names for the months
375 enum Month
376 {
377 Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec, Inv_Month
378 };
379
380 // symbolic names for the weekdays
381 enum WeekDay
382 {
383 Sun, Mon, Tue, Wed, Thu, Fri, Sat, Inv_WeekDay
384 };
385
386 // invalid value for the year
387 enum Year
388 {
b76b015e
VZ
389 Inv_Year = SHRT_MIN // should hold in wxDateTime_t
390 };
391
f0f951fa
VZ
392 // flags for GetWeekDayName and GetMonthName
393 enum NameFlags
394 {
395 Name_Full = 0x01, // return full name
396 Name_Abbr = 0x02 // return abbreviated name
397 };
398
9d9b7755
VZ
399 // flags for GetWeekOfYear and GetWeekOfMonth
400 enum WeekFlags
401 {
402 Default_First, // Sunday_First for US, Monday_First for the rest
403 Monday_First, // week starts with a Monday
404 Sunday_First // week starts with a Sunday
405 };
406
b76b015e
VZ
407 // helper classes
408 // ------------------------------------------------------------------------
409
1582a1db 410 // a class representing a time zone: basically, this is just an offset
299fcbfe 411 // (in seconds) from GMT
bddd7a8d 412 class WXDLLIMPEXP_BASE TimeZone
299fcbfe
VZ
413 {
414 public:
415 TimeZone(TZ tz);
1cf57808
VZ
416
417 // create time zone object with the given offset
418 TimeZone(long offset = 0) { m_offset = offset; }
419
420 static TimeZone Make(long offset)
421 {
422 TimeZone tz;
423 tz.m_offset = offset;
424 return tz;
425 }
299fcbfe 426
cd0b1709 427 long GetOffset() const { return m_offset; }
299fcbfe
VZ
428
429 private:
430 // offset for this timezone from GMT in seconds
cd0b1709 431 long m_offset;
299fcbfe
VZ
432 };
433
b76b015e
VZ
434 // standard struct tm is limited to the years from 1900 (because
435 // tm_year field is the offset from 1900), so we use our own struct
436 // instead to represent broken down time
fcc3d7cb
VZ
437 //
438 // NB: this struct should always be kept normalized (i.e. mon should
439 // be < 12, 1 <= day <= 31 &c), so use AddMonths(), AddDays()
440 // instead of modifying the member fields directly!
bddd7a8d 441 struct WXDLLIMPEXP_BASE Tm
b76b015e 442 {
5ed8879e
VZ
443 wxDateTime_t msec, sec, min, hour,
444 mday, // Day of the month in 1..31 range.
445 yday; // Day of the year in 0..365 range.
fcc3d7cb
VZ
446 Month mon;
447 int year;
b76b015e
VZ
448
449 // default ctor inits the object to an invalid value
450 Tm();
451
299fcbfe
VZ
452 // ctor from struct tm and the timezone
453 Tm(const struct tm& tm, const TimeZone& tz);
b76b015e
VZ
454
455 // check that the given date/time is valid (in Gregorian calendar)
456 bool IsValid() const;
457
458 // get the week day
459 WeekDay GetWeekDay() // not const because wday may be changed
460 {
461 if ( wday == Inv_WeekDay )
462 ComputeWeekDay();
463
464 return (WeekDay)wday;
465 }
466
fcc3d7cb 467 // add the given number of months to the date keeping it normalized
e6ec579c 468 void AddMonths(int monDiff);
fcc3d7cb
VZ
469
470 // add the given number of months to the date keeping it normalized
e6ec579c 471 void AddDays(int dayDiff);
fcc3d7cb 472
b76b015e
VZ
473 private:
474 // compute the weekday from other fields
475 void ComputeWeekDay();
476
299fcbfe
VZ
477 // the timezone we correspond to
478 TimeZone m_tz;
479
5ed8879e
VZ
480 // This value can only be accessed via GetWeekDay() and not directly
481 // because it's not always computed when creating this object and may
482 // need to be calculated on demand.
483 wxDateTime_t wday;
b76b015e
VZ
484 };
485
0979c962
VZ
486 // static methods
487 // ------------------------------------------------------------------------
488
489 // set the current country
490 static void SetCountry(Country country);
491 // get the current country
239446b4
VZ
492 static Country GetCountry();
493
68379eaf 494 // return true if the country is a West European one (in practice,
239446b4
VZ
495 // this means that the same DST rules as for EEC apply)
496 static bool IsWestEuropeanCountry(Country country = Country_Default);
0979c962
VZ
497
498 // return the current year
499 static int GetCurrentYear(Calendar cal = Gregorian);
500
501 // convert the year as returned by wxDateTime::GetYear() to a year
502 // suitable for BC/AD notation. The difference is that BC year 1
503 // corresponds to the year 0 (while BC year 0 didn't exist) and AD
504 // year N is just year N.
505 static int ConvertYearToBC(int year);
506
507 // return the current month
508 static Month GetCurrentMonth(Calendar cal = Gregorian);
509
68379eaf 510 // returns true if the given year is a leap year in the given calendar
2f02cb89
VZ
511 static bool IsLeapYear(int year = Inv_Year, Calendar cal = Gregorian);
512
513 // get the century (19 for 1999, 20 for 2000 and -5 for 492 BC)
a333edbd 514 static int GetCentury(int year);
0979c962 515
b76b015e
VZ
516 // returns the number of days in this year (356 or 355 for Gregorian
517 // calendar usually :-)
0979c962
VZ
518 static wxDateTime_t GetNumberOfDays(int year, Calendar cal = Gregorian);
519
520 // get the number of the days in the given month (default value for
521 // the year means the current one)
522 static wxDateTime_t GetNumberOfDays(Month month,
523 int year = Inv_Year,
524 Calendar cal = Gregorian);
525
e538985e 526
b76b015e
VZ
527 // get the full (default) or abbreviated month name in the current
528 // locale, returns empty string on error
f0f951fa
VZ
529 static wxString GetMonthName(Month month,
530 NameFlags flags = Name_Full);
0979c962 531
e538985e
VZ
532 // get the standard English full (default) or abbreviated month name
533 static wxString GetEnglishMonthName(Month month,
534 NameFlags flags = Name_Full);
535
b76b015e
VZ
536 // get the full (default) or abbreviated weekday name in the current
537 // locale, returns empty string on error
f0f951fa
VZ
538 static wxString GetWeekDayName(WeekDay weekday,
539 NameFlags flags = Name_Full);
540
e538985e
VZ
541 // get the standard English full (default) or abbreviated weekday name
542 static wxString GetEnglishWeekDayName(WeekDay weekday,
543 NameFlags flags = Name_Full);
544
f0f951fa
VZ
545 // get the AM and PM strings in the current locale (may be empty)
546 static void GetAmPmStrings(wxString *am, wxString *pm);
0979c962 547
68379eaf 548 // return true if the given country uses DST for this year
239446b4
VZ
549 static bool IsDSTApplicable(int year = Inv_Year,
550 Country country = Country_Default);
551
0979c962
VZ
552 // get the beginning of DST for this year, will return invalid object
553 // if no DST applicable in this year. The default value of the
554 // parameter means to take the current year.
239446b4
VZ
555 static wxDateTime GetBeginDST(int year = Inv_Year,
556 Country country = Country_Default);
0979c962
VZ
557 // get the end of DST for this year, will return invalid object
558 // if no DST applicable in this year. The default value of the
559 // parameter means to take the current year.
239446b4
VZ
560 static wxDateTime GetEndDST(int year = Inv_Year,
561 Country country = Country_Default);
0979c962 562
b76b015e
VZ
563 // return the wxDateTime object for the current time
564 static inline wxDateTime Now();
565
f6bcfd97
BP
566 // return the wxDateTime object for the current time with millisecond
567 // precision (if available on this platform)
568 static wxDateTime UNow();
569
cd0b1709
VZ
570 // return the wxDateTime object for today midnight: i.e. as Now() but
571 // with time set to 0
572 static inline wxDateTime Today();
573
0979c962
VZ
574 // constructors: you should test whether the constructor succeeded with
575 // IsValid() function. The values Inv_Month and Inv_Year for the
576 // parameters mean take current month and/or year values.
577 // ------------------------------------------------------------------------
578
579 // default ctor does not initialize the object, use Set()!
4bd53224 580 wxDateTime() { m_time = wxLongLong(wxINT32_MIN, 0); }
0979c962
VZ
581
582 // from time_t: seconds since the Epoch 00:00:00 UTC, Jan 1, 1970)
16ee521a
DW
583#if (!(defined(__VISAGECPP__) && __IBMCPP__ >= 400))
584// VA C++ confuses this with wxDateTime(double jdn) thinking it is a duplicate declaration
0979c962 585 inline wxDateTime(time_t timet);
16ee521a 586#endif
b76b015e 587 // from broken down time/date (only for standard Unix range)
0979c962 588 inline wxDateTime(const struct tm& tm);
b76b015e
VZ
589 // from broken down time/date (any range)
590 inline wxDateTime(const Tm& tm);
0979c962 591
e6ec579c
VZ
592 // from JDN (beware of rounding errors)
593 inline wxDateTime(double jdn);
594
0979c962
VZ
595 // from separate values for each component, date set to today
596 inline wxDateTime(wxDateTime_t hour,
597 wxDateTime_t minute = 0,
598 wxDateTime_t second = 0,
599 wxDateTime_t millisec = 0);
600 // from separate values for each component with explicit date
b76b015e 601 inline wxDateTime(wxDateTime_t day, // day of the month
33ac7e6f 602 Month month,
0979c962
VZ
603 int year = Inv_Year, // 1999, not 99 please!
604 wxDateTime_t hour = 0,
605 wxDateTime_t minute = 0,
606 wxDateTime_t second = 0,
607 wxDateTime_t millisec = 0);
d98a58c5 608#ifdef __WINDOWS__
154014d6
VZ
609 wxDateTime(const struct _SYSTEMTIME& st)
610 {
611 SetFromMSWSysTime(st);
612 }
613#endif
0979c962
VZ
614
615 // default copy ctor ok
616
617 // no dtor
618
619 // assignment operators and Set() functions: all non const methods return
620 // the reference to this object. IsValid() should be used to test whether
621 // the function succeeded.
622 // ------------------------------------------------------------------------
623
624 // set to the current time
625 inline wxDateTime& SetToCurrent();
626
16ee521a
DW
627#if (!(defined(__VISAGECPP__) && __IBMCPP__ >= 400))
628// VA C++ confuses this with wxDateTime(double jdn) thinking it is a duplicate declaration
0979c962
VZ
629 // set to given time_t value
630 inline wxDateTime& Set(time_t timet);
16ee521a 631#endif
0979c962
VZ
632
633 // set to given broken down time/date
634 wxDateTime& Set(const struct tm& tm);
635
b76b015e
VZ
636 // set to given broken down time/date
637 inline wxDateTime& Set(const Tm& tm);
638
e6ec579c
VZ
639 // set to given JDN (beware of rounding errors)
640 wxDateTime& Set(double jdn);
641
0979c962
VZ
642 // set to given time, date = today
643 wxDateTime& Set(wxDateTime_t hour,
644 wxDateTime_t minute = 0,
645 wxDateTime_t second = 0,
646 wxDateTime_t millisec = 0);
647
648 // from separate values for each component with explicit date
649 // (defaults for month and year are the current values)
650 wxDateTime& Set(wxDateTime_t day,
33ac7e6f 651 Month month,
0979c962
VZ
652 int year = Inv_Year, // 1999, not 99 please!
653 wxDateTime_t hour = 0,
654 wxDateTime_t minute = 0,
655 wxDateTime_t second = 0,
656 wxDateTime_t millisec = 0);
657
658 // resets time to 00:00:00, doesn't change the date
659 wxDateTime& ResetTime();
660
fb96cf85
VZ
661 // get the date part of this object only, i.e. the object which has the
662 // same date as this one but time of 00:00:00
663 wxDateTime GetDateOnly() const;
fb96cf85 664
0979c962
VZ
665 // the following functions don't change the values of the other
666 // fields, i.e. SetMinute() won't change either hour or seconds value
667
668 // set the year
669 wxDateTime& SetYear(int year);
670 // set the month
671 wxDateTime& SetMonth(Month month);
672 // set the day of the month
673 wxDateTime& SetDay(wxDateTime_t day);
674 // set hour
675 wxDateTime& SetHour(wxDateTime_t hour);
676 // set minute
677 wxDateTime& SetMinute(wxDateTime_t minute);
678 // set second
679 wxDateTime& SetSecond(wxDateTime_t second);
680 // set millisecond
681 wxDateTime& SetMillisecond(wxDateTime_t millisecond);
682
683 // assignment operator from time_t
684 wxDateTime& operator=(time_t timet) { return Set(timet); }
685
686 // assignment operator from broken down time/date
687 wxDateTime& operator=(const struct tm& tm) { return Set(tm); }
688
b76b015e
VZ
689 // assignment operator from broken down time/date
690 wxDateTime& operator=(const Tm& tm) { return Set(tm); }
691
0979c962
VZ
692 // default assignment operator is ok
693
694 // calendar calculations (functions which set the date only leave the time
1582a1db 695 // unchanged, e.g. don't explicitly zero it): SetXXX() functions modify the
4f6aed9c 696 // object itself, GetXXX() ones return a new object.
0979c962
VZ
697 // ------------------------------------------------------------------------
698
cd0b1709 699 // set to the given week day in the same week as this one
2b5f62a0
VZ
700 wxDateTime& SetToWeekDayInSameWeek(WeekDay weekday,
701 WeekFlags flags = Monday_First);
702 inline wxDateTime GetWeekDayInSameWeek(WeekDay weekday,
703 WeekFlags flags = Monday_First) const;
cd0b1709
VZ
704
705 // set to the next week day following this one
706 wxDateTime& SetToNextWeekDay(WeekDay weekday);
4f6aed9c 707 inline wxDateTime GetNextWeekDay(WeekDay weekday) const;
cd0b1709 708
2ef31e80 709 // set to the previous week day before this one
cd0b1709 710 wxDateTime& SetToPrevWeekDay(WeekDay weekday);
4f6aed9c 711 inline wxDateTime GetPrevWeekDay(WeekDay weekday) const;
cd0b1709 712
7929902d 713 // set to Nth occurrence of given weekday in the given month of the
68379eaf 714 // given year (time is set to 0), return true on success and false on
0979c962
VZ
715 // failure. n may be positive (1..5) or negative to count from the end
716 // of the month (see helper function SetToLastWeekDay())
717 bool SetToWeekDay(WeekDay weekday,
718 int n = 1,
2f02cb89 719 Month month = Inv_Month,
0979c962 720 int year = Inv_Year);
4f6aed9c
VZ
721 inline wxDateTime GetWeekDay(WeekDay weekday,
722 int n = 1,
723 Month month = Inv_Month,
724 int year = Inv_Year) const;
0979c962
VZ
725
726 // sets to the last weekday in the given month, year
727 inline bool SetToLastWeekDay(WeekDay weekday,
2f02cb89 728 Month month = Inv_Month,
0979c962 729 int year = Inv_Year);
4f6aed9c
VZ
730 inline wxDateTime GetLastWeekDay(WeekDay weekday,
731 Month month = Inv_Month,
732 int year = Inv_Year);
0979c962 733
ca3e85cf 734#if WXWIN_COMPATIBILITY_2_6
0979c962 735 // sets the date to the given day of the given week in the year,
68379eaf 736 // returns true on success and false if given date doesn't exist (e.g.
0979c962 737 // numWeek is > 53)
4c27e2fa
VZ
738 //
739 // these functions are badly defined as they're not the reverse of
740 // GetWeekOfYear(), use SetToTheWeekOfYear() instead
741 wxDEPRECATED( bool SetToTheWeek(wxDateTime_t numWeek,
742 WeekDay weekday = Mon,
743 WeekFlags flags = Monday_First) );
744 wxDEPRECATED( wxDateTime GetWeek(wxDateTime_t numWeek,
745 WeekDay weekday = Mon,
746 WeekFlags flags = Monday_First) const );
ca3e85cf 747#endif // WXWIN_COMPATIBILITY_2_6
4c27e2fa
VZ
748
749 // returns the date corresponding to the given week day of the given
750 // week (in ISO notation) of the specified year
751 static wxDateTime SetToWeekOfYear(int year,
752 wxDateTime_t numWeek,
753 WeekDay weekday = Mon);
0979c962 754
2f02cb89
VZ
755 // sets the date to the last day of the given (or current) month or the
756 // given (or current) year
757 wxDateTime& SetToLastMonthDay(Month month = Inv_Month,
758 int year = Inv_Year);
4f6aed9c
VZ
759 inline wxDateTime GetLastMonthDay(Month month = Inv_Month,
760 int year = Inv_Year) const;
0979c962 761
f0f951fa
VZ
762 // sets to the given year day (1..365 or 366)
763 wxDateTime& SetToYearDay(wxDateTime_t yday);
4f6aed9c 764 inline wxDateTime GetYearDay(wxDateTime_t yday) const;
f0f951fa 765
0979c962
VZ
766 // The definitions below were taken verbatim from
767 //
768 // http://www.capecod.net/~pbaum/date/date0.htm
769 //
770 // (Peter Baum's home page)
771 //
772 // definition: The Julian Day Number, Julian Day, or JD of a
773 // particular instant of time is the number of days and fractions of a
774 // day since 12 hours Universal Time (Greenwich mean noon) on January
775 // 1 of the year -4712, where the year is given in the Julian
776 // proleptic calendar. The idea of using this reference date was
777 // originally proposed by Joseph Scalizer in 1582 to count years but
778 // it was modified by 19th century astronomers to count days. One
779 // could have equivalently defined the reference time to be noon of
780 // November 24, -4713 if were understood that Gregorian calendar rules
781 // were applied. Julian days are Julian Day Numbers and are not to be
782 // confused with Julian dates.
783 //
784 // definition: The Rata Die number is a date specified as the number
785 // of days relative to a base date of December 31 of the year 0. Thus
786 // January 1 of the year 1 is Rata Die day 1.
787
e6ec579c
VZ
788 // get the Julian Day number (the fractional part specifies the time of
789 // the day, related to noon - beware of rounding errors!)
790 double GetJulianDayNumber() const;
239446b4
VZ
791 double GetJDN() const { return GetJulianDayNumber(); }
792
793 // get the Modified Julian Day number: it is equal to JDN - 2400000.5
794 // and so integral MJDs correspond to the midnights (and not noons).
795 // MJD 0 is Nov 17, 1858
796 double GetModifiedJulianDayNumber() const { return GetJDN() - 2400000.5; }
797 double GetMJD() const { return GetModifiedJulianDayNumber(); }
0979c962
VZ
798
799 // get the Rata Die number
e6ec579c 800 double GetRataDie() const;
0979c962
VZ
801
802 // TODO algorithms for calculating some important dates, such as
803 // religious holidays (Easter...) or moon/solar eclipses? Some
804 // algorithms can be found in the calendar FAQ
805
d26adb9d
VZ
806
807 // Timezone stuff: a wxDateTime object constructed using given
808 // day/month/year/hour/min/sec values is interpreted as this moment in
809 // local time. Using the functions below, it may be converted to another
810 // time zone (e.g., the Unix epoch is wxDateTime(1, Jan, 1970).ToGMT()).
299fcbfe 811 //
d26adb9d 812 // These functions try to handle DST internally, but there is no magical
41acf5c0
VZ
813 // way to know all rules for it in all countries in the world, so if the
814 // program can handle it itself (or doesn't want to handle it at all for
815 // whatever reason), the DST handling can be disabled with noDST.
b76b015e
VZ
816 // ------------------------------------------------------------------------
817
299fcbfe 818 // transform to any given timezone
68379eaf
WS
819 inline wxDateTime ToTimezone(const TimeZone& tz, bool noDST = false) const;
820 wxDateTime& MakeTimezone(const TimeZone& tz, bool noDST = false);
b76b015e 821
d26adb9d
VZ
822 // interpret current value as being in another timezone and transform
823 // it to local one
824 inline wxDateTime FromTimezone(const TimeZone& tz, bool noDST = false) const;
825 wxDateTime& MakeFromTimezone(const TimeZone& tz, bool noDST = false);
d26adb9d
VZ
826
827 // transform to/from GMT/UTC
828 wxDateTime ToUTC(bool noDST = false) const { return ToTimezone(UTC, noDST); }
829 wxDateTime& MakeUTC(bool noDST = false) { return MakeTimezone(UTC, noDST); }
830
831 wxDateTime ToGMT(bool noDST = false) const { return ToUTC(noDST); }
832 wxDateTime& MakeGMT(bool noDST = false) { return MakeUTC(noDST); }
833
d26adb9d
VZ
834 wxDateTime FromUTC(bool noDST = false) const
835 { return FromTimezone(UTC, noDST); }
836 wxDateTime& MakeFromUTC(bool noDST = false)
837 { return MakeFromTimezone(UTC, noDST); }
fcc3d7cb 838
239446b4
VZ
839 // is daylight savings time in effect at this moment according to the
840 // rules of the specified country?
841 //
842 // Return value is > 0 if DST is in effect, 0 if it is not and -1 if
843 // the information is not available (this is compatible with ANSI C)
844 int IsDST(Country country = Country_Default) const;
845
d26adb9d 846
0979c962
VZ
847 // accessors: many of them take the timezone parameter which indicates the
848 // timezone for which to make the calculations and the default value means
849 // to do it for the current timezone of this machine (even if the function
850 // only operates with the date it's necessary because a date may wrap as
851 // result of timezone shift)
852 // ------------------------------------------------------------------------
853
c3302e7e 854 // is the date valid?
384223b3 855 inline bool IsValid() const { return m_time != wxInvalidDateTime.m_time; }
0979c962 856
299fcbfe
VZ
857 // get the broken down date/time representation in the given timezone
858 //
859 // If you wish to get several time components (day, month and year),
860 // consider getting the whole Tm strcuture first and retrieving the
861 // value from it - this is much more efficient
862 Tm GetTm(const TimeZone& tz = Local) const;
b76b015e
VZ
863
864 // get the number of seconds since the Unix epoch - returns (time_t)-1
865 // if the value is out of range
866 inline time_t GetTicks() const;
867
a333edbd
VZ
868 // get the century, same as GetCentury(GetYear())
869 int GetCentury(const TimeZone& tz = Local) const
870 { return GetCentury(GetYear(tz)); }
0979c962 871 // get the year (returns Inv_Year if date is invalid)
16ee521a 872 int GetYear(const TimeZone& tz = Local) const
299fcbfe 873 { return GetTm(tz).year; }
0979c962 874 // get the month (Inv_Month if date is invalid)
16ee521a 875 Month GetMonth(const TimeZone& tz = Local) const
299fcbfe 876 { return (Month)GetTm(tz).mon; }
0979c962 877 // get the month day (in 1..31 range, 0 if date is invalid)
16ee521a 878 wxDateTime_t GetDay(const TimeZone& tz = Local) const
299fcbfe 879 { return GetTm(tz).mday; }
0979c962 880 // get the day of the week (Inv_WeekDay if date is invalid)
16ee521a 881 WeekDay GetWeekDay(const TimeZone& tz = Local) const
299fcbfe 882 { return GetTm(tz).GetWeekDay(); }
0979c962 883 // get the hour of the day
16ee521a 884 wxDateTime_t GetHour(const TimeZone& tz = Local) const
299fcbfe 885 { return GetTm(tz).hour; }
0979c962 886 // get the minute
16ee521a 887 wxDateTime_t GetMinute(const TimeZone& tz = Local) const
299fcbfe 888 { return GetTm(tz).min; }
0979c962 889 // get the second
16ee521a 890 wxDateTime_t GetSecond(const TimeZone& tz = Local) const
299fcbfe 891 { return GetTm(tz).sec; }
0979c962 892 // get milliseconds
16ee521a 893 wxDateTime_t GetMillisecond(const TimeZone& tz = Local) const
299fcbfe 894 { return GetTm(tz).msec; }
0979c962
VZ
895
896 // get the day since the year start (1..366, 0 if date is invalid)
299fcbfe 897 wxDateTime_t GetDayOfYear(const TimeZone& tz = Local) const;
cd0b1709 898 // get the week number since the year start (1..52 or 53, 0 if date is
0979c962 899 // invalid)
9d9b7755
VZ
900 wxDateTime_t GetWeekOfYear(WeekFlags flags = Monday_First,
901 const TimeZone& tz = Local) const;
cd0b1709
VZ
902 // get the week number since the month start (1..5, 0 if date is
903 // invalid)
9d9b7755
VZ
904 wxDateTime_t GetWeekOfMonth(WeekFlags flags = Monday_First,
905 const TimeZone& tz = Local) const;
0979c962
VZ
906
907 // is this date a work day? This depends on a country, of course,
908 // because the holidays are different in different countries
4f6aed9c 909 bool IsWorkDay(Country country = Country_Default) const;
0979c962
VZ
910
911 // is this date later than Gregorian calendar introduction for the
912 // given country (see enum GregorianAdoption)?
913 //
4f6aed9c 914 // NB: this function shouldn't be considered as absolute authority in
0979c962
VZ
915 // the matter. Besides, for some countries the exact date of
916 // adoption of the Gregorian calendar is simply unknown.
b76b015e 917 bool IsGregorianDate(GregorianAdoption country = Gr_Standard) const;
0979c962 918
2b5f62a0
VZ
919 // dos date and time format
920 // ------------------------------------------------------------------------
921
922 // set from the DOS packed format
923 wxDateTime& SetFromDOS(unsigned long ddt);
924
925 // pack the date in DOS format
926 unsigned long GetAsDOS() const;
927
154014d6
VZ
928 // SYSTEMTIME format
929 // ------------------------------------------------------------------------
d98a58c5 930#ifdef __WINDOWS__
154014d6 931 // convert SYSTEMTIME to wxDateTime
10acc3ef 932 wxDateTime& SetFromMSWSysTime(const struct _SYSTEMTIME& st);
154014d6
VZ
933
934 // convert wxDateTime to SYSTEMTIME
10acc3ef
VZ
935 void GetAsMSWSysTime(struct _SYSTEMTIME* st) const;
936
937 // same as above but only take date part into account, time is always zero
938 wxDateTime& SetFromMSWSysDate(const struct _SYSTEMTIME& st);
939 void GetAsMSWSysDate(struct _SYSTEMTIME* st) const;
d98a58c5 940#endif // __WINDOWS__
154014d6 941
0979c962
VZ
942 // comparison (see also functions below for operator versions)
943 // ------------------------------------------------------------------------
944
68379eaf 945 // returns true if the two moments are strictly identical
b76b015e
VZ
946 inline bool IsEqualTo(const wxDateTime& datetime) const;
947
68379eaf 948 // returns true if the date is strictly earlier than the given one
b76b015e 949 inline bool IsEarlierThan(const wxDateTime& datetime) const;
0979c962 950
68379eaf 951 // returns true if the date is strictly later than the given one
b76b015e 952 inline bool IsLaterThan(const wxDateTime& datetime) const;
0979c962 953
68379eaf 954 // returns true if the date is strictly in the given range
b76b015e
VZ
955 inline bool IsStrictlyBetween(const wxDateTime& t1,
956 const wxDateTime& t2) const;
957
68379eaf 958 // returns true if the date is in the given range
b76b015e 959 inline bool IsBetween(const wxDateTime& t1, const wxDateTime& t2) const;
0979c962 960
be4017f8
VZ
961 // do these two objects refer to the same date?
962 inline bool IsSameDate(const wxDateTime& dt) const;
963
964 // do these two objects have the same time?
965 inline bool IsSameTime(const wxDateTime& dt) const;
966
967 // are these two objects equal up to given timespan?
968 inline bool IsEqualUpTo(const wxDateTime& dt, const wxTimeSpan& ts) const;
969
26364344
WS
970 inline bool operator<(const wxDateTime& dt) const
971 {
9a83f860 972 wxASSERT_MSG( IsValid() && dt.IsValid(), wxT("invalid wxDateTime") );
26364344
WS
973 return GetValue() < dt.GetValue();
974 }
975
976 inline bool operator<=(const wxDateTime& dt) const
977 {
9a83f860 978 wxASSERT_MSG( IsValid() && dt.IsValid(), wxT("invalid wxDateTime") );
26364344
WS
979 return GetValue() <= dt.GetValue();
980 }
981
982 inline bool operator>(const wxDateTime& dt) const
983 {
9a83f860 984 wxASSERT_MSG( IsValid() && dt.IsValid(), wxT("invalid wxDateTime") );
26364344
WS
985 return GetValue() > dt.GetValue();
986 }
987
988 inline bool operator>=(const wxDateTime& dt) const
989 {
9a83f860 990 wxASSERT_MSG( IsValid() && dt.IsValid(), wxT("invalid wxDateTime") );
26364344
WS
991 return GetValue() >= dt.GetValue();
992 }
993
994 inline bool operator==(const wxDateTime& dt) const
995 {
9a83f860 996 wxASSERT_MSG( IsValid() && dt.IsValid(), wxT("invalid wxDateTime") );
26364344
WS
997 return GetValue() == dt.GetValue();
998 }
999
1000 inline bool operator!=(const wxDateTime& dt) const
1001 {
9a83f860 1002 wxASSERT_MSG( IsValid() && dt.IsValid(), wxT("invalid wxDateTime") );
26364344
WS
1003 return GetValue() != dt.GetValue();
1004 }
1005
cd0b1709 1006 // arithmetics with dates (see also below for more operators)
0979c962
VZ
1007 // ------------------------------------------------------------------------
1008
cd0b1709
VZ
1009 // return the sum of the date with a time span (positive or negative)
1010 inline wxDateTime Add(const wxTimeSpan& diff) const;
0979c962 1011 // add a time span (positive or negative)
b76b015e 1012 inline wxDateTime& Add(const wxTimeSpan& diff);
0979c962 1013 // add a time span (positive or negative)
b76b015e 1014 inline wxDateTime& operator+=(const wxTimeSpan& diff);
26364344
WS
1015 inline wxDateTime operator+(const wxTimeSpan& ts) const
1016 {
1017 wxDateTime dt(*this);
1018 dt.Add(ts);
1019 return dt;
1020 }
0979c962 1021
cd0b1709 1022 // return the difference of the date with a time span
f6bcfd97
BP
1023 inline wxDateTime Subtract(const wxTimeSpan& diff) const;
1024 // subtract a time span (positive or negative)
1025 inline wxDateTime& Subtract(const wxTimeSpan& diff);
1026 // subtract a time span (positive or negative)
0979c962 1027 inline wxDateTime& operator-=(const wxTimeSpan& diff);
26364344
WS
1028 inline wxDateTime operator-(const wxTimeSpan& ts) const
1029 {
1030 wxDateTime dt(*this);
1031 dt.Subtract(ts);
1032 return dt;
1033 }
0979c962 1034
cd0b1709
VZ
1035 // return the sum of the date with a date span
1036 inline wxDateTime Add(const wxDateSpan& diff) const;
0979c962
VZ
1037 // add a date span (positive or negative)
1038 wxDateTime& Add(const wxDateSpan& diff);
1039 // add a date span (positive or negative)
b76b015e 1040 inline wxDateTime& operator+=(const wxDateSpan& diff);
26364344
WS
1041 inline wxDateTime operator+(const wxDateSpan& ds) const
1042 {
1043 wxDateTime dt(*this);
1044 dt.Add(ds);
1045 return dt;
1046 }
0979c962 1047
cd0b1709 1048 // return the difference of the date with a date span
f6bcfd97
BP
1049 inline wxDateTime Subtract(const wxDateSpan& diff) const;
1050 // subtract a date span (positive or negative)
1051 inline wxDateTime& Subtract(const wxDateSpan& diff);
1052 // subtract a date span (positive or negative)
0979c962 1053 inline wxDateTime& operator-=(const wxDateSpan& diff);
26364344
WS
1054 inline wxDateTime operator-(const wxDateSpan& ds) const
1055 {
1056 wxDateTime dt(*this);
1057 dt.Subtract(ds);
1058 return dt;
1059 }
0979c962 1060
cd0b1709 1061 // return the difference between two dates
f6bcfd97 1062 inline wxTimeSpan Subtract(const wxDateTime& dt) const;
26364344 1063 inline wxTimeSpan operator-(const wxDateTime& dt2) const;
0979c962 1064
77dd7daa
VZ
1065 wxDateSpan DiffAsDateSpan(const wxDateTime& dt) const;
1066
c398434d 1067 // conversion to/from text
0979c962
VZ
1068 // ------------------------------------------------------------------------
1069
c398434d
VZ
1070 // all conversions functions return true to indicate whether parsing
1071 // succeeded or failed and fill in the provided end iterator, which must
1072 // not be NULL, with the location of the character where the parsing
1073 // stopped (this will be end() of the passed string if everything was
1074 // parsed)
1075
0979c962
VZ
1076 // parse a string in RFC 822 format (found e.g. in mail headers and
1077 // having the form "Wed, 10 Feb 1999 19:07:07 +0100")
c398434d
VZ
1078 bool ParseRfc822Date(const wxString& date,
1079 wxString::const_iterator *end);
75a29ef1 1080
f0f951fa
VZ
1081 // parse a date/time in the given format (see strptime(3)), fill in
1082 // the missing (in the string) fields with the values of dateDef (by
1083 // default, they will not change if they had valid values or will
1084 // default to Today() otherwise)
c398434d
VZ
1085 bool ParseFormat(const wxString& date,
1086 const wxString& format,
1087 const wxDateTime& dateDef,
1088 wxString::const_iterator *end);
1089
1090 bool ParseFormat(const wxString& date,
1091 const wxString& format,
1092 wxString::const_iterator *end)
71ebd60b
VZ
1093 {
1094 return ParseFormat(date, format, wxDefaultDateTime, end);
1095 }
1096
c398434d
VZ
1097 bool ParseFormat(const wxString& date,
1098 wxString::const_iterator *end)
1099 {
1100 return ParseFormat(date, wxDefaultDateTimeFormat, wxDefaultDateTime, end);
1101 }
71ebd60b 1102
f3f2e255
VZ
1103 // parse a string containing date, time or both in ISO 8601 format
1104 //
1105 // notice that these functions are new in wx 3.0 and so we don't
1106 // provide compatibility overloads for them
1107 bool ParseISODate(const wxString& date)
1108 {
a0bcd61b 1109 wxString::const_iterator end;
c398434d 1110 return ParseFormat(date, wxS("%Y-%m-%d"), &end) && end == date.end();
f3f2e255
VZ
1111 }
1112
a0bcd61b 1113 bool ParseISOTime(const wxString& time)
f3f2e255 1114 {
a0bcd61b 1115 wxString::const_iterator end;
c398434d 1116 return ParseFormat(time, wxS("%H:%M:%S"), &end) && end == time.end();
f3f2e255
VZ
1117 }
1118
a0bcd61b 1119 bool ParseISOCombined(const wxString& datetime, char sep = 'T')
f3f2e255 1120 {
a0bcd61b 1121 wxString::const_iterator end;
f3f2e255 1122 const wxString fmt = wxS("%Y-%m-%d") + wxString(sep) + wxS("%H:%M:%S");
c398434d 1123 return ParseFormat(datetime, fmt, &end) && end == datetime.end();
f3f2e255
VZ
1124 }
1125
0979c962
VZ
1126 // parse a string containing the date/time in "free" format, this
1127 // function will try to make an educated guess at the string contents
c398434d
VZ
1128 bool ParseDateTime(const wxString& datetime,
1129 wxString::const_iterator *end);
71ebd60b 1130
cd0b1709
VZ
1131 // parse a string containing the date only in "free" format (less
1132 // flexible than ParseDateTime)
c398434d
VZ
1133 bool ParseDate(const wxString& date,
1134 wxString::const_iterator *end);
71ebd60b 1135
cd0b1709 1136 // parse a string containing the time only in "free" format
c398434d
VZ
1137 bool ParseTime(const wxString& time,
1138 wxString::const_iterator *end);
71ebd60b 1139
0979c962
VZ
1140
1141 // this function accepts strftime()-like format string (default
1142 // argument corresponds to the preferred date and time representation
1143 // for the current locale) and returns the string containing the
1144 // resulting text representation
12e82477 1145 wxString Format(const wxString& format = wxDefaultDateTimeFormat,
299fcbfe 1146 const TimeZone& tz = Local) const;
0979c962 1147 // preferred date representation for the current locale
f3f2e255 1148 wxString FormatDate() const { return Format(wxS("%x")); }
0979c962 1149 // preferred time representation for the current locale
f3f2e255 1150 wxString FormatTime() const { return Format(wxS("%X")); }
4f6aed9c 1151 // returns the string representing the date in ISO 8601 format
9d9b7755 1152 // (YYYY-MM-DD)
f3f2e255 1153 wxString FormatISODate() const { return Format(wxS("%Y-%m-%d")); }
4f6aed9c
VZ
1154 // returns the string representing the time in ISO 8601 format
1155 // (HH:MM:SS)
f3f2e255
VZ
1156 wxString FormatISOTime() const { return Format(wxS("%H:%M:%S")); }
1157 // return the combined date time representation in ISO 8601 format; the
1158 // separator character should be 'T' according to the standard but it
1159 // can also be useful to set it to ' '
1160 wxString FormatISOCombined(char sep = 'T') const
1161 { return FormatISODate() + sep + FormatISOTime(); }
0979c962 1162
c398434d
VZ
1163
1164 // backwards compatible versions of the parsing functions: they return an
1165 // object representing the next character following the date specification
1166 // (i.e. the one where the scan had to stop) or a special NULL-like object
1167 // on failure
1168 //
1169 // they're not deprecated because a lot of existing code uses them and
1170 // there is no particular harm in keeping them but you should still prefer
1171 // the versions above in the new code
1172 wxAnyStrPtr ParseRfc822Date(const wxString& date)
1173 {
1174 wxString::const_iterator end;
1175 return ParseRfc822Date(date, &end) ? wxAnyStrPtr(date, end)
1176 : wxAnyStrPtr();
1177 }
1178
1179 wxAnyStrPtr ParseFormat(const wxString& date,
1180 const wxString& format = wxDefaultDateTimeFormat,
1181 const wxDateTime& dateDef = wxDefaultDateTime)
1182 {
1183 wxString::const_iterator end;
1184 return ParseFormat(date, format, dateDef, &end) ? wxAnyStrPtr(date, end)
1185 : wxAnyStrPtr();
1186 }
1187
1188 wxAnyStrPtr ParseDateTime(const wxString& datetime)
1189 {
1190 wxString::const_iterator end;
1191 return ParseDateTime(datetime, &end) ? wxAnyStrPtr(datetime, end)
1192 : wxAnyStrPtr();
1193 }
1194
1195 wxAnyStrPtr ParseDate(const wxString& date)
1196 {
1197 wxString::const_iterator end;
1198 return ParseDate(date, &end) ? wxAnyStrPtr(date, end)
1199 : wxAnyStrPtr();
1200 }
1201
1202 wxAnyStrPtr ParseTime(const wxString& time)
1203 {
1204 wxString::const_iterator end;
1205 return ParseTime(time, &end) ? wxAnyStrPtr(time, end)
1206 : wxAnyStrPtr();
1207 }
1208
f17ac574
VZ
1209 // In addition to wxAnyStrPtr versions above we also must provide the
1210 // overloads for C strings as we must return a pointer into the original
1211 // string and not inside a temporary wxString which would have been created
1212 // if the overloads above were used.
1213 //
1214 // And then we also have to provide the overloads for wxCStrData, as usual.
ae8079a2
VZ
1215 // Unfortunately those ones can't return anything as we don't have any
1216 // sufficiently long-lived wxAnyStrPtr to return from them: any temporary
1217 // strings it would point to would be destroyed when this function returns
1218 // making it impossible to dereference the return value. So we just don't
1219 // return anything from here which at least allows to keep compatibility
1220 // with the code not testing the return value. Other uses of this method
1221 // need to be converted to use one of the new bool-returning overloads
1222 // above.
1223 void ParseRfc822Date(const wxCStrData& date)
1224 { ParseRfc822Date(wxString(date)); }
f17ac574
VZ
1225 const char* ParseRfc822Date(const char* date);
1226 const wchar_t* ParseRfc822Date(const wchar_t* date);
1227
ae8079a2
VZ
1228 void ParseFormat(const wxCStrData& date,
1229 const wxString& format = wxDefaultDateTimeFormat,
1230 const wxDateTime& dateDef = wxDefaultDateTime)
1231 { ParseFormat(wxString(date), format, dateDef); }
f17ac574
VZ
1232 const char* ParseFormat(const char* date,
1233 const wxString& format = wxDefaultDateTimeFormat,
1234 const wxDateTime& dateDef = wxDefaultDateTime);
1235 const wchar_t* ParseFormat(const wchar_t* date,
1236 const wxString& format = wxDefaultDateTimeFormat,
1237 const wxDateTime& dateDef = wxDefaultDateTime);
1238
ae8079a2
VZ
1239 void ParseDateTime(const wxCStrData& datetime)
1240 { ParseDateTime(wxString(datetime)); }
f17ac574
VZ
1241 const char* ParseDateTime(const char* datetime);
1242 const wchar_t* ParseDateTime(const wchar_t* datetime);
1243
ae8079a2
VZ
1244 void ParseDate(const wxCStrData& date)
1245 { ParseDate(wxString(date)); }
f17ac574
VZ
1246 const char* ParseDate(const char* date);
1247 const wchar_t* ParseDate(const wchar_t* date);
1248
ae8079a2
VZ
1249 void ParseTime(const wxCStrData& time)
1250 { ParseTime(wxString(time)); }
f17ac574
VZ
1251 const char* ParseTime(const char* time);
1252 const wchar_t* ParseTime(const wchar_t* time);
1253
1254
0979c962
VZ
1255 // implementation
1256 // ------------------------------------------------------------------------
1257
cd0b1709
VZ
1258 // construct from internal representation
1259 wxDateTime(const wxLongLong& time) { m_time = time; }
1260
0979c962
VZ
1261 // get the internal representation
1262 inline wxLongLong GetValue() const;
1263
0979c962 1264 // a helper function to get the current time_t
d3b9f782 1265 static time_t GetTimeNow() { return time(NULL); }
0979c962 1266
2f02cb89
VZ
1267 // another one to get the current time broken down
1268 static struct tm *GetTmNow()
1269 {
135d1ad0
JS
1270 static struct tm l_CurrentTime;
1271 return GetTmNow(&l_CurrentTime);
2f02cb89
VZ
1272 }
1273
a452689b
SN
1274 // get current time using thread-safe function
1275 static struct tm *GetTmNow(struct tm *tmstruct);
1276
2f02cb89 1277private:
0979c962 1278 // the current country - as it's the same for all program objects (unless
b76b015e
VZ
1279 // it runs on a _really_ big cluster system :-), this is a static member:
1280 // see SetCountry() and GetCountry()
0979c962
VZ
1281 static Country ms_country;
1282
0979c962
VZ
1283 // this constant is used to transform a time_t value to the internal
1284 // representation, as time_t is in seconds and we use milliseconds it's
1285 // fixed to 1000
cd0b1709 1286 static const long TIME_T_FACTOR;
0979c962 1287
68379eaf 1288 // returns true if we fall in range in which we can use standard ANSI C
b76b015e 1289 // functions
fcc3d7cb 1290 inline bool IsInStdRange() const;
b76b015e
VZ
1291
1292 // the internal representation of the time is the amount of milliseconds
1293 // elapsed since the origin which is set by convention to the UNIX/C epoch
1294 // value: the midnight of January 1, 1970 (UTC)
1295 wxLongLong m_time;
0979c962
VZ
1296};
1297
1298// ----------------------------------------------------------------------------
1299// This class contains a difference between 2 wxDateTime values, so it makes
f6bcfd97 1300// sense to add it to wxDateTime and it is the result of subtraction of 2
0979c962
VZ
1301// objects of that class. See also wxDateSpan.
1302// ----------------------------------------------------------------------------
b76b015e 1303
bddd7a8d 1304class WXDLLIMPEXP_BASE wxTimeSpan
0979c962
VZ
1305{
1306public:
1307 // constructors
1308 // ------------------------------------------------------------------------
1309
bd35ed32
VZ
1310 // return the timespan for the given number of milliseconds
1311 static wxTimeSpan Milliseconds(wxLongLong ms) { return wxTimeSpan(0, 0, 0, ms); }
1312 static wxTimeSpan Millisecond() { return Milliseconds(1); }
1313
fcc3d7cb 1314 // return the timespan for the given number of seconds
9c21e80b 1315 static wxTimeSpan Seconds(wxLongLong sec) { return wxTimeSpan(0, 0, sec); }
68ee7c47 1316 static wxTimeSpan Second() { return Seconds(1); }
fcc3d7cb
VZ
1317
1318 // return the timespan for the given number of minutes
6f2a55e3 1319 static wxTimeSpan Minutes(long min) { return wxTimeSpan(0, min, 0 ); }
68ee7c47 1320 static wxTimeSpan Minute() { return Minutes(1); }
fcc3d7cb
VZ
1321
1322 // return the timespan for the given number of hours
6f2a55e3 1323 static wxTimeSpan Hours(long hours) { return wxTimeSpan(hours, 0, 0); }
68ee7c47 1324 static wxTimeSpan Hour() { return Hours(1); }
fcc3d7cb 1325
cd0b1709 1326 // return the timespan for the given number of days
6f2a55e3 1327 static wxTimeSpan Days(long days) { return Hours(24 * days); }
68ee7c47 1328 static wxTimeSpan Day() { return Days(1); }
cd0b1709
VZ
1329
1330 // return the timespan for the given number of weeks
6f2a55e3 1331 static wxTimeSpan Weeks(long days) { return Days(7 * days); }
68ee7c47 1332 static wxTimeSpan Week() { return Weeks(1); }
cd0b1709 1333
0979c962
VZ
1334 // default ctor constructs the 0 time span
1335 wxTimeSpan() { }
1336
1337 // from separate values for each component, date set to 0 (hours are
1338 // not restricted to 0..24 range, neither are minutes, seconds or
1339 // milliseconds)
6f2a55e3
VZ
1340 inline wxTimeSpan(long hours,
1341 long minutes = 0,
9c21e80b
VZ
1342 wxLongLong seconds = 0,
1343 wxLongLong milliseconds = 0);
0979c962 1344
0979c962
VZ
1345 // default copy ctor is ok
1346
1347 // no dtor
1348
cd0b1709 1349 // arithmetics with time spans (see also below for more operators)
0979c962
VZ
1350 // ------------------------------------------------------------------------
1351
cd0b1709
VZ
1352 // return the sum of two timespans
1353 inline wxTimeSpan Add(const wxTimeSpan& diff) const;
0979c962
VZ
1354 // add two timespans together
1355 inline wxTimeSpan& Add(const wxTimeSpan& diff);
1356 // add two timespans together
1357 wxTimeSpan& operator+=(const wxTimeSpan& diff) { return Add(diff); }
26364344
WS
1358 inline wxTimeSpan operator+(const wxTimeSpan& ts) const
1359 {
1360 return wxTimeSpan(GetValue() + ts.GetValue());
1361 }
0979c962 1362
cd0b1709 1363 // return the difference of two timespans
f6bcfd97
BP
1364 inline wxTimeSpan Subtract(const wxTimeSpan& diff) const;
1365 // subtract another timespan
1366 inline wxTimeSpan& Subtract(const wxTimeSpan& diff);
1367 // subtract another timespan
1368 wxTimeSpan& operator-=(const wxTimeSpan& diff) { return Subtract(diff); }
26364344
WS
1369 inline wxTimeSpan operator-(const wxTimeSpan& ts)
1370 {
1371 return wxTimeSpan(GetValue() - ts.GetValue());
1372 }
0979c962 1373
cd0b1709
VZ
1374 // multiply timespan by a scalar
1375 inline wxTimeSpan Multiply(int n) const;
0979c962
VZ
1376 // multiply timespan by a scalar
1377 inline wxTimeSpan& Multiply(int n);
1378 // multiply timespan by a scalar
1379 wxTimeSpan& operator*=(int n) { return Multiply(n); }
26364344
WS
1380 inline wxTimeSpan operator*(int n) const
1381 {
1382 return wxTimeSpan(*this).Multiply(n);
1383 }
0979c962 1384
3103e8a9 1385 // return this timespan with opposite sign
b76b015e 1386 wxTimeSpan Negate() const { return wxTimeSpan(-GetValue()); }
0979c962
VZ
1387 // negate the value of the timespan
1388 wxTimeSpan& Neg() { m_diff = -GetValue(); return *this; }
1389 // negate the value of the timespan
1390 wxTimeSpan& operator-() { return Neg(); }
1391
1392 // return the absolute value of the timespan: does _not_ modify the
1393 // object
1394 inline wxTimeSpan Abs() const;
1395
1396 // there is intentionally no division because we don't want to
1397 // introduce rounding errors in time calculations
1398
1399 // comparaison (see also operator versions below)
1400 // ------------------------------------------------------------------------
1401
1402 // is the timespan null?
b76b015e 1403 bool IsNull() const { return m_diff == 0l; }
0979c962
VZ
1404 // returns true if the timespan is null
1405 bool operator!() const { return !IsNull(); }
1406
1407 // is the timespan positive?
b76b015e 1408 bool IsPositive() const { return m_diff > 0l; }
0979c962
VZ
1409
1410 // is the timespan negative?
b76b015e 1411 bool IsNegative() const { return m_diff < 0l; }
0979c962
VZ
1412
1413 // are two timespans equal?
1414 inline bool IsEqualTo(const wxTimeSpan& ts) const;
1415 // compare two timestamps: works with the absolute values, i.e. -2
68379eaf 1416 // hours is longer than 1 hour. Also, it will return false if the
0979c962
VZ
1417 // timespans are equal in absolute value.
1418 inline bool IsLongerThan(const wxTimeSpan& ts) const;
1419 // compare two timestamps: works with the absolute values, i.e. 1
68379eaf 1420 // hour is shorter than -2 hours. Also, it will return false if the
0979c962 1421 // timespans are equal in absolute value.
f7541d48 1422 bool IsShorterThan(const wxTimeSpan& t) const;
0979c962 1423
26364344
WS
1424 inline bool operator<(const wxTimeSpan &ts) const
1425 {
1426 return GetValue() < ts.GetValue();
1427 }
1428
1429 inline bool operator<=(const wxTimeSpan &ts) const
1430 {
1431 return GetValue() <= ts.GetValue();
1432 }
1433
1434 inline bool operator>(const wxTimeSpan &ts) const
1435 {
1436 return GetValue() > ts.GetValue();
1437 }
1438
1439 inline bool operator>=(const wxTimeSpan &ts) const
1440 {
1441 return GetValue() >= ts.GetValue();
1442 }
1443
1444 inline bool operator==(const wxTimeSpan &ts) const
1445 {
1446 return GetValue() == ts.GetValue();
1447 }
1448
1449 inline bool operator!=(const wxTimeSpan &ts) const
1450 {
1451 return GetValue() != ts.GetValue();
1452 }
1453
e6ec579c 1454 // breaking into days, hours, minutes and seconds
0979c962
VZ
1455 // ------------------------------------------------------------------------
1456
0979c962
VZ
1457 // get the max number of weeks in this timespan
1458 inline int GetWeeks() const;
1459 // get the max number of days in this timespan
1460 inline int GetDays() const;
1461 // get the max number of hours in this timespan
1462 inline int GetHours() const;
1463 // get the max number of minutes in this timespan
1464 inline int GetMinutes() const;
1465 // get the max number of seconds in this timespan
e6ec579c 1466 inline wxLongLong GetSeconds() const;
0979c962 1467 // get the number of milliseconds in this timespan
b76b015e 1468 wxLongLong GetMilliseconds() const { return m_diff; }
0979c962
VZ
1469
1470 // conversion to text
1471 // ------------------------------------------------------------------------
1472
1473 // this function accepts strftime()-like format string (default
1474 // argument corresponds to the preferred date and time representation
1475 // for the current locale) and returns the string containing the
1476 // resulting text representation. Notice that only some of format
1477 // specifiers valid for wxDateTime are valid for wxTimeSpan: hours,
1478 // minutes and seconds make sense, but not "PM/AM" string for example.
12e82477 1479 wxString Format(const wxString& format = wxDefaultTimeSpanFormat) const;
0979c962
VZ
1480
1481 // implementation
1482 // ------------------------------------------------------------------------
1483
cd0b1709
VZ
1484 // construct from internal representation
1485 wxTimeSpan(const wxLongLong& diff) { m_diff = diff; }
1486
0979c962
VZ
1487 // get the internal representation
1488 wxLongLong GetValue() const { return m_diff; }
1489
1490private:
1491 // the (signed) time span in milliseconds
1492 wxLongLong m_diff;
1493};
1494
1495// ----------------------------------------------------------------------------
1496// This class is a "logical time span" and is useful for implementing program
1497// logic for such things as "add one month to the date" which, in general,
1498// doesn't mean to add 60*60*24*31 seconds to it, but to take the same date
1499// the next month (to understand that this is indeed different consider adding
1500// one month to Feb, 15 - we want to get Mar, 15, of course).
1501//
1502// When adding a month to the date, all lesser components (days, hours, ...)
4f6aed9c
VZ
1503// won't be changed unless the resulting date would be invalid: for example,
1504// Jan 31 + 1 month will be Feb 28, not (non existing) Feb 31.
1505//
f6bcfd97 1506// Because of this feature, adding and subtracting back again the same
4f6aed9c
VZ
1507// wxDateSpan will *not*, in general give back the original date: Feb 28 - 1
1508// month will be Jan 28, not Jan 31!
0979c962
VZ
1509//
1510// wxDateSpan can be either positive or negative. They may be
1511// multiplied by scalars which multiply all deltas by the scalar: i.e. 2*(1
1512// month and 1 day) is 2 months and 2 days. They can be added together and
1513// with wxDateTime or wxTimeSpan, but the type of result is different for each
1514// case.
1515//
1516// Beware about weeks: if you specify both weeks and days, the total number of
1517// days added will be 7*weeks + days! See also GetTotalDays() function.
1518//
93401be9
VZ
1519// Equality operators are defined for wxDateSpans. Two datespans are equal if
1520// they both give the same target date when added to *every* source date.
1521// Thus wxDateSpan::Months(1) is not equal to wxDateSpan::Days(30), because
1522// they not give the same date when added to 1 Feb. But wxDateSpan::Days(14) is
1523// equal to wxDateSpan::Weeks(2)
1524//
0979c962
VZ
1525// Finally, notice that for adding hours, minutes &c you don't need this
1526// class: wxTimeSpan will do the job because there are no subtleties
1527// associated with those.
1528// ----------------------------------------------------------------------------
b76b015e 1529
bddd7a8d 1530class WXDLLIMPEXP_BASE wxDateSpan
0979c962
VZ
1531{
1532public:
1533 // constructors
1534 // ------------------------------------------------------------------------
1535
1536 // this many years/months/weeks/days
2f02cb89
VZ
1537 wxDateSpan(int years = 0, int months = 0, int weeks = 0, int days = 0)
1538 {
1539 m_years = years;
1540 m_months = months;
1541 m_weeks = weeks;
1542 m_days = days;
1543 }
1544
1545 // get an object for the given number of days
1546 static wxDateSpan Days(int days) { return wxDateSpan(0, 0, 0, days); }
68ee7c47 1547 static wxDateSpan Day() { return Days(1); }
2f02cb89
VZ
1548
1549 // get an object for the given number of weeks
1550 static wxDateSpan Weeks(int weeks) { return wxDateSpan(0, 0, weeks, 0); }
68ee7c47 1551 static wxDateSpan Week() { return Weeks(1); }
2f02cb89
VZ
1552
1553 // get an object for the given number of months
1554 static wxDateSpan Months(int mon) { return wxDateSpan(0, mon, 0, 0); }
68ee7c47 1555 static wxDateSpan Month() { return Months(1); }
2f02cb89
VZ
1556
1557 // get an object for the given number of years
1558 static wxDateSpan Years(int years) { return wxDateSpan(years, 0, 0, 0); }
68ee7c47 1559 static wxDateSpan Year() { return Years(1); }
0979c962
VZ
1560
1561 // default copy ctor is ok
1562
1563 // no dtor
1564
1565 // accessors (all SetXXX() return the (modified) wxDateSpan object)
1566 // ------------------------------------------------------------------------
1567
1568 // set number of years
b76b015e 1569 wxDateSpan& SetYears(int n) { m_years = n; return *this; }
0979c962 1570 // set number of months
b76b015e 1571 wxDateSpan& SetMonths(int n) { m_months = n; return *this; }
0979c962 1572 // set number of weeks
b76b015e 1573 wxDateSpan& SetWeeks(int n) { m_weeks = n; return *this; }
0979c962 1574 // set number of days
b76b015e 1575 wxDateSpan& SetDays(int n) { m_days = n; return *this; }
0979c962
VZ
1576
1577 // get number of years
1578 int GetYears() const { return m_years; }
1579 // get number of months
1580 int GetMonths() const { return m_months; }
16630eb7
VZ
1581 // returns 12*GetYears() + GetMonths()
1582 int GetTotalMonths() const { return 12*m_years + m_months; }
0979c962
VZ
1583 // get number of weeks
1584 int GetWeeks() const { return m_weeks; }
1585 // get number of days
1586 int GetDays() const { return m_days; }
1587 // returns 7*GetWeeks() + GetDays()
1588 int GetTotalDays() const { return 7*m_weeks + m_days; }
1589
cd0b1709 1590 // arithmetics with date spans (see also below for more operators)
0979c962
VZ
1591 // ------------------------------------------------------------------------
1592
cd0b1709
VZ
1593 // return sum of two date spans
1594 inline wxDateSpan Add(const wxDateSpan& other) const;
0979c962
VZ
1595 // add another wxDateSpan to us
1596 inline wxDateSpan& Add(const wxDateSpan& other);
1597 // add another wxDateSpan to us
1598 inline wxDateSpan& operator+=(const wxDateSpan& other);
26364344
WS
1599 inline wxDateSpan operator+(const wxDateSpan& ds) const
1600 {
1601 return wxDateSpan(GetYears() + ds.GetYears(),
1602 GetMonths() + ds.GetMonths(),
1603 GetWeeks() + ds.GetWeeks(),
1604 GetDays() + ds.GetDays());
1605 }
0979c962 1606
cd0b1709 1607 // return difference of two date spans
f6bcfd97
BP
1608 inline wxDateSpan Subtract(const wxDateSpan& other) const;
1609 // subtract another wxDateSpan from us
1610 inline wxDateSpan& Subtract(const wxDateSpan& other);
1611 // subtract another wxDateSpan from us
0979c962 1612 inline wxDateSpan& operator-=(const wxDateSpan& other);
26364344
WS
1613 inline wxDateSpan operator-(const wxDateSpan& ds) const
1614 {
1615 return wxDateSpan(GetYears() - ds.GetYears(),
1616 GetMonths() - ds.GetMonths(),
1617 GetWeeks() - ds.GetWeeks(),
1618 GetDays() - ds.GetDays());
1619 }
0979c962
VZ
1620
1621 // return a copy of this time span with changed sign
1622 inline wxDateSpan Negate() const;
1623 // inverse the sign of this timespan
1624 inline wxDateSpan& Neg();
1625 // inverse the sign of this timespan
1626 wxDateSpan& operator-() { return Neg(); }
1627
cd0b1709
VZ
1628 // return the date span proportional to this one with given factor
1629 inline wxDateSpan Multiply(int factor) const;
0979c962 1630 // multiply all components by a (signed) number
cd0b1709
VZ
1631 inline wxDateSpan& Multiply(int factor);
1632 // multiply all components by a (signed) number
1633 inline wxDateSpan& operator*=(int factor) { return Multiply(factor); }
26364344
WS
1634 inline wxDateSpan operator*(int n) const
1635 {
1636 return wxDateSpan(*this).Multiply(n);
1637 }
1638
1639 // ds1 == d2 if and only if for every wxDateTime t t + ds1 == t + ds2
1640 inline bool operator==(const wxDateSpan& ds) const
1641 {
1642 return GetYears() == ds.GetYears() &&
1643 GetMonths() == ds.GetMonths() &&
1644 GetTotalDays() == ds.GetTotalDays();
1645 }
1646
1647 inline bool operator!=(const wxDateSpan& ds) const
1648 {
1649 return !(*this == ds);
1650 }
0979c962
VZ
1651
1652private:
1653 int m_years,
1654 m_months,
1655 m_weeks,
1656 m_days;
1657};
1658
4f6aed9c
VZ
1659// ----------------------------------------------------------------------------
1660// wxDateTimeArray: array of dates.
1661// ----------------------------------------------------------------------------
1662
bb24c68f 1663WX_DECLARE_USER_EXPORTED_OBJARRAY(wxDateTime, wxDateTimeArray, WXDLLIMPEXP_BASE);
4f6aed9c
VZ
1664
1665// ----------------------------------------------------------------------------
1666// wxDateTimeHolidayAuthority: an object of this class will decide whether a
1667// given date is a holiday and is used by all functions working with "work
1668// days".
1669//
1670// NB: the base class is an ABC, derived classes must implement the pure
1671// virtual methods to work with the holidays they correspond to.
1672// ----------------------------------------------------------------------------
1673
b5dbe15d 1674class WXDLLIMPEXP_FWD_BASE wxDateTimeHolidayAuthority;
d5d29b8a 1675WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxDateTimeHolidayAuthority *,
bb24c68f 1676 wxHolidayAuthoritiesArray,
fd497ede 1677 class WXDLLIMPEXP_BASE);
4f6aed9c 1678
f6081a04 1679class wxDateTimeHolidaysModule;
bddd7a8d 1680class WXDLLIMPEXP_BASE wxDateTimeHolidayAuthority
4f6aed9c 1681{
f6bcfd97 1682friend class wxDateTimeHolidaysModule;
4f6aed9c 1683public:
68379eaf 1684 // returns true if the given date is a holiday
4f6aed9c
VZ
1685 static bool IsHoliday(const wxDateTime& dt);
1686
1687 // fills the provided array with all holidays in the given range, returns
1688 // the number of them
1689 static size_t GetHolidaysInRange(const wxDateTime& dtStart,
1690 const wxDateTime& dtEnd,
1691 wxDateTimeArray& holidays);
1692
1693 // clear the list of holiday authorities
1694 static void ClearAllAuthorities();
1695
1696 // add a new holiday authority (the pointer will be deleted by
1697 // wxDateTimeHolidayAuthority)
1698 static void AddAuthority(wxDateTimeHolidayAuthority *auth);
1699
30e671a5 1700 // the base class must have a virtual dtor
5e233068 1701 virtual ~wxDateTimeHolidayAuthority();
30e671a5 1702
4f6aed9c
VZ
1703protected:
1704 // this function is called to determine whether a given day is a holiday
1705 virtual bool DoIsHoliday(const wxDateTime& dt) const = 0;
1706
1707 // this function should fill the array with all holidays between the two
1708 // given dates - it is implemented in the base class, but in a very
1709 // inefficient way (it just iterates over all days and uses IsHoliday() for
1710 // each of them), so it must be overridden in the derived class where the
1711 // base class version may be explicitly used if needed
1712 //
1713 // returns the number of holidays in the given range and fills holidays
1714 // array
1715 virtual size_t DoGetHolidaysInRange(const wxDateTime& dtStart,
1716 const wxDateTime& dtEnd,
1717 wxDateTimeArray& holidays) const = 0;
1718
1719private:
1720 // all holiday authorities
1721 static wxHolidayAuthoritiesArray ms_authorities;
1722};
1723
1724// the holidays for this class are all Saturdays and Sundays
bddd7a8d 1725class WXDLLIMPEXP_BASE wxDateTimeWorkDays : public wxDateTimeHolidayAuthority
4f6aed9c
VZ
1726{
1727protected:
1728 virtual bool DoIsHoliday(const wxDateTime& dt) const;
1729 virtual size_t DoGetHolidaysInRange(const wxDateTime& dtStart,
1730 const wxDateTime& dtEnd,
1731 wxDateTimeArray& holidays) const;
1732};
0979c962 1733
2f02cb89
VZ
1734// ============================================================================
1735// inline functions implementation
1736// ============================================================================
1737
df5168c4
MB
1738// ----------------------------------------------------------------------------
1739// private macros
1740// ----------------------------------------------------------------------------
1741
1742#define MILLISECONDS_PER_DAY 86400000l
1743
1744// some broken compilers (HP-UX CC) refuse to compile the "normal" version, but
1745// using a temp variable always might prevent other compilers from optimising
1746// it away - hence use of this ugly macro
1747#ifndef __HPUX__
1748 #define MODIFY_AND_RETURN(op) return wxDateTime(*this).op
1749#else
1750 #define MODIFY_AND_RETURN(op) wxDateTime dt(*this); dt.op; return dt
1751#endif
1752
1753// ----------------------------------------------------------------------------
1754// wxDateTime construction
1755// ----------------------------------------------------------------------------
1756
1757inline bool wxDateTime::IsInStdRange() const
1758{
57563c71
VZ
1759 // currently we don't know what is the real type of time_t so prefer to err
1760 // on the safe side and limit it to 32 bit values which is safe everywhere
1761 return m_time >= 0l && (m_time / TIME_T_FACTOR) < wxINT32_MAX;
df5168c4 1762}
2f02cb89 1763
df5168c4
MB
1764/* static */
1765inline wxDateTime wxDateTime::Now()
1766{
a452689b
SN
1767 struct tm tmstruct;
1768 return wxDateTime(*GetTmNow(&tmstruct));
df5168c4
MB
1769}
1770
1771/* static */
1772inline wxDateTime wxDateTime::Today()
1773{
cb1ef833
VZ
1774 wxDateTime dt(Now());
1775 dt.ResetTime();
df5168c4 1776
cb1ef833 1777 return dt;
df5168c4
MB
1778}
1779
1780#if (!(defined(__VISAGECPP__) && __IBMCPP__ >= 400))
1781inline wxDateTime& wxDateTime::Set(time_t timet)
1782{
d2a02746
VZ
1783 if ( timet == (time_t)-1 )
1784 {
1785 m_time = wxInvalidDateTime.m_time;
1786 }
1787 else
1788 {
1789 // assign first to avoid long multiplication overflow!
1790 m_time = timet - WX_TIME_BASE_OFFSET;
1791 m_time *= TIME_T_FACTOR;
1792 }
df5168c4
MB
1793
1794 return *this;
1795}
2f02cb89
VZ
1796#endif
1797
df5168c4
MB
1798inline wxDateTime& wxDateTime::SetToCurrent()
1799{
1800 *this = Now();
1801 return *this;
1802}
1803
1804#if (!(defined(__VISAGECPP__) && __IBMCPP__ >= 400))
1805inline wxDateTime::wxDateTime(time_t timet)
1806{
1807 Set(timet);
1808}
dc84437e 1809#endif
2f02cb89 1810
df5168c4
MB
1811inline wxDateTime::wxDateTime(const struct tm& tm)
1812{
1813 Set(tm);
1814}
1815
1816inline wxDateTime::wxDateTime(const Tm& tm)
1817{
1818 Set(tm);
1819}
1820
1821inline wxDateTime::wxDateTime(double jdn)
1822{
1823 Set(jdn);
1824}
1825
1826inline wxDateTime& wxDateTime::Set(const Tm& tm)
1827{
9a83f860 1828 wxASSERT_MSG( tm.IsValid(), wxT("invalid broken down date/time") );
df5168c4 1829
271f6072
VZ
1830 return Set(tm.mday, (Month)tm.mon, tm.year,
1831 tm.hour, tm.min, tm.sec, tm.msec);
df5168c4
MB
1832}
1833
1834inline wxDateTime::wxDateTime(wxDateTime_t hour,
1835 wxDateTime_t minute,
1836 wxDateTime_t second,
1837 wxDateTime_t millisec)
1838{
1839 Set(hour, minute, second, millisec);
1840}
1841
1842inline wxDateTime::wxDateTime(wxDateTime_t day,
1843 Month month,
1844 int year,
1845 wxDateTime_t hour,
1846 wxDateTime_t minute,
1847 wxDateTime_t second,
1848 wxDateTime_t millisec)
1849{
1850 Set(day, month, year, hour, minute, second, millisec);
1851}
1852
1853// ----------------------------------------------------------------------------
1854// wxDateTime accessors
1855// ----------------------------------------------------------------------------
1856
1857inline wxLongLong wxDateTime::GetValue() const
1858{
9a83f860 1859 wxASSERT_MSG( IsValid(), wxT("invalid wxDateTime"));
df5168c4
MB
1860
1861 return m_time;
1862}
1863
1864inline time_t wxDateTime::GetTicks() const
1865{
9a83f860 1866 wxASSERT_MSG( IsValid(), wxT("invalid wxDateTime"));
df5168c4
MB
1867 if ( !IsInStdRange() )
1868 {
1869 return (time_t)-1;
1870 }
1871
d3c58c7e 1872 return (time_t)((m_time / (long)TIME_T_FACTOR).ToLong()) + WX_TIME_BASE_OFFSET;
df5168c4
MB
1873}
1874
1875inline bool wxDateTime::SetToLastWeekDay(WeekDay weekday,
1876 Month month,
1877 int year)
1878{
1879 return SetToWeekDay(weekday, -1, month, year);
1880}
1881
fc7a2a60
VZ
1882inline wxDateTime
1883wxDateTime::GetWeekDayInSameWeek(WeekDay weekday,
1884 WeekFlags WXUNUSED(flags)) const
df5168c4
MB
1885{
1886 MODIFY_AND_RETURN( SetToWeekDayInSameWeek(weekday) );
1887}
1888
1889inline wxDateTime wxDateTime::GetNextWeekDay(WeekDay weekday) const
1890{
1891 MODIFY_AND_RETURN( SetToNextWeekDay(weekday) );
1892}
1893
1894inline wxDateTime wxDateTime::GetPrevWeekDay(WeekDay weekday) const
1895{
1896 MODIFY_AND_RETURN( SetToPrevWeekDay(weekday) );
1897}
1898
1899inline wxDateTime wxDateTime::GetWeekDay(WeekDay weekday,
1900 int n,
1901 Month month,
1902 int year) const
1903{
1904 wxDateTime dt(*this);
1905
1906 return dt.SetToWeekDay(weekday, n, month, year) ? dt : wxInvalidDateTime;
1907}
1908
1909inline wxDateTime wxDateTime::GetLastWeekDay(WeekDay weekday,
1910 Month month,
1911 int year)
1912{
1913 wxDateTime dt(*this);
1914
1915 return dt.SetToLastWeekDay(weekday, month, year) ? dt : wxInvalidDateTime;
1916}
1917
df5168c4
MB
1918inline wxDateTime wxDateTime::GetLastMonthDay(Month month, int year) const
1919{
1920 MODIFY_AND_RETURN( SetToLastMonthDay(month, year) );
1921}
1922
1923inline wxDateTime wxDateTime::GetYearDay(wxDateTime_t yday) const
1924{
1925 MODIFY_AND_RETURN( SetToYearDay(yday) );
1926}
1927
1928// ----------------------------------------------------------------------------
1929// wxDateTime comparison
1930// ----------------------------------------------------------------------------
1931
1932inline bool wxDateTime::IsEqualTo(const wxDateTime& datetime) const
1933{
9a83f860 1934 wxASSERT_MSG( IsValid() && datetime.IsValid(), wxT("invalid wxDateTime"));
df5168c4
MB
1935
1936 return m_time == datetime.m_time;
1937}
1938
1939inline bool wxDateTime::IsEarlierThan(const wxDateTime& datetime) const
1940{
9a83f860 1941 wxASSERT_MSG( IsValid() && datetime.IsValid(), wxT("invalid wxDateTime"));
df5168c4
MB
1942
1943 return m_time < datetime.m_time;
1944}
1945
1946inline bool wxDateTime::IsLaterThan(const wxDateTime& datetime) const
1947{
9a83f860 1948 wxASSERT_MSG( IsValid() && datetime.IsValid(), wxT("invalid wxDateTime"));
df5168c4
MB
1949
1950 return m_time > datetime.m_time;
1951}
1952
1953inline bool wxDateTime::IsStrictlyBetween(const wxDateTime& t1,
1954 const wxDateTime& t2) const
1955{
1956 // no need for assert, will be checked by the functions we call
1957 return IsLaterThan(t1) && IsEarlierThan(t2);
1958}
1959
1960inline bool wxDateTime::IsBetween(const wxDateTime& t1,
1961 const wxDateTime& t2) const
1962{
1963 // no need for assert, will be checked by the functions we call
1964 return IsEqualTo(t1) || IsEqualTo(t2) || IsStrictlyBetween(t1, t2);
1965}
1966
1967inline bool wxDateTime::IsSameDate(const wxDateTime& dt) const
1968{
1969 Tm tm1 = GetTm(),
1970 tm2 = dt.GetTm();
1971
1972 return tm1.year == tm2.year &&
1973 tm1.mon == tm2.mon &&
1974 tm1.mday == tm2.mday;
1975}
1976
1977inline bool wxDateTime::IsSameTime(const wxDateTime& dt) const
1978{
1979 // notice that we can't do something like this:
1980 //
1981 // m_time % MILLISECONDS_PER_DAY == dt.m_time % MILLISECONDS_PER_DAY
1982 //
1983 // because we have also to deal with (possibly) different DST settings!
1984 Tm tm1 = GetTm(),
1985 tm2 = dt.GetTm();
1986
1987 return tm1.hour == tm2.hour &&
1988 tm1.min == tm2.min &&
1989 tm1.sec == tm2.sec &&
1990 tm1.msec == tm2.msec;
1991}
1992
1993inline bool wxDateTime::IsEqualUpTo(const wxDateTime& dt,
1994 const wxTimeSpan& ts) const
1995{
1996 return IsBetween(dt.Subtract(ts), dt.Add(ts));
1997}
1998
1999// ----------------------------------------------------------------------------
2000// wxDateTime arithmetics
2001// ----------------------------------------------------------------------------
2002
2003inline wxDateTime wxDateTime::Add(const wxTimeSpan& diff) const
2004{
9a83f860 2005 wxASSERT_MSG( IsValid(), wxT("invalid wxDateTime"));
df5168c4
MB
2006
2007 return wxDateTime(m_time + diff.GetValue());
2008}
2009
2010inline wxDateTime& wxDateTime::Add(const wxTimeSpan& diff)
2011{
9a83f860 2012 wxASSERT_MSG( IsValid(), wxT("invalid wxDateTime"));
df5168c4
MB
2013
2014 m_time += diff.GetValue();
2015
2016 return *this;
2017}
2018
2019inline wxDateTime& wxDateTime::operator+=(const wxTimeSpan& diff)
2020{
2021 return Add(diff);
2022}
2023
2024inline wxDateTime wxDateTime::Subtract(const wxTimeSpan& diff) const
2025{
9a83f860 2026 wxASSERT_MSG( IsValid(), wxT("invalid wxDateTime"));
df5168c4
MB
2027
2028 return wxDateTime(m_time - diff.GetValue());
2029}
2030
2031inline wxDateTime& wxDateTime::Subtract(const wxTimeSpan& diff)
2032{
9a83f860 2033 wxASSERT_MSG( IsValid(), wxT("invalid wxDateTime"));
df5168c4
MB
2034
2035 m_time -= diff.GetValue();
2036
2037 return *this;
2038}
2039
2040inline wxDateTime& wxDateTime::operator-=(const wxTimeSpan& diff)
2041{
2042 return Subtract(diff);
2043}
2044
2045inline wxTimeSpan wxDateTime::Subtract(const wxDateTime& datetime) const
2046{
9a83f860 2047 wxASSERT_MSG( IsValid() && datetime.IsValid(), wxT("invalid wxDateTime"));
df5168c4
MB
2048
2049 return wxTimeSpan(GetValue() - datetime.GetValue());
2050}
2051
26364344
WS
2052inline wxTimeSpan wxDateTime::operator-(const wxDateTime& dt2) const
2053{
2054 return this->Subtract(dt2);
2055}
2056
df5168c4
MB
2057inline wxDateTime wxDateTime::Add(const wxDateSpan& diff) const
2058{
2059 return wxDateTime(*this).Add(diff);
2060}
2061
2062inline wxDateTime& wxDateTime::Subtract(const wxDateSpan& diff)
2063{
2064 return Add(diff.Negate());
2065}
2066
2067inline wxDateTime wxDateTime::Subtract(const wxDateSpan& diff) const
2068{
2069 return wxDateTime(*this).Subtract(diff);
2070}
2071
2072inline wxDateTime& wxDateTime::operator-=(const wxDateSpan& diff)
2073{
2074 return Subtract(diff);
2075}
2076
2077inline wxDateTime& wxDateTime::operator+=(const wxDateSpan& diff)
2078{
2079 return Add(diff);
2080}
2081
2082// ----------------------------------------------------------------------------
2083// wxDateTime and timezones
2084// ----------------------------------------------------------------------------
2085
d26adb9d
VZ
2086inline wxDateTime
2087wxDateTime::ToTimezone(const wxDateTime::TimeZone& tz, bool noDST) const
df5168c4
MB
2088{
2089 MODIFY_AND_RETURN( MakeTimezone(tz, noDST) );
2090}
2091
d26adb9d
VZ
2092inline wxDateTime
2093wxDateTime::FromTimezone(const wxDateTime::TimeZone& tz, bool noDST) const
2094{
2095 MODIFY_AND_RETURN( MakeFromTimezone(tz, noDST) );
2096}
2097
df5168c4
MB
2098// ----------------------------------------------------------------------------
2099// wxTimeSpan construction
2100// ----------------------------------------------------------------------------
2101
2102inline wxTimeSpan::wxTimeSpan(long hours,
2103 long minutes,
9c21e80b
VZ
2104 wxLongLong seconds,
2105 wxLongLong milliseconds)
df5168c4
MB
2106{
2107 // assign first to avoid precision loss
2108 m_diff = hours;
2109 m_diff *= 60l;
2110 m_diff += minutes;
2111 m_diff *= 60l;
2112 m_diff += seconds;
2113 m_diff *= 1000l;
2114 m_diff += milliseconds;
2115}
2116
2117// ----------------------------------------------------------------------------
2118// wxTimeSpan accessors
2119// ----------------------------------------------------------------------------
2120
2121inline wxLongLong wxTimeSpan::GetSeconds() const
2122{
2123 return m_diff / 1000l;
2124}
2125
2126inline int wxTimeSpan::GetMinutes() const
2127{
2415cf67
VZ
2128 // For compatibility, this method (and the other accessors) return int,
2129 // even though GetLo() actually returns unsigned long with greater range.
2130 return static_cast<int>((GetSeconds() / 60l).GetLo());
df5168c4
MB
2131}
2132
2133inline int wxTimeSpan::GetHours() const
2134{
2135 return GetMinutes() / 60;
2136}
2137
2138inline int wxTimeSpan::GetDays() const
2139{
2140 return GetHours() / 24;
2141}
2142
2143inline int wxTimeSpan::GetWeeks() const
2144{
2145 return GetDays() / 7;
2146}
2147
2148// ----------------------------------------------------------------------------
2149// wxTimeSpan arithmetics
2150// ----------------------------------------------------------------------------
2151
2152inline wxTimeSpan wxTimeSpan::Add(const wxTimeSpan& diff) const
2153{
2154 return wxTimeSpan(m_diff + diff.GetValue());
2155}
2156
2157inline wxTimeSpan& wxTimeSpan::Add(const wxTimeSpan& diff)
2158{
2159 m_diff += diff.GetValue();
2160
2161 return *this;
2162}
2163
2164inline wxTimeSpan wxTimeSpan::Subtract(const wxTimeSpan& diff) const
2165{
2166 return wxTimeSpan(m_diff - diff.GetValue());
2167}
2168
2169inline wxTimeSpan& wxTimeSpan::Subtract(const wxTimeSpan& diff)
2170{
2171 m_diff -= diff.GetValue();
2172
2173 return *this;
2174}
2175
2176inline wxTimeSpan& wxTimeSpan::Multiply(int n)
2177{
2178 m_diff *= (long)n;
2179
2180 return *this;
2181}
2182
2183inline wxTimeSpan wxTimeSpan::Multiply(int n) const
2184{
2185 return wxTimeSpan(m_diff * (long)n);
2186}
2187
2188inline wxTimeSpan wxTimeSpan::Abs() const
2189{
2190 return wxTimeSpan(GetValue().Abs());
2191}
2192
2193inline bool wxTimeSpan::IsEqualTo(const wxTimeSpan& ts) const
2194{
2195 return GetValue() == ts.GetValue();
2196}
2197
2198inline bool wxTimeSpan::IsLongerThan(const wxTimeSpan& ts) const
2199{
2200 return GetValue().Abs() > ts.GetValue().Abs();
f7541d48
VZ
2201}
2202
2203inline bool wxTimeSpan::IsShorterThan(const wxTimeSpan& ts) const
2204{
2205 return GetValue().Abs() < ts.GetValue().Abs();
df5168c4
MB
2206}
2207
2208// ----------------------------------------------------------------------------
2209// wxDateSpan
2210// ----------------------------------------------------------------------------
2211
2212inline wxDateSpan& wxDateSpan::operator+=(const wxDateSpan& other)
2213{
2214 m_years += other.m_years;
2215 m_months += other.m_months;
2216 m_weeks += other.m_weeks;
2217 m_days += other.m_days;
2218
2219 return *this;
2220}
2221
2222inline wxDateSpan& wxDateSpan::Add(const wxDateSpan& other)
2223{
2224 return *this += other;
2225}
2226
2227inline wxDateSpan wxDateSpan::Add(const wxDateSpan& other) const
2228{
2229 wxDateSpan ds(*this);
2230 ds.Add(other);
2231 return ds;
2232}
2233
2234inline wxDateSpan& wxDateSpan::Multiply(int factor)
2235{
2236 m_years *= factor;
2237 m_months *= factor;
2238 m_weeks *= factor;
2239 m_days *= factor;
2240
2241 return *this;
2242}
2243
2244inline wxDateSpan wxDateSpan::Multiply(int factor) const
2245{
2246 wxDateSpan ds(*this);
2247 ds.Multiply(factor);
2248 return ds;
2249}
2250
2251inline wxDateSpan wxDateSpan::Negate() const
2252{
2253 return wxDateSpan(-m_years, -m_months, -m_weeks, -m_days);
2254}
2255
2256inline wxDateSpan& wxDateSpan::Neg()
2257{
2258 m_years = -m_years;
2259 m_months = -m_months;
2260 m_weeks = -m_weeks;
2261 m_days = -m_days;
2262
2263 return *this;
2264}
2265
2266inline wxDateSpan& wxDateSpan::operator-=(const wxDateSpan& other)
2267{
2268 return *this += other.Negate();
2269}
2270
2271inline wxDateSpan& wxDateSpan::Subtract(const wxDateSpan& other)
2272{
2273 return *this -= other;
2274}
2275
2276inline wxDateSpan wxDateSpan::Subtract(const wxDateSpan& other) const
2277{
2278 wxDateSpan ds(*this);
2279 ds.Subtract(other);
2280 return ds;
2281}
2282
2283#undef MILLISECONDS_PER_DAY
2284
2285#undef MODIFY_AND_RETURN
2286
0979c962
VZ
2287// ============================================================================
2288// binary operators
2289// ============================================================================
2290
0979c962
VZ
2291// ----------------------------------------------------------------------------
2292// wxTimeSpan operators
2293// ----------------------------------------------------------------------------
2294
26364344 2295wxTimeSpan WXDLLIMPEXP_BASE operator*(int n, const wxTimeSpan& ts);
0979c962
VZ
2296
2297// ----------------------------------------------------------------------------
2298// wxDateSpan
2299// ----------------------------------------------------------------------------
2300
26364344 2301wxDateSpan WXDLLIMPEXP_BASE operator*(int n, const wxDateSpan& ds);
cd0b1709
VZ
2302
2303// ============================================================================
2304// other helper functions
2305// ============================================================================
2306
2307// ----------------------------------------------------------------------------
2308// iteration helpers: can be used to write a for loop over enum variable like
2309// this:
2310// for ( m = wxDateTime::Jan; m < wxDateTime::Inv_Month; wxNextMonth(m) )
2311// ----------------------------------------------------------------------------
2312
26364344
WS
2313WXDLLIMPEXP_BASE void wxNextMonth(wxDateTime::Month& m);
2314WXDLLIMPEXP_BASE void wxPrevMonth(wxDateTime::Month& m);
2315WXDLLIMPEXP_BASE void wxNextWDay(wxDateTime::WeekDay& wd);
2316WXDLLIMPEXP_BASE void wxPrevWDay(wxDateTime::WeekDay& wd);
0979c962 2317
e421922f
VZ
2318#endif // wxUSE_DATETIME
2319
2f02cb89 2320#endif // _WX_DATETIME_H