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