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