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