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