]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/src/utils.i
Reorganized listctrl demo a bit so I can test a bug report
[wxWidgets.git] / wxPython / src / utils.i
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: utils.i
3// Purpose: SWIG definitions of various utility classes
4//
5// Author: Robin Dunn
6//
7// Created: 25-Nov-1998
8// RCS-ID: $Id$
9// Copyright: (c) 1998 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13
14%module utils
15
16%{
17#include "helpers.h"
18#include <wx/config.h>
19#include <wx/fileconf.h>
20#include <wx/datetime.h>
21%}
22
23//---------------------------------------------------------------------------
24%{
25 // Put some wx default wxChar* values into wxStrings.
26 DECLARE_DEF_STRING2(DateFormatStr, wxT("%c"));
27 static const wxString wxPyEmptyString(wxT(""));
28
29%}
30//---------------------------------------------------------------------------
31
32%include typemaps.i
33%include my_typemaps.i
34
35// Import some definitions of other classes, etc.
36%import _defs.i
37
38%pragma(python) code = "import string"
39
40
41//---------------------------------------------------------------------------
42
43%{
44 static PyObject* __EnumerationHelper(bool flag, wxString& str, long index) {
45 PyObject* ret = PyTuple_New(3);
46 if (ret) {
47 PyTuple_SET_ITEM(ret, 0, PyInt_FromLong(flag));
48#if wxUSE_UNICODE
49 PyTuple_SET_ITEM(ret, 1, PyUnicode_FromUnicode(str.c_str(), str.Len()));
50#else
51 PyTuple_SET_ITEM(ret, 1, PyString_FromStringAndSize(str.c_str(), str.Len()));
52#endif
53 PyTuple_SET_ITEM(ret, 2, PyInt_FromLong(index));
54 }
55 return ret;
56 }
57%}
58
59//---------------------------------------------------------------------------
60
61enum
62{
63 wxCONFIG_USE_LOCAL_FILE = 1,
64 wxCONFIG_USE_GLOBAL_FILE = 2,
65 wxCONFIG_USE_RELATIVE_PATH = 4
66};
67
68//---------------------------------------------------------------------------
69
70class wxConfigBase {
71public:
72// wxConfigBase(const wxString& appName = wxPyEmptyString, **** An ABC
73// const wxString& vendorName = wxPyEmptyString,
74// const wxString& localFilename = wxPyEmptyString,
75// const wxString& globalFilename = wxPyEmptyString,
76// long style = 0);
77 ~wxConfigBase();
78
79 enum EntryType
80 {
81 Type_Unknown,
82 Type_String,
83 Type_Boolean,
84 Type_Integer, // use Read(long *)
85 Type_Float // use Read(double *)
86 };
87
88 // static functions
89 // sets the config object, returns the previous pointer
90 static wxConfigBase *Set(wxConfigBase *pConfig);
91 // get the config object, creates it on demand unless DontCreateOnDemand
92 // was called
93 static wxConfigBase *Get(bool createOnDemand = TRUE);
94 // create a new config object: this function will create the "best"
95 // implementation of wxConfig available for the current platform, see
96 // comments near definition wxUSE_CONFIG_NATIVE for details. It returns
97 // the created object and also sets it as ms_pConfig.
98 static wxConfigBase *Create();
99 // should Get() try to create a new log object if the current one is NULL?
100 static void DontCreateOnDemand();
101
102
103
104 bool DeleteAll(); // This is supposed to have been fixed...
105 bool DeleteEntry(const wxString& key, bool bDeleteGroupIfEmpty = TRUE);
106 bool DeleteGroup(const wxString& key);
107 bool Exists(wxString& strName);
108 bool Flush(bool bCurrentOnly = FALSE);
109 wxString GetAppName();
110
111
112 // Each of these enumeration methods return a 3-tuple consisting of
113 // the continue flag, the value string, and the index for the next call.
114 %addmethods {
115 PyObject* GetFirstGroup() {
116 bool cont;
117 long index = 0;
118 wxString value;
119
120 cont = self->GetFirstGroup(value, index);
121 return __EnumerationHelper(cont, value, index);
122 }
123
124 PyObject* GetFirstEntry() {
125 bool cont;
126 long index = 0;
127 wxString value;
128
129 cont = self->GetFirstEntry(value, index);
130 return __EnumerationHelper(cont, value, index);
131 }
132
133 PyObject* GetNextGroup(long index) {
134 bool cont;
135 wxString value;
136
137 cont = self->GetNextGroup(value, index);
138 return __EnumerationHelper(cont, value, index);
139 }
140
141 PyObject* GetNextEntry(long index) {
142 bool cont;
143 wxString value;
144
145 cont = self->GetNextEntry(value, index);
146 return __EnumerationHelper(cont, value, index);
147 }
148 }
149
150
151 int GetNumberOfEntries(bool bRecursive = FALSE);
152 int GetNumberOfGroups(bool bRecursive = FALSE);
153 wxString GetPath();
154 wxString GetVendorName();
155 bool HasEntry(wxString& strName);
156 bool HasGroup(const wxString& strName);
157 bool IsExpandingEnvVars();
158 bool IsRecordingDefaults();
159
160 wxString Read(const wxString& key, const wxString& defaultVal = wxPyEmptyString);
161
162 %addmethods {
163 long ReadInt(const wxString& key, long defaultVal = 0) {
164 long rv;
165 self->Read(key, &rv, defaultVal);
166 return rv;
167 }
168 double ReadFloat(const wxString& key, double defaultVal = 0.0) {
169 double rv;
170 self->Read(key, &rv, defaultVal);
171 return rv;
172 }
173 bool ReadBool(const wxString& key, bool defaultVal = FALSE) {
174 bool rv;
175 self->Read(key, &rv, defaultVal);
176 return rv;
177 }
178 }
179
180 void SetExpandEnvVars (bool bDoIt = TRUE);
181 void SetPath(const wxString& strPath);
182 void SetRecordDefaults(bool bDoIt = TRUE);
183 void SetAppName(const wxString& appName);
184 void SetVendorName(const wxString& vendorName);
185
186 void SetStyle(long style);
187 long GetStyle();
188
189 bool Write(const wxString& key, const wxString& value);
190 %name(WriteInt)bool Write(const wxString& key, long value);
191 %name(WriteFloat)bool Write(const wxString& key, double value);
192 %name(WriteBool)bool Write(const wxString& key, bool value);
193
194 EntryType GetEntryType(const wxString& name);
195 bool RenameEntry(const wxString& oldName,
196 const wxString& newName);
197 bool RenameGroup(const wxString& oldName,
198 const wxString& newName);
199 wxString ExpandEnvVars(const wxString& str);
200
201
202};
203
204
205//---------------------------------------------------------------------------
206
207// This will be a wxRegConfig on Win32 and wxFileConfig otherwise.
208class wxConfig : public wxConfigBase {
209public:
210 wxConfig(const wxString& appName = wxPyEmptyString,
211 const wxString& vendorName = wxPyEmptyString,
212 const wxString& localFilename = wxPyEmptyString,
213 const wxString& globalFilename = wxPyEmptyString,
214 long style = 0);
215 ~wxConfig();
216};
217
218
219// Sometimes it's nice to explicitly have a wxFileConfig too.
220class wxFileConfig : public wxConfigBase {
221public:
222 wxFileConfig(const wxString& appName = wxPyEmptyString,
223 const wxString& vendorName = wxPyEmptyString,
224 const wxString& localFilename = wxPyEmptyString,
225 const wxString& globalFilename = wxPyEmptyString,
226 long style = 0);
227 ~wxFileConfig();
228};
229
230
231//---------------------------------------------------------------------------
232//---------------------------------------------------------------------------
233
234class wxDateTime;
235class wxTimeSpan;
236class wxDateSpan;
237
238
239%typemap(python,in) wxDateTime::TimeZone& {
240 $target = new wxDateTime::TimeZone((wxDateTime::TZ)PyInt_AsLong($source));
241}
242%typemap(python,freearg) wxDateTime::TimeZone& {
243 if ($source) delete $source;
244}
245
246%{
247#define LOCAL *(new wxDateTime::TimeZone(wxDateTime::Local))
248%}
249
250
251%typemap(python, out) wxLongLong {
252 PyObject *hi, *lo, *shifter, *shifted;
253 hi = PyLong_FromLong($source->GetHi());
254 lo = PyLong_FromLong($source->GetLo());
255 shifter = PyLong_FromLong(32);
256 shifted = PyNumber_Lshift(hi, shifter);
257 $target = PyNumber_Or(shifted, lo);
258 Py_DECREF(hi);
259 Py_DECREF(lo);
260 Py_DECREF(shifter);
261 Py_DECREF(shifted);
262}
263
264
265
266
267class wxDateTime {
268public:
269 typedef unsigned short wxDateTime_t;
270
271 enum TZ
272 {
273 Local,
274
275 GMT_12, GMT_11, GMT_10, GMT_9, GMT_8, GMT_7,
276 GMT_6, GMT_5, GMT_4, GMT_3, GMT_2, GMT_1,
277 GMT0,
278 GMT1, GMT2, GMT3, GMT4, GMT5, GMT6,
279 GMT7, GMT8, GMT9, GMT10, GMT11, GMT12,
280
281 // Europe
282 WET = GMT0, // Western Europe Time
283 WEST = GMT1, // Western Europe Summer Time
284 CET = GMT1, // Central Europe Time
285 CEST = GMT2, // Central Europe Summer Time
286 EET = GMT2, // Eastern Europe Time
287 EEST = GMT3, // Eastern Europe Summer Time
288 MSK = GMT3, // Moscow Time
289 MSD = GMT4, // Moscow Summer Time
290
291 // US and Canada
292 AST = GMT_4, // Atlantic Standard Time
293 ADT = GMT_3, // Atlantic Daylight Time
294 EST = GMT_5, // Eastern Standard Time
295 EDT = GMT_4, // Eastern Daylight Saving Time
296 CST = GMT_6, // Central Standard Time
297 CDT = GMT_5, // Central Daylight Saving Time
298 MST = GMT_7, // Mountain Standard Time
299 MDT = GMT_6, // Mountain Daylight Saving Time
300 PST = GMT_8, // Pacific Standard Time
301 PDT = GMT_7, // Pacific Daylight Saving Time
302 HST = GMT_10, // Hawaiian Standard Time
303 AKST = GMT_9, // Alaska Standard Time
304 AKDT = GMT_8, // Alaska Daylight Saving Time
305
306 // Australia
307
308 A_WST = GMT8, // Western Standard Time
309 A_CST = GMT12 + 1, // Central Standard Time (+9.5)
310 A_EST = GMT10, // Eastern Standard Time
311 A_ESST = GMT11, // Eastern Summer Time
312
313 // Universal Coordinated Time = the new and politically correct name
314 // for GMT
315 UTC = GMT0
316 };
317
318 enum Calendar
319 {
320 Gregorian, // current calendar
321 Julian // calendar in use since -45 until the 1582 (or later)
322 };
323
324 enum Country
325 {
326 Country_Unknown, // no special information for this country
327 Country_Default, // set the default country with SetCountry() method
328 // or use the default country with any other
329
330 // Western European countries: we assume that they all follow the same
331 // DST rules (true or false?)
332 Country_WesternEurope_Start,
333 Country_EEC = Country_WesternEurope_Start,
334 France,
335 Germany,
336 UK,
337 Country_WesternEurope_End = UK,
338
339 Russia,
340
341 USA
342 };
343
344 // symbolic names for the months
345 enum Month
346 {
347 Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec, Inv_Month
348 };
349
350 // symbolic names for the weekdays
351 enum WeekDay
352 {
353 Sun, Mon, Tue, Wed, Thu, Fri, Sat, Inv_WeekDay
354 };
355
356 // invalid value for the year
357 enum Year
358 {
359 Inv_Year = SHRT_MIN // should hold in wxDateTime_t
360 };
361
362 // flags for GetWeekDayName and GetMonthName
363 enum NameFlags
364 {
365 Name_Full = 0x01, // return full name
366 Name_Abbr = 0x02 // return abbreviated name
367 };
368
369 // flags for GetWeekOfYear and GetWeekOfMonth
370 enum WeekFlags
371 {
372 Default_First, // Sunday_First for US, Monday_First for the rest
373 Monday_First, // week starts with a Monday
374 Sunday_First // week starts with a Sunday
375 };
376
377
378 // static methods
379 // ------------------------------------------------------------------------
380
381 // set the current country
382 static void SetCountry(Country country);
383 // get the current country
384 static Country GetCountry();
385
386 // return TRUE if the country is a West European one (in practice,
387 // this means that the same DST rules as for EEC apply)
388 static bool IsWestEuropeanCountry(Country country = Country_Default);
389
390 // return the current year
391 static int GetCurrentYear(Calendar cal = Gregorian);
392
393 // convert the year as returned by wxDateTime::GetYear() to a year
394 // suitable for BC/AD notation. The difference is that BC year 1
395 // corresponds to the year 0 (while BC year 0 didn't exist) and AD
396 // year N is just year N.
397 static int ConvertYearToBC(int year);
398
399 // return the current month
400 static Month GetCurrentMonth(Calendar cal = Gregorian);
401
402 // returns TRUE if the given year is a leap year in the given calendar
403 static bool IsLeapYear(int year = Inv_Year, Calendar cal = Gregorian);
404
405 // get the century (19 for 1999, 20 for 2000 and -5 for 492 BC)
406 static int GetCentury(int year = Inv_Year);
407
408 // returns the number of days in this year (356 or 355 for Gregorian
409 // calendar usually :-)
410 %name(GetNumberOfDaysinYear)
411 static wxDateTime_t GetNumberOfDays(int year, Calendar cal = Gregorian);
412
413 // get the number of the days in the given month (default value for
414 // the year means the current one)
415 %name(GetNumberOfDaysInMonth)
416 static wxDateTime_t GetNumberOfDays(Month month,
417 int year = Inv_Year,
418 Calendar cal = Gregorian);
419
420 // get the full (default) or abbreviated month name in the current
421 // locale, returns empty string on error
422 static wxString GetMonthName(Month month,
423 NameFlags flags = Name_Full);
424
425 // get the full (default) or abbreviated weekday name in the current
426 // locale, returns empty string on error
427 static wxString GetWeekDayName(WeekDay weekday,
428 NameFlags flags = Name_Full);
429
430 // get the AM and PM strings in the current locale (may be empty)
431 static void GetAmPmStrings(wxString *OUTPUT, wxString *OUTPUT);
432
433 // return TRUE if the given country uses DST for this year
434 static bool IsDSTApplicable(int year = Inv_Year,
435 Country country = Country_Default);
436
437 // get the beginning of DST for this year, will return invalid object
438 // if no DST applicable in this year. The default value of the
439 // parameter means to take the current year.
440 static wxDateTime GetBeginDST(int year = Inv_Year,
441 Country country = Country_Default);
442 // get the end of DST for this year, will return invalid object
443 // if no DST applicable in this year. The default value of the
444 // parameter means to take the current year.
445 static wxDateTime GetEndDST(int year = Inv_Year,
446 Country country = Country_Default);
447
448 // return the wxDateTime object for the current time
449 static inline wxDateTime Now();
450
451 // return the wxDateTime object for today midnight: i.e. as Now() but
452 // with time set to 0
453 static inline wxDateTime Today();
454
455
456
457 // ------------------------------------------------------------------------
458 // constructors
459
460 wxDateTime();
461 %name(wxDateTimeFromTimeT)wxDateTime(time_t timet);
462 %name(wxDateTimeFromJDN)wxDateTime(double jdn);
463 %name(wxDateTimeFromHMS)wxDateTime(wxDateTime_t hour,
464 wxDateTime_t minute = 0,
465 wxDateTime_t second = 0,
466 wxDateTime_t millisec = 0);
467 %name(wxDateTimeFromDMY)wxDateTime(wxDateTime_t day,
468 Month month = Inv_Month,
469 int year = Inv_Year,
470 wxDateTime_t hour = 0,
471 wxDateTime_t minute = 0,
472 wxDateTime_t second = 0,
473 wxDateTime_t millisec = 0);
474
475 ~wxDateTime();
476
477 // ------------------------------------------------------------------------
478 // Set methods
479
480 wxDateTime& SetToCurrent();
481
482 // set to given time_t value
483 %name(SetTimeT)wxDateTime& Set(time_t timet);
484
485 // set to given JDN (beware of rounding errors)
486 %name(SetJDN)wxDateTime& Set(double jdn);
487
488 // set to given time, date = today
489 %name(SetHMS)wxDateTime& Set(wxDateTime_t hour,
490 wxDateTime_t minute = 0,
491 wxDateTime_t second = 0,
492 wxDateTime_t millisec = 0);
493
494 // from separate values for each component with explicit date
495 // (defaults for month and year are the current values)
496 wxDateTime& Set(wxDateTime_t day,
497 Month month = Inv_Month,
498 int year = Inv_Year, // 1999, not 99 please!
499 wxDateTime_t hour = 0,
500 wxDateTime_t minute = 0,
501 wxDateTime_t second = 0,
502 wxDateTime_t millisec = 0);
503
504 // resets time to 00:00:00, doesn't change the date
505 wxDateTime& ResetTime();
506
507 // the following functions don't change the values of the other
508 // fields, i.e. SetMinute() won't change either hour or seconds value
509
510 // set the year
511 wxDateTime& SetYear(int year);
512 // set the month
513 wxDateTime& SetMonth(Month month);
514 // set the day of the month
515 wxDateTime& SetDay(wxDateTime_t day);
516 // set hour
517 wxDateTime& SetHour(wxDateTime_t hour);
518 // set minute
519 wxDateTime& SetMinute(wxDateTime_t minute);
520 // set second
521 wxDateTime& SetSecond(wxDateTime_t second);
522 // set millisecond
523 wxDateTime& SetMillisecond(wxDateTime_t millisecond);
524
525
526 // ------------------------------------------------------------------------
527 // calendar calculations
528
529 // set to the given week day in the same week as this one
530 wxDateTime& SetToWeekDayInSameWeek(WeekDay weekday);
531 wxDateTime GetWeekDayInSameWeek(WeekDay weekday);
532
533 // set to the next week day following this one
534 wxDateTime& SetToNextWeekDay(WeekDay weekday);
535 wxDateTime GetNextWeekDay(WeekDay weekday);
536
537 // set to the previous week day before this one
538 wxDateTime& SetToPrevWeekDay(WeekDay weekday);
539 wxDateTime GetPrevWeekDay(WeekDay weekday);
540
541 // set to Nth occurence of given weekday in the given month of the
542 // given year (time is set to 0), return TRUE on success and FALSE on
543 // failure. n may be positive (1..5) or negative to count from the end
544 // of the month (see helper function SetToLastWeekDay())
545 bool SetToWeekDay(WeekDay weekday,
546 int n = 1,
547 Month month = Inv_Month,
548 int year = Inv_Year);
549// wxDateTime GetWeekDay(WeekDay weekday,
550// int n = 1,
551// Month month = Inv_Month,
552// int year = Inv_Year);
553
554 // sets to the last weekday in the given month, year
555 bool SetToLastWeekDay(WeekDay weekday,
556 Month month = Inv_Month,
557 int year = Inv_Year);
558 wxDateTime GetLastWeekDay(WeekDay weekday,
559 Month month = Inv_Month,
560 int year = Inv_Year);
561
562 // sets the date to the given day of the given week in the year,
563 // returns TRUE on success and FALSE if given date doesn't exist (e.g.
564 // numWeek is > 53)
565 bool SetToTheWeek(wxDateTime_t numWeek, WeekDay weekday = Mon);
566 wxDateTime GetWeek(wxDateTime_t numWeek, WeekDay weekday = Mon);
567
568 // sets the date to the last day of the given (or current) month or the
569 // given (or current) year
570 wxDateTime& SetToLastMonthDay(Month month = Inv_Month,
571 int year = Inv_Year);
572 wxDateTime GetLastMonthDay(Month month = Inv_Month,
573 int year = Inv_Year);
574
575 // sets to the given year day (1..365 or 366)
576 wxDateTime& SetToYearDay(wxDateTime_t yday);
577 wxDateTime GetYearDay(wxDateTime_t yday);
578
579 // The definitions below were taken verbatim from
580 //
581 // http://www.capecod.net/~pbaum/date/date0.htm
582 //
583 // (Peter Baum's home page)
584 //
585 // definition: The Julian Day Number, Julian Day, or JD of a
586 // particular instant of time is the number of days and fractions of a
587 // day since 12 hours Universal Time (Greenwich mean noon) on January
588 // 1 of the year -4712, where the year is given in the Julian
589 // proleptic calendar. The idea of using this reference date was
590 // originally proposed by Joseph Scalizer in 1582 to count years but
591 // it was modified by 19th century astronomers to count days. One
592 // could have equivalently defined the reference time to be noon of
593 // November 24, -4713 if were understood that Gregorian calendar rules
594 // were applied. Julian days are Julian Day Numbers and are not to be
595 // confused with Julian dates.
596 //
597 // definition: The Rata Die number is a date specified as the number
598 // of days relative to a base date of December 31 of the year 0. Thus
599 // January 1 of the year 1 is Rata Die day 1.
600
601 // get the Julian Day number (the fractional part specifies the time of
602 // the day, related to noon - beware of rounding errors!)
603 double GetJulianDayNumber();
604 double GetJDN();
605
606 // get the Modified Julian Day number: it is equal to JDN - 2400000.5
607 // and so integral MJDs correspond to the midnights (and not noons).
608 // MJD 0 is Nov 17, 1858
609 double GetModifiedJulianDayNumber() const { return GetJDN() - 2400000.5; }
610 double GetMJD();
611
612 // get the Rata Die number
613 double GetRataDie();
614
615
616 // ------------------------------------------------------------------------
617 // timezone stuff
618
619 // transform to any given timezone
620 wxDateTime ToTimezone(const wxDateTime::TimeZone& tz, bool noDST = FALSE);
621 wxDateTime& MakeTimezone(const wxDateTime::TimeZone& tz, bool noDST = FALSE);
622
623 // transform to GMT/UTC
624 wxDateTime ToGMT(bool noDST = FALSE);
625 wxDateTime& MakeGMT(bool noDST = FALSE);
626
627 // is daylight savings time in effect at this moment according to the
628 // rules of the specified country?
629 //
630 // Return value is > 0 if DST is in effect, 0 if it is not and -1 if
631 // the information is not available (this is compatible with ANSI C)
632 int IsDST(Country country = Country_Default);
633
634
635
636 // ------------------------------------------------------------------------
637 // accessors
638
639 // is the date valid (TRUE even for non initialized objects)?
640 inline bool IsValid() const;
641
642 // get the number of seconds since the Unix epoch - returns (time_t)-1
643 // if the value is out of range
644 inline time_t GetTicks() const;
645
646 // get the year (returns Inv_Year if date is invalid)
647 int GetYear(const wxDateTime::TimeZone& tz = LOCAL) const;
648
649 // get the month (Inv_Month if date is invalid)
650 Month GetMonth(const wxDateTime::TimeZone& tz = LOCAL) const;
651
652 // get the month day (in 1..31 range, 0 if date is invalid)
653 wxDateTime_t GetDay(const wxDateTime::TimeZone& tz = LOCAL) const;
654
655 // get the day of the week (Inv_WeekDay if date is invalid)
656 WeekDay GetWeekDay(const wxDateTime::TimeZone& tz = LOCAL) const;
657
658 // get the hour of the day
659 wxDateTime_t GetHour(const wxDateTime::TimeZone& tz = LOCAL) const;
660
661 // get the minute
662 wxDateTime_t GetMinute(const wxDateTime::TimeZone& tz = LOCAL) const;
663
664 // get the second
665 wxDateTime_t GetSecond(const wxDateTime::TimeZone& tz = LOCAL) const;
666
667 // get milliseconds
668 wxDateTime_t GetMillisecond(const wxDateTime::TimeZone& tz = LOCAL) const;
669
670
671 // get the day since the year start (1..366, 0 if date is invalid)
672 wxDateTime_t GetDayOfYear(const wxDateTime::TimeZone& tz = LOCAL) const;
673 // get the week number since the year start (1..52 or 53, 0 if date is
674 // invalid)
675 wxDateTime_t GetWeekOfYear(WeekFlags flags = Monday_First,
676 const wxDateTime::TimeZone& tz = LOCAL) const;
677 // get the week number since the month start (1..5, 0 if date is
678 // invalid)
679 wxDateTime_t GetWeekOfMonth(WeekFlags flags = Monday_First,
680 const wxDateTime::TimeZone& tz = LOCAL) const;
681
682 // is this date a work day? This depends on a country, of course,
683 // because the holidays are different in different countries
684 bool IsWorkDay(Country country = Country_Default) const;
685
686 // is this date later than Gregorian calendar introduction for the
687 // given country (see enum GregorianAdoption)?
688 //
689 // NB: this function shouldn't be considered as absolute authority in
690 // the matter. Besides, for some countries the exact date of
691 // adoption of the Gregorian calendar is simply unknown.
692 //bool IsGregorianDate(GregorianAdoption country = Gr_Standard) const;
693
694
695 // ------------------------------------------------------------------------
696 // comparison (see also functions below for operator versions)
697
698 // returns TRUE if the two moments are strictly identical
699 inline bool IsEqualTo(const wxDateTime& datetime) const;
700
701 // returns TRUE if the date is strictly earlier than the given one
702 inline bool IsEarlierThan(const wxDateTime& datetime) const;
703
704 // returns TRUE if the date is strictly later than the given one
705 inline bool IsLaterThan(const wxDateTime& datetime) const;
706
707 // returns TRUE if the date is strictly in the given range
708 inline bool IsStrictlyBetween(const wxDateTime& t1,
709 const wxDateTime& t2) const;
710
711 // returns TRUE if the date is in the given range
712 inline bool IsBetween(const wxDateTime& t1, const wxDateTime& t2) const;
713
714 // do these two objects refer to the same date?
715 inline bool IsSameDate(const wxDateTime& dt) const;
716
717 // do these two objects have the same time?
718 inline bool IsSameTime(const wxDateTime& dt) const;
719
720 // are these two objects equal up to given timespan?
721 inline bool IsEqualUpTo(const wxDateTime& dt, const wxTimeSpan& ts) const;
722
723
724 // ------------------------------------------------------------------------
725 // arithmetics with dates (see also below for more operators)
726
727 // add a time span (positive or negative)
728 %name(AddTS) wxDateTime& Add(const wxTimeSpan& diff);
729 // add a date span (positive or negative)
730 %name(AddDS) wxDateTime& Add(const wxDateSpan& diff);
731
732 // subtract a time span (positive or negative)
733 %name(SubtractTS) wxDateTime& Subtract(const wxTimeSpan& diff);
734
735 // subtract a date span (positive or negative)
736 %name(SubtractDS) wxDateTime& Subtract(const wxDateSpan& diff);
737
738 // return the difference between two dates
739 wxTimeSpan Subtract(const wxDateTime& dt) const;
740
741
742 %addmethods {
743 wxDateTime __add__TS(const wxTimeSpan& other) { return *self + other; }
744 wxDateTime __add__DS(const wxDateSpan& other) { return *self + other; }
745
746 wxTimeSpan __sub__DT(const wxDateTime& other) { return *self - other; }
747 wxDateTime __sub__TS(const wxTimeSpan& other) { return *self - other; }
748 wxDateTime __sub__DS(const wxDateSpan& other) { return *self - other; }
749
750 int __cmp__(const wxDateTime* other) {
751 if (! other) return -1;
752 if (*self < *other) return -1;
753 if (*self == *other) return 0;
754 return 1;
755 }
756 }
757
758 %pragma(python) addtoclass = "
759 def __add__(self, other):
760 if string.find(other.this, 'wxTimeSpan') != -1:
761 return self.__add__TS(other)
762 if string.find(other.this, 'wxDateSpan') != -1:
763 return self.__add__DS(other)
764 raise TypeError, 'Invalid r.h.s. type for __add__'
765 def __sub__(self, other):
766 if string.find(other.this, 'wxDateTime') != -1:
767 return self.__sub__DT(other)
768 if string.find(other.this, 'wxTimeSpan') != -1:
769 return self.__sub__TS(other)
770 if string.find(other.this, 'wxDateSpan') != -1:
771 return self.__sub__DS(other)
772 raise TypeError, 'Invalid r.h.s. type for __sub__'
773"
774
775 // ------------------------------------------------------------------------
776 // conversion from text: all conversions from text return -1 on failure,
777 // or the index in the string where the next character following the date
778 // specification (i.e. the one where the scan had to stop) is located.
779
780 %addmethods {
781
782 // parse a string in RFC 822 format (found e.g. in mail headers and
783 // having the form "Wed, 10 Feb 1999 19:07:07 +0100")
784 int ParseRfc822Date(const wxString& date) {
785 const wxChar* rv;
786 const wxChar* _date = date;
787 rv = self->ParseRfc822Date(_date);
788 if (rv == NULL) return -1;
789 return rv - _date;
790 }
791
792
793 // parse a date/time in the given format (see strptime(3)), fill in
794 // the missing (in the string) fields with the values of dateDef (by
795 // default, they will not change if they had valid values or will
796 // default to Today() otherwise)
797 int ParseFormat(const wxString& date,
798 const wxString& format = wxPyDateFormatStr,
799 const wxDateTime& dateDef = wxDefaultDateTime) {
800 const wxChar* rv;
801 const wxChar* _date = date;
802 rv = self->ParseFormat(_date, format, dateDef);
803 if (rv == NULL) return -1;
804 return rv - _date;
805 }
806
807 // parse a string containing the date/time in "free" format, this
808 // function will try to make an educated guess at the string contents
809 int ParseDateTime(const wxString& datetime) {
810 const wxChar* rv;
811 const wxChar* _datetime = datetime;
812 rv = self->ParseDateTime(_datetime);
813 if (rv == NULL) return -1;
814 return rv - _datetime;
815 }
816
817
818 // parse a string containing the date only in "free" format (less
819 // flexible than ParseDateTime)
820 int ParseDate(const wxString& date) {
821 const wxChar* rv;
822 const wxChar* _date = date;
823 rv = self->ParseDate(_date);
824 if (rv == NULL) return -1;
825 return rv - _date;
826 }
827
828 // parse a string containing the time only in "free" format
829 int ParseTime(const wxString& time) {
830 const wxChar* rv;
831 const wxChar* _time = time;
832 rv = self->ParseTime(_time);
833 if (rv == NULL) return -1;
834 return rv - _time;
835 }
836 }
837
838
839 // this function accepts strftime()-like format string (default
840 // argument corresponds to the preferred date and time representation
841 // for the current locale) and returns the string containing the
842 // resulting text representation
843 wxString Format(const wxString& format = wxPyDateFormatStr,
844 const wxDateTime::TimeZone& tz = LOCAL) const;
845
846 // preferred date representation for the current locale
847 wxString FormatDate() const;
848
849 // preferred time representation for the current locale
850 wxString FormatTime() const;
851
852 // returns the string representing the date in ISO 8601 format
853 // (YYYY-MM-DD)
854 wxString FormatISODate() const;
855
856 // returns the string representing the time in ISO 8601 format
857 // (HH:MM:SS)
858 wxString FormatISOTime() const;
859
860 %pragma(python) addtoclass = "
861 def __repr__(self):
862 return '<wxDateTime: \"%s\" at %s>' % ( self.Format(), self.this)
863 def __str__(self):
864 return self.Format()
865"
866
867};
868
869//---------------------------------------------------------------------------
870//---------------------------------------------------------------------------
871
872
873class wxTimeSpan
874{
875public:
876 // return the timespan for the given number of seconds
877 static wxTimeSpan Seconds(long sec);
878 static wxTimeSpan Second();
879
880 // return the timespan for the given number of minutes
881 static wxTimeSpan Minutes(long min);
882 static wxTimeSpan Minute();
883
884 // return the timespan for the given number of hours
885 static wxTimeSpan Hours(long hours);
886 static wxTimeSpan Hour();
887
888 // return the timespan for the given number of days
889 static wxTimeSpan Days(long days);
890 static wxTimeSpan Day();
891
892 // return the timespan for the given number of weeks
893 static wxTimeSpan Weeks(long days);
894 static wxTimeSpan Week();
895
896 // ------------------------------------------------------------------------
897 // constructors
898
899 // from separate values for each component, date set to 0 (hours are
900 // not restricted to 0..24 range, neither are minutes, seconds or
901 // milliseconds)
902 wxTimeSpan(long hours = 0,
903 long minutes = 0,
904 long seconds = 0,
905 long milliseconds = 0);
906
907 ~wxTimeSpan();
908
909 // ------------------------------------------------------------------------
910 // arithmetics with time spans
911
912 // add two timespans together
913 inline wxTimeSpan& Add(const wxTimeSpan& diff);
914
915 // subtract another timespan
916 inline wxTimeSpan& Subtract(const wxTimeSpan& diff);
917
918 // multiply timespan by a scalar
919 inline wxTimeSpan& Multiply(int n);
920
921 // negate the value of the timespan
922 wxTimeSpan& Neg();
923
924 // return the absolute value of the timespan: does _not_ modify the
925 // object
926 inline wxTimeSpan Abs() const;
927
928 %addmethods {
929 wxTimeSpan __add__(const wxTimeSpan& other) { return *self + other; }
930 wxTimeSpan __sub__(const wxTimeSpan& other) { return *self - other; }
931 wxTimeSpan __mul__(int n) { return *self * n; }
932 wxTimeSpan __rmul__(int n) { return n * *self; }
933 wxTimeSpan __neg__() { return self->Negate(); }
934 int __cmp__(const wxTimeSpan* other) {
935 if (! other) return -1;
936 if (*self < *other) return -1;
937 if (*self == *other) return 0;
938 return 1;
939 }
940 }
941
942 // comparaison (see also operator versions below)
943 // ------------------------------------------------------------------------
944
945 // is the timespan null?
946 bool IsNull() const;
947
948 // is the timespan positive?
949 bool IsPositive() const;
950
951 // is the timespan negative?
952 bool IsNegative() const;
953
954 // are two timespans equal?
955 inline bool IsEqualTo(const wxTimeSpan& ts) const;
956
957 // compare two timestamps: works with the absolute values, i.e. -2
958 // hours is longer than 1 hour. Also, it will return FALSE if the
959 // timespans are equal in absolute value.
960 inline bool IsLongerThan(const wxTimeSpan& ts) const;
961
962 // compare two timestamps: works with the absolute values, i.e. 1
963 // hour is shorter than -2 hours. Also, it will return FALSE if the
964 // timespans are equal in absolute value.
965 bool IsShorterThan(const wxTimeSpan& t) const;
966
967 // ------------------------------------------------------------------------
968 // breaking into days, hours, minutes and seconds
969
970 // get the max number of weeks in this timespan
971 inline int GetWeeks() const;
972 // get the max number of days in this timespan
973 inline int GetDays() const;
974 // get the max number of hours in this timespan
975 inline int GetHours() const;
976 // get the max number of minutes in this timespan
977 inline int GetMinutes() const;
978
979
980 // get the max number of seconds in this timespan
981 inline wxLongLong GetSeconds() const;
982 // get the number of milliseconds in this timespan
983 wxLongLong GetMilliseconds() const;
984
985 // ------------------------------------------------------------------------
986 // conversion to text
987
988 // this function accepts strftime()-like format string (default
989 // argument corresponds to the preferred date and time representation
990 // for the current locale) and returns the string containing the
991 // resulting text representation. Notice that only some of format
992 // specifiers valid for wxDateTime are valid for wxTimeSpan: hours,
993 // minutes and seconds make sense, but not "PM/AM" string for example.
994 wxString Format(const wxString& format = wxPyDateFormatStr) const;
995
996// // preferred date representation for the current locale
997// wxString FormatDate() const;
998
999// // preferred time representation for the current locale
1000// wxString FormatTime() const;
1001
1002// %pragma(python) addtoclass = "
1003// def __repr__(self):
1004// return '<wxTimeSpan: \"%s\" at %s>' % ( self.Format(), self.this)
1005// def __str__(self):
1006// return self.Format()
1007// "
1008};
1009
1010
1011//---------------------------------------------------------------------------
1012//---------------------------------------------------------------------------
1013
1014class wxDateSpan
1015{
1016public:
1017 // this many years/months/weeks/days
1018 wxDateSpan(int years = 0, int months = 0, int weeks = 0, int days = 0)
1019 {
1020 m_years = years;
1021 m_months = months;
1022 m_weeks = weeks;
1023 m_days = days;
1024 }
1025
1026 ~wxDateSpan();
1027
1028 // get an object for the given number of days
1029 static wxDateSpan Days(int days);
1030 static wxDateSpan Day();
1031
1032 // get an object for the given number of weeks
1033 static wxDateSpan Weeks(int weeks);
1034 static wxDateSpan Week();
1035
1036 // get an object for the given number of months
1037 static wxDateSpan Months(int mon);
1038 static wxDateSpan Month();
1039
1040 // get an object for the given number of years
1041 static wxDateSpan Years(int years);
1042 static wxDateSpan Year();
1043
1044
1045 // ------------------------------------------------------------------------
1046
1047 // set number of years
1048 wxDateSpan& SetYears(int n);
1049 // set number of months
1050 wxDateSpan& SetMonths(int n);
1051 // set number of weeks
1052 wxDateSpan& SetWeeks(int n);
1053 // set number of days
1054 wxDateSpan& SetDays(int n);
1055
1056 // get number of years
1057 int GetYears() const;
1058 // get number of months
1059 int GetMonths() const;
1060 // get number of weeks
1061 int GetWeeks() const;
1062 // get number of days
1063 int GetDays() const;
1064 // returns 7*GetWeeks() + GetDays()
1065 int GetTotalDays() const;
1066
1067
1068 // ------------------------------------------------------------------------
1069
1070 // add another wxDateSpan to us
1071 inline wxDateSpan& Add(const wxDateSpan& other);
1072
1073 // subtract another wxDateSpan from us
1074 inline wxDateSpan& Subtract(const wxDateSpan& other);
1075
1076 // inverse the sign of this timespan
1077 inline wxDateSpan& Neg();
1078
1079 // multiply all components by a (signed) number
1080 inline wxDateSpan& Multiply(int factor);
1081
1082 %addmethods {
1083 wxDateSpan __add__(const wxDateSpan& other) { return *self + other; }
1084 wxDateSpan __sub__(const wxDateSpan& other) { return *self - other; }
1085 wxDateSpan __mul__(int n) { return *self * n; }
1086 wxDateSpan __rmul__(int n) { return n * *self; }
1087 wxDateSpan __neg__() { return self->Negate(); }
1088 }
1089};
1090
1091
1092//---------------------------------------------------------------------------
1093
1094long wxGetLocalTime();
1095long wxGetUTCTime();
1096long wxGetCurrentTime();
1097wxLongLong wxGetLocalTimeMillis();
1098
1099//---------------------------------------------------------------------------
1100//---------------------------------------------------------------------------
1101
1102%init %{
1103 // These are no longer needed since utils is back in the core
1104// wxClassInfo::CleanUpClasses();
1105// wxClassInfo::InitializeClasses();
1106%}
1107
1108//---------------------------------------------------------------------------
1109