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