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