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