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