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