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