datetime.h 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: datetime.h
  3. // Purpose: interface of wxDateTime
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @class wxDateTime
  9. wxDateTime class represents an absolute moment in time.
  10. The type @c wxDateTime_t is typedefed as <tt>unsigned short</tt> and is
  11. used to contain the number of years, hours, minutes, seconds and
  12. milliseconds.
  13. Global constant ::wxDefaultDateTime and synonym for it ::wxInvalidDateTime are
  14. defined. This constant will be different from any valid wxDateTime object.
  15. @section datetime_static Static Functions
  16. All static functions either set or return the static variables of
  17. wxDateSpan (the country), return the current moment, year, month or number
  18. of days in it, or do some general calendar-related actions.
  19. Please note that although several function accept an extra Calendar
  20. parameter, it is currently ignored as only the Gregorian calendar is
  21. supported. Future versions will support other calendars.
  22. @section datetime_formatting Date Formatting and Parsing
  23. The date formatting and parsing functions convert wxDateTime objects to and
  24. from text. The conversions to text are mostly trivial: you can either do it
  25. using the default date and time representations for the current locale
  26. (FormatDate() and FormatTime()), using the international standard
  27. representation defined by ISO 8601 (FormatISODate(), FormatISOTime() and
  28. FormatISOCombined()) or by specifying any format at all and using Format()
  29. directly.
  30. The conversions from text are more interesting, as there are much more
  31. possibilities to care about. The simplest cases can be taken care of with
  32. ParseFormat() which can parse any date in the given (rigid) format.
  33. ParseRfc822Date() is another function for parsing dates in predefined
  34. format -- the one of RFC 822 which (still...) defines the format of email
  35. messages on the Internet. This format cannot be described with
  36. @c strptime(3)-like format strings used by Format(), hence the need for a
  37. separate function.
  38. But the most interesting functions are ParseTime(), ParseDate() and
  39. ParseDateTime(). They try to parse the date and time (or only one of them)
  40. in 'free' format, i.e. allow them to be specified in any of possible ways.
  41. These functions will usually be used to parse the (interactive) user input
  42. which is not bound to be in any predefined format. As an example,
  43. ParseDate() can parse the strings such as "tomorrow", "March first" and
  44. even "next Sunday".
  45. Finally notice that each of the parsing functions is available in several
  46. overloads: if the input string is a narrow (@c char *) string, then a
  47. narrow pointer is returned. If the input string is a wide string, a wide
  48. char pointer is returned. Finally, if the input parameter is a wxString, a
  49. narrow char pointer is also returned for backwards compatibility but there
  50. is also an additional argument of wxString::const_iterator type in which,
  51. if it is not @NULL, an iterator pointing to the end of the scanned string
  52. part is returned.
  53. @library{wxbase}
  54. @category{data}
  55. @stdobjects
  56. - ::wxDefaultDateTime
  57. @see @ref overview_datetime, wxTimeSpan, wxDateSpan, wxCalendarCtrl
  58. */
  59. class wxDateTime
  60. {
  61. public:
  62. /**
  63. A small unsigned integer type for storing things like minutes,
  64. seconds &c. It should be at least short (i.e. not char) to contain
  65. the number of milliseconds - it may also be 'int' because there is
  66. no size penalty associated with it in our code, we don't store any
  67. data in this format.
  68. */
  69. typedef unsigned short wxDateTime_t;
  70. /**
  71. Time zone symbolic names.
  72. */
  73. enum TZ
  74. {
  75. /// the time in the current time zone
  76. Local,
  77. //@{
  78. /// zones from GMT (= Greenwich Mean Time): they're guaranteed to be
  79. /// consequent numbers, so writing something like `GMT0 + offset' is
  80. /// safe if abs(offset) <= 12
  81. // underscore stands for minus
  82. GMT_12, GMT_11, GMT_10, GMT_9, GMT_8, GMT_7,
  83. GMT_6, GMT_5, GMT_4, GMT_3, GMT_2, GMT_1,
  84. GMT0,
  85. GMT1, GMT2, GMT3, GMT4, GMT5, GMT6,
  86. GMT7, GMT8, GMT9, GMT10, GMT11, GMT12, GMT13,
  87. // Note that GMT12 and GMT_12 are not the same: there is a difference
  88. // of exactly one day between them
  89. //@}
  90. // some symbolic names for TZ
  91. // Europe
  92. WET = GMT0, //!< Western Europe Time
  93. WEST = GMT1, //!< Western Europe Summer Time
  94. CET = GMT1, //!< Central Europe Time
  95. CEST = GMT2, //!< Central Europe Summer Time
  96. EET = GMT2, //!< Eastern Europe Time
  97. EEST = GMT3, //!< Eastern Europe Summer Time
  98. MSK = GMT3, //!< Moscow Time
  99. MSD = GMT4, //!< Moscow Summer Time
  100. // US and Canada
  101. AST = GMT_4, //!< Atlantic Standard Time
  102. ADT = GMT_3, //!< Atlantic Daylight Time
  103. EST = GMT_5, //!< Eastern Standard Time
  104. EDT = GMT_4, //!< Eastern Daylight Saving Time
  105. CST = GMT_6, //!< Central Standard Time
  106. CDT = GMT_5, //!< Central Daylight Saving Time
  107. MST = GMT_7, //!< Mountain Standard Time
  108. MDT = GMT_6, //!< Mountain Daylight Saving Time
  109. PST = GMT_8, //!< Pacific Standard Time
  110. PDT = GMT_7, //!< Pacific Daylight Saving Time
  111. HST = GMT_10, //!< Hawaiian Standard Time
  112. AKST = GMT_9, //!< Alaska Standard Time
  113. AKDT = GMT_8, //!< Alaska Daylight Saving Time
  114. // Australia
  115. A_WST = GMT8, //!< Western Standard Time
  116. A_CST = GMT13 + 1, //!< Central Standard Time (+9.5)
  117. A_EST = GMT10, //!< Eastern Standard Time
  118. A_ESST = GMT11, //!< Eastern Summer Time
  119. // New Zealand
  120. NZST = GMT12, //!< Standard Time
  121. NZDT = GMT13, //!< Daylight Saving Time
  122. /// Universal Coordinated Time = the new and politically correct name
  123. /// for GMT.
  124. UTC = GMT0
  125. };
  126. /**
  127. Several functions accept an extra parameter specifying the calendar to use
  128. (although most of them only support now the Gregorian calendar). This
  129. parameters is one of the following values.
  130. */
  131. enum Calendar
  132. {
  133. Gregorian, ///< calendar currently in use in Western countries
  134. Julian ///< calendar in use since -45 until the 1582 (or later)
  135. };
  136. /**
  137. Date calculations often depend on the country and wxDateTime allows to set
  138. the country whose conventions should be used using SetCountry(). It takes
  139. one of the following values as parameter.
  140. */
  141. enum Country
  142. {
  143. Country_Unknown, ///< no special information for this country
  144. Country_Default, ///< set the default country with SetCountry() method
  145. ///< or use the default country with any other
  146. Country_WesternEurope_Start,
  147. Country_EEC = Country_WesternEurope_Start,
  148. France,
  149. Germany,
  150. UK,
  151. Country_WesternEurope_End = UK,
  152. Russia,
  153. USA
  154. };
  155. /// symbolic names for the months
  156. enum Month
  157. {
  158. Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec,
  159. /// Invalid month value.
  160. Inv_Month
  161. };
  162. /// symbolic names for the weekdays
  163. enum WeekDay
  164. {
  165. Sun, Mon, Tue, Wed, Thu, Fri, Sat,
  166. /// Invalid week day value.
  167. Inv_WeekDay
  168. };
  169. /// invalid value for the year
  170. enum Year
  171. {
  172. Inv_Year = SHRT_MIN // should hold in wxDateTime_t
  173. };
  174. /**
  175. Flags to be used with GetMonthName() and GetWeekDayName() functions.
  176. */
  177. enum NameFlags
  178. {
  179. Name_Full = 0x01, ///< return full name
  180. Name_Abbr = 0x02 ///< return abbreviated name
  181. };
  182. /**
  183. Different parts of the world use different conventions for the week start.
  184. In some countries, the week starts on Sunday, while in others -- on Monday.
  185. The ISO standard doesn't address this issue, so we support both conventions
  186. in the functions whose result depends on it (GetWeekOfYear() and
  187. GetWeekOfMonth()).
  188. The desired behaviour may be specified by giving one of the following
  189. constants as argument to these functions.
  190. */
  191. enum WeekFlags
  192. {
  193. Default_First, ///< Sunday_First for US, Monday_First for the rest
  194. Monday_First, ///< week starts with a Monday
  195. Sunday_First ///< week starts with a Sunday
  196. };
  197. /**
  198. Class representing a time zone.
  199. The representation is simply the offset, in seconds, from UTC.
  200. */
  201. class WXDLLIMPEXP_BASE TimeZone
  202. {
  203. public:
  204. /// Constructor for a named time zone.
  205. TimeZone(TZ tz);
  206. /// Constructor for the given offset in seconds.
  207. TimeZone(long offset = 0);
  208. /// Create a time zone with the given offset in seconds.
  209. static TimeZone Make(long offset);
  210. /// Return the offset of this time zone from UTC, in seconds.
  211. long GetOffset() const;
  212. };
  213. /**
  214. Contains broken down date-time representation.
  215. This struct is analogous to standard C <code>struct tm</code> and uses
  216. the same, not always immediately obvious, conventions for its members:
  217. notably its mon and mday fields count from 0 while yday counts from 1.
  218. */
  219. struct Tm
  220. {
  221. wxDateTime_t msec, ///< Number of milliseconds.
  222. sec, ///< Seconds in 0..59 (60 with leap seconds) range.
  223. min, ///< Minutes in 0..59 range.
  224. hour, ///< Hours since midnight in 0..23 range.
  225. mday, ///< Day of the month in 1..31 range.
  226. yday; ///< Day of the year in 0..365 range.
  227. Month mon; ///< Month, as an enumerated constant.
  228. int year; ///< Year.
  229. /**
  230. Check if the given date/time is valid (in Gregorian calendar).
  231. Return @false if the components don't correspond to a correct date.
  232. */
  233. bool IsValid() const;
  234. /**
  235. Return the week day corresponding to this date.
  236. Unlike the other fields, the week day is not always available and
  237. so must be accessed using this method as it is computed on demand
  238. when it is called.
  239. */
  240. WeekDay GetWeekDay();
  241. };
  242. /**
  243. @name Constructors, Assignment Operators and Setters
  244. Constructors and various Set() methods are collected here. If you
  245. construct a date object from separate values for day, month and year,
  246. you should use IsValid() method to check that the values were correct
  247. as constructors cannot return an error code.
  248. */
  249. //@{
  250. /**
  251. Default constructor. Use one of the Set() functions to initialize the
  252. object later.
  253. */
  254. wxDateTime();
  255. /**
  256. Copy constructor.
  257. */
  258. wxDateTime(const wxDateTime& date);
  259. /**
  260. Same as Set().
  261. */
  262. wxDateTime(time_t timet);
  263. /**
  264. Same as Set().
  265. */
  266. wxDateTime(const struct tm& tm);
  267. /**
  268. Same as Set().
  269. */
  270. wxDateTime(double jdn);
  271. /**
  272. Same as Set().
  273. */
  274. wxDateTime(wxDateTime_t hour, wxDateTime_t minute = 0,
  275. wxDateTime_t second = 0, wxDateTime_t millisec = 0);
  276. /**
  277. Same as Set().
  278. */
  279. wxDateTime(wxDateTime_t day, Month month,
  280. int year = Inv_Year, wxDateTime_t hour = 0,
  281. wxDateTime_t minute = 0, wxDateTime_t second = 0,
  282. wxDateTime_t millisec = 0);
  283. /**
  284. Same as SetFromMSWSysTime.
  285. @param st
  286. Input, Windows SYSTEMTIME reference
  287. @since 2.9.0
  288. @remarks MSW only
  289. @onlyfor{wxmsw}
  290. */
  291. wxDateTime(const struct _SYSTEMTIME& st);
  292. /**
  293. Reset time to midnight (00:00:00) without changing the date.
  294. */
  295. wxDateTime& ResetTime();
  296. /**
  297. Constructs the object from @a timet value holding the number of seconds
  298. since Jan 1, 1970 UTC.
  299. If @a timet is invalid, i.e. @code (time_t)-1 @endcode, wxDateTime
  300. becomes invalid too, i.e. its IsValid() will return @false.
  301. */
  302. wxDateTime& Set(time_t timet);
  303. /**
  304. Sets the date and time from the broken down representation in the
  305. standard @a tm structure.
  306. */
  307. wxDateTime& Set(const struct tm& tm);
  308. /**
  309. Sets the date and time from the broken down representation in the
  310. @a wxDateTime::Tm structure.
  311. */
  312. wxDateTime& Set(const Tm& tm);
  313. /**
  314. Sets the date from the so-called Julian Day Number.
  315. By definition, the Julian Day Number, usually abbreviated as JDN, of a
  316. particular instant is the fractional number of days since 12 hours
  317. Universal Coordinated Time (Greenwich mean noon) on January 1 of the
  318. year -4712 in the Julian proleptic calendar.
  319. */
  320. wxDateTime& Set(double jdn);
  321. /**
  322. Sets the date to be equal to Today() and the time from supplied
  323. parameters.
  324. See the full Set() overload for the remarks about DST.
  325. */
  326. wxDateTime& Set(wxDateTime_t hour, wxDateTime_t minute = 0,
  327. wxDateTime_t second = 0, wxDateTime_t millisec = 0);
  328. /**
  329. Sets the date and time from the parameters.
  330. If the function parameters are invalid, e.g. @a month is February and
  331. @a day is 30, the object is left in an invalid state, i.e. IsValid()
  332. method will return @false.
  333. If the specified time moment is invalid due to DST, i.e. it falls into
  334. the "missing" hour on the date on which the DST starts, a valid
  335. wxDateTime object is still constructed but its hour component is moved
  336. forward to ensure that it corresponds to a valid moment in the local
  337. time zone. For example, in the CET time zone the DST started on
  338. 2013-03-31T02:00:00 in 2013 and so setting the object to 2:30 at this
  339. date actually sets the hour to 3, and not 2.
  340. */
  341. wxDateTime& Set(wxDateTime_t day, Month month,
  342. int year = Inv_Year, wxDateTime_t hour = 0,
  343. wxDateTime_t minute = 0, wxDateTime_t second = 0,
  344. wxDateTime_t millisec = 0);
  345. /**
  346. Sets the day without changing other date components.
  347. */
  348. wxDateTime& SetDay(unsigned short day);
  349. /**
  350. Sets the date from the date and time in DOS format.
  351. */
  352. wxDateTime& SetFromDOS(unsigned long ddt);
  353. /**
  354. Sets the hour without changing other date components.
  355. */
  356. wxDateTime& SetHour(unsigned short hour);
  357. /**
  358. Sets the millisecond without changing other date components.
  359. */
  360. wxDateTime& SetMillisecond(unsigned short millisecond);
  361. /**
  362. Sets the minute without changing other date components.
  363. */
  364. wxDateTime& SetMinute(unsigned short minute);
  365. /**
  366. Sets the month without changing other date components.
  367. */
  368. wxDateTime& SetMonth(Month month);
  369. /**
  370. Sets the second without changing other date components.
  371. */
  372. wxDateTime& SetSecond(unsigned short second);
  373. /**
  374. Sets the date and time of to the current values. Same as assigning the
  375. result of Now() to this object.
  376. */
  377. wxDateTime& SetToCurrent();
  378. /**
  379. Sets the year without changing other date components.
  380. */
  381. wxDateTime& SetYear(int year);
  382. /**
  383. Same as Set().
  384. */
  385. wxDateTime& operator=(time_t timet);
  386. /**
  387. Same as Set().
  388. */
  389. wxDateTime& operator=(const struct tm& tm);
  390. //@}
  391. /**
  392. @name Accessors
  393. Here are the trivial accessors. Other functions, which might have to
  394. perform some more complicated calculations to find the answer are under
  395. the "Date Arithmetics" section.
  396. */
  397. //@{
  398. /**
  399. Returns the date and time in DOS format.
  400. */
  401. unsigned long GetAsDOS() const;
  402. /**
  403. Initialize using the Windows SYSTEMTIME structure.
  404. @param st
  405. Input, Windows SYSTEMTIME reference
  406. @since 2.9.0
  407. @remarks MSW only
  408. @onlyfor{wxmsw}
  409. */
  410. wxDateTime& SetFromMSWSysTime(const struct _SYSTEMTIME& st);
  411. /**
  412. Returns the date and time in the Windows SYSTEMTIME format.
  413. @param st
  414. Output, pointer to Windows SYSTEMTIME
  415. @since 2.9.0
  416. @remarks MSW only
  417. @onlyfor{wxmsw}
  418. */
  419. void GetAsMSWSysTime(struct _SYSTEMTIME* st) const;
  420. /**
  421. Returns the century of this date.
  422. */
  423. int GetCentury(const TimeZone& tz = Local) const;
  424. /**
  425. Returns the object having the same date component as this one but time
  426. of 00:00:00.
  427. @since 2.8.2
  428. @see ResetTime()
  429. */
  430. wxDateTime GetDateOnly() const;
  431. /**
  432. Returns the day in the given timezone (local one by default).
  433. */
  434. unsigned short GetDay(const TimeZone& tz = Local) const;
  435. /**
  436. Returns the day of the year (in 1-366 range) in the given timezone
  437. (local one by default).
  438. */
  439. unsigned short GetDayOfYear(const TimeZone& tz = Local) const;
  440. /**
  441. Returns the hour in the given timezone (local one by default).
  442. */
  443. unsigned short GetHour(const TimeZone& tz = Local) const;
  444. /**
  445. Returns the milliseconds in the given timezone (local one by default).
  446. */
  447. unsigned short GetMillisecond(const TimeZone& tz = Local) const;
  448. /**
  449. Returns the minute in the given timezone (local one by default).
  450. */
  451. unsigned short GetMinute(const TimeZone& tz = Local) const;
  452. /**
  453. Returns the month in the given timezone (local one by default).
  454. */
  455. Month GetMonth(const TimeZone& tz = Local) const;
  456. /**
  457. Returns the seconds in the given timezone (local one by default).
  458. */
  459. unsigned short GetSecond(const TimeZone& tz = Local) const;
  460. /**
  461. Returns the number of seconds since Jan 1, 1970 UTC.
  462. An assert failure will occur if the date is not in the range covered by
  463. @c time_t type, use GetValue() if you work with dates outside of it.
  464. */
  465. time_t GetTicks() const;
  466. /**
  467. Returns broken down representation of the date and time.
  468. */
  469. Tm GetTm(const TimeZone& tz = Local) const;
  470. /**
  471. Returns the week day in the given timezone (local one by default).
  472. */
  473. WeekDay GetWeekDay(const TimeZone& tz = Local) const;
  474. /**
  475. Returns the ordinal number of the week in the month (in 1-5 range).
  476. As GetWeekOfYear(), this function supports both conventions for the
  477. week start.
  478. */
  479. wxDateTime_t GetWeekOfMonth(WeekFlags flags = Monday_First,
  480. const TimeZone& tz = Local) const;
  481. /**
  482. Returns the number of the week of the year this date is in. The first
  483. week of the year is, according to international standards, the one
  484. containing Jan 4 or, equivalently, the first week which has Thursday in
  485. this year. Both of these definitions are the same as saying that the
  486. first week of the year must contain more than half of its days in this
  487. year. Accordingly, the week number will always be in 1-53 range (52 for
  488. non-leap years).
  489. The function depends on the week start convention specified by the @a flags
  490. argument but its results for @c Sunday_First are not well-defined as the
  491. ISO definition quoted above applies to the weeks starting on Monday only.
  492. */
  493. wxDateTime_t GetWeekOfYear(WeekFlags flags = Monday_First,
  494. const TimeZone& tz = Local) const;
  495. /**
  496. Returns the year in the given timezone (local one by default).
  497. */
  498. int GetYear(const TimeZone& tz = Local) const;
  499. /**
  500. Returns @true if the object represents a valid time moment.
  501. */
  502. bool IsValid() const;
  503. /**
  504. Returns @true is this day is not a holiday in the given country.
  505. */
  506. bool IsWorkDay(Country country = Country_Default) const;
  507. //@}
  508. /**
  509. @name Date Comparison
  510. There are several functions to allow date comparison. To supplement
  511. them, a few global operators, etc taking wxDateTime are defined.
  512. */
  513. //@{
  514. /**
  515. Returns @true if this date precedes the given one.
  516. */
  517. bool IsEarlierThan(const wxDateTime& datetime) const;
  518. /**
  519. Returns @true if the two dates are strictly identical.
  520. */
  521. bool IsEqualTo(const wxDateTime& datetime) const;
  522. /**
  523. Returns @true if the date is equal to another one up to the given time
  524. interval, i.e.\ if the absolute difference between the two dates is less
  525. than this interval.
  526. */
  527. bool IsEqualUpTo(const wxDateTime& dt, const wxTimeSpan& ts) const;
  528. /**
  529. Returns @true if this date is later than the given one.
  530. */
  531. bool IsLaterThan(const wxDateTime& datetime) const;
  532. /**
  533. Returns @true if the date is the same without comparing the time parts.
  534. */
  535. bool IsSameDate(const wxDateTime& dt) const;
  536. /**
  537. Returns @true if the time is the same (although dates may differ).
  538. */
  539. bool IsSameTime(const wxDateTime& dt) const;
  540. /**
  541. Returns @true if this date lies strictly between the two given dates.
  542. @see IsBetween()
  543. */
  544. bool IsStrictlyBetween(const wxDateTime& t1,
  545. const wxDateTime& t2) const;
  546. /**
  547. Returns @true if IsStrictlyBetween() is @true or if the date is equal
  548. to one of the limit values.
  549. @see IsStrictlyBetween()
  550. */
  551. bool IsBetween(const wxDateTime& t1, const wxDateTime& t2) const;
  552. //@}
  553. /**
  554. @name Date Arithmetics
  555. These functions carry out
  556. @ref overview_datetime_arithmetics "arithmetics" on the wxDateTime
  557. objects. As explained in the overview, either wxTimeSpan or wxDateSpan
  558. may be added to wxDateTime, hence all functions are overloaded to
  559. accept both arguments.
  560. Also, both Add() and Subtract() have both const and non-const version.
  561. The first one returns a new object which represents the sum/difference
  562. of the original one with the argument while the second form modifies
  563. the object to which it is applied. The operators "-=" and "+=" are
  564. defined to be equivalent to the second forms of these functions.
  565. */
  566. //@{
  567. /**
  568. Adds the given date span to this object.
  569. */
  570. wxDateTime Add(const wxDateSpan& diff) const;
  571. /**
  572. Adds the given date span to this object.
  573. */
  574. wxDateTime& Add(const wxDateSpan& diff);
  575. /**
  576. Adds the given time span to this object.
  577. */
  578. wxDateTime Add(const wxTimeSpan& diff) const;
  579. /**
  580. Adds the given time span to this object.
  581. */
  582. wxDateTime& Add(const wxTimeSpan& diff);
  583. /**
  584. Subtracts the given time span from this object.
  585. */
  586. wxDateTime Subtract(const wxTimeSpan& diff) const;
  587. /**
  588. Subtracts the given time span from this object.
  589. */
  590. wxDateTime& Subtract(const wxTimeSpan& diff);
  591. /**
  592. Subtracts the given date span from this object.
  593. */
  594. wxDateTime Subtract(const wxDateSpan& diff) const;
  595. /**
  596. Subtracts the given date span from this object.
  597. */
  598. wxDateTime& Subtract(const wxDateSpan& diff);
  599. /**
  600. Subtracts another date from this one and returns the difference between
  601. them as a wxTimeSpan.
  602. */
  603. wxTimeSpan Subtract(const wxDateTime& dt) const;
  604. /**
  605. Returns the difference between this object and @a dt as a wxDateSpan.
  606. This method allows to find the number of entire years, months, weeks and
  607. days between @a dt and this date.
  608. @since 2.9.5
  609. */
  610. wxDateSpan DiffAsDateSpan(const wxDateTime& dt) const;
  611. /**
  612. Adds the given date span to this object.
  613. */
  614. wxDateTime& operator+=(const wxDateSpan& diff);
  615. /**
  616. Adds the given date span to this object.
  617. */
  618. wxDateTime operator+(const wxDateSpan& ds) const;
  619. /**
  620. Subtracts the given date span from this object.
  621. */
  622. wxDateTime& operator-=(const wxDateSpan& diff);
  623. /**
  624. Subtracts the given date span from this object.
  625. */
  626. wxDateTime operator-(const wxDateSpan& ds) const;
  627. /**
  628. Adds the given time span to this object.
  629. */
  630. wxDateTime& operator+=(const wxTimeSpan& diff);
  631. /**
  632. Adds the given time span to this object.
  633. */
  634. wxDateTime operator+(const wxTimeSpan& ts) const;
  635. /**
  636. Subtracts the given time span from this object.
  637. */
  638. wxDateTime& operator-=(const wxTimeSpan& diff);
  639. /**
  640. Subtracts the given time span from this object.
  641. */
  642. wxDateTime operator-(const wxTimeSpan& ts) const;
  643. /**
  644. Subtracts another date from this one and returns the difference between
  645. them as a wxTimeSpan.
  646. */
  647. wxTimeSpan operator-(const wxDateTime& dt2) const;
  648. //@}
  649. /**
  650. @name Date Formatting and Parsing
  651. See @ref datetime_formatting
  652. */
  653. //@{
  654. /**
  655. This function does the same as the standard ANSI C @c strftime(3)
  656. function (http://www.cplusplus.com/reference/clibrary/ctime/strftime.html).
  657. Please see its description for the meaning of @a format parameter.
  658. Notice that POSIX @c "%g", @c "%G", @c "%V" and @c "%z" format
  659. specifiers are supported even if the standard library doesn't support
  660. them (e.g. MSVC).
  661. It also accepts a few wxWidgets-specific extensions: you can optionally
  662. specify the width of the field to follow using @c printf(3)-like syntax
  663. and the format specification @c "%l" can be used to get the number of
  664. milliseconds.
  665. @see ParseFormat()
  666. */
  667. wxString Format(const wxString& format = wxDefaultDateTimeFormat,
  668. const TimeZone& tz = Local) const;
  669. /**
  670. Identical to calling Format() with @c "%x" argument (which means
  671. "preferred date representation for the current locale").
  672. */
  673. wxString FormatDate() const;
  674. /**
  675. Returns the combined date-time representation in the ISO 8601 format
  676. @c "YYYY-MM-DDTHH:MM:SS". The @a sep parameter default value produces
  677. the result exactly corresponding to the ISO standard, but it can also
  678. be useful to use a space as separator if a more human-readable combined
  679. date-time representation is needed.
  680. @see FormatISODate(), FormatISOTime(), ParseISOCombined()
  681. */
  682. wxString FormatISOCombined(char sep = 'T') const;
  683. /**
  684. This function returns the date representation in the ISO 8601 format
  685. @c "YYYY-MM-DD".
  686. */
  687. wxString FormatISODate() const;
  688. /**
  689. This function returns the time representation in the ISO 8601 format
  690. @c "HH:MM:SS".
  691. */
  692. wxString FormatISOTime() const;
  693. /**
  694. Identical to calling Format() with @c "%X" argument (which means
  695. "preferred time representation for the current locale").
  696. */
  697. wxString FormatTime() const;
  698. /**
  699. This function is like ParseDateTime(), but it only allows the date to
  700. be specified.
  701. It is thus less flexible then ParseDateTime(), but also has less
  702. chances to misinterpret the user input.
  703. See ParseFormat() for the description of function parameters and return
  704. value.
  705. @see Format()
  706. */
  707. bool ParseDate(const wxString& date, wxString::const_iterator *end);
  708. /**
  709. Parses the string @a datetime containing the date and time in free
  710. format.
  711. This function tries as hard as it can to interpret the given string as
  712. date and time. Unlike ParseRfc822Date(), it will accept anything that
  713. may be accepted and will only reject strings which cannot be parsed in
  714. any way at all. Notice that the function will fail if either date or
  715. time part is present but not both, use ParseDate() or ParseTime() to
  716. parse strings containing just the date or time component.
  717. See ParseFormat() for the description of function parameters and return
  718. value.
  719. */
  720. bool ParseDateTime(const wxString& datetime, wxString::const_iterator *end);
  721. /**
  722. This function parses the string @a date according to the given
  723. @e format. The system @c strptime(3) function is used whenever
  724. available, but even if it is not, this function is still implemented,
  725. although support for locale-dependent format specifiers such as
  726. @c "%c", @c "%x" or @c "%X" may not be perfect and GNU extensions such
  727. as @c "%z" and @c "%Z" are not implemented. This function does handle
  728. the month and weekday names in the current locale on all platforms,
  729. however.
  730. Please see the description of the ANSI C function @c strftime(3) for
  731. the syntax of the format string.
  732. The @a dateDef parameter is used to fill in the fields which could not
  733. be determined from the format string. For example, if the format is
  734. @c "%d" (the day of the month), the month and the year are taken from
  735. @a dateDef. If it is not specified, Today() is used as the default
  736. date.
  737. Example of using this function:
  738. @code
  739. wxDateTime dt;
  740. wxString str = "...";
  741. wxString::const_iterator end;
  742. if ( !dt.ParseFormat(str, "%Y-%m-%d", &end) )
  743. ... parsing failed ...
  744. else if ( end == str.end() )
  745. ... entire string parsed ...
  746. else
  747. ... wxString(end, str.end()) left over ...
  748. @endcode
  749. @param date
  750. The string to be parsed.
  751. @param format
  752. strptime()-like format string.
  753. @param dateDef
  754. Used to fill in the date components not specified in the @a date
  755. string.
  756. @param end
  757. Will be filled with the iterator pointing to the location where the
  758. parsing stopped if the function returns @true. If the entire string
  759. was consumed, it is set to @c date.end(). Notice that this argument
  760. must be non-@NULL.
  761. @return
  762. @true if at least part of the string was parsed successfully,
  763. @false otherwise.
  764. @see Format()
  765. */
  766. bool ParseFormat(const wxString& date,
  767. const wxString& format,
  768. const wxDateTime& dateDef,
  769. wxString::const_iterator *end);
  770. /**
  771. @overload
  772. */
  773. bool ParseFormat(const wxString& date,
  774. const wxString& format,
  775. wxString::const_iterator *end);
  776. /**
  777. @overload
  778. */
  779. bool ParseFormat(const wxString& date, wxString::const_iterator *end);
  780. /**
  781. This function parses the string containing the date and time in ISO
  782. 8601 combined format @c "YYYY-MM-DDTHH:MM:SS". The separator between
  783. the date and time parts must be equal to @a sep for the function to
  784. succeed.
  785. @return @true if the entire string was parsed successfully, @false
  786. otherwise.
  787. */
  788. bool ParseISOCombined(const wxString& date, char sep = 'T');
  789. /**
  790. This function parses the date in ISO 8601 format @c "YYYY-MM-DD".
  791. @return @true if the entire string was parsed successfully, @false
  792. otherwise.
  793. */
  794. bool ParseISODate(const wxString& date);
  795. /**
  796. This function parses the time in ISO 8601 format @c "HH:MM:SS".
  797. @return @true if the entire string was parsed successfully, @false
  798. otherwise.
  799. */
  800. bool ParseISOTime(const wxString& date);
  801. /**
  802. Parses the string @a date looking for a date formatted according to the
  803. RFC 822 in it. The exact description of this format may, of course, be
  804. found in the RFC (section 5), but, briefly, this is the format used in
  805. the headers of Internet email messages and one of the most common
  806. strings expressing date in this format may be something like
  807. @c "Sat, 18 Dec 1999 00:48:30 +0100".
  808. Returns @NULL if the conversion failed, otherwise return the pointer to
  809. the character immediately following the part of the string which could
  810. be parsed. If the entire string contains only the date in RFC 822
  811. format, the returned pointer will be pointing to a @c NUL character.
  812. This function is intentionally strict, it will return an error for any
  813. string which is not RFC 822 compliant. If you need to parse date
  814. formatted in more free ways, you should use ParseDateTime() or
  815. ParseDate() instead.
  816. See ParseFormat() for the description of function parameters and return
  817. value.
  818. */
  819. bool ParseRfc822Date(const wxString& date, wxString::const_iterator *end);
  820. /**
  821. This functions is like ParseDateTime(), but only allows the time to be
  822. specified in the input string.
  823. See ParseFormat() for the description of function parameters and return
  824. value.
  825. */
  826. bool ParseTime(const wxString& time, wxString::const_iterator *end);
  827. //@}
  828. /**
  829. @name Calendar Calculations
  830. The functions in this section perform the basic calendar calculations,
  831. mostly related to the week days. They allow to find the given week day
  832. in the week with given number (either in the month or in the year) and
  833. so on.
  834. None of the functions in this section modify the time part of the
  835. wxDateTime, they only work with the date part of it.
  836. */
  837. //@{
  838. /**
  839. Returns the copy of this object to which SetToLastMonthDay() was
  840. applied.
  841. */
  842. wxDateTime GetLastMonthDay(Month month = Inv_Month,
  843. int year = Inv_Year) const;
  844. /**
  845. Returns the copy of this object to which SetToLastWeekDay() was
  846. applied.
  847. */
  848. wxDateTime GetLastWeekDay(WeekDay weekday, Month month = Inv_Month,
  849. int year = Inv_Year);
  850. /**
  851. Returns the copy of this object to which SetToNextWeekDay() was
  852. applied.
  853. */
  854. wxDateTime GetNextWeekDay(WeekDay weekday) const;
  855. /**
  856. Returns the copy of this object to which SetToPrevWeekDay() was
  857. applied.
  858. */
  859. wxDateTime GetPrevWeekDay(WeekDay weekday) const;
  860. /**
  861. Returns the copy of this object to which SetToWeekDay() was applied.
  862. */
  863. wxDateTime GetWeekDay(WeekDay weekday, int n = 1, Month month = Inv_Month,
  864. int year = Inv_Year) const;
  865. /**
  866. Returns the copy of this object to which SetToWeekDayInSameWeek() was
  867. applied.
  868. */
  869. wxDateTime GetWeekDayInSameWeek(WeekDay weekday,
  870. WeekFlags flags = Monday_First) const;
  871. /**
  872. Returns the copy of this object to which SetToYearDay() was applied.
  873. */
  874. wxDateTime GetYearDay(wxDateTime_t yday) const;
  875. /**
  876. Sets the date to the last day in the specified month (the current one
  877. by default).
  878. @return The reference to the modified object itself.
  879. */
  880. wxDateTime& SetToLastMonthDay(Month month = Inv_Month, int year = Inv_Year);
  881. /**
  882. The effect of calling this function is the same as of calling
  883. @c SetToWeekDay(-1, weekday, month, year). The date will be set to the
  884. last @a weekday in the given month and year (the current ones by
  885. default). Always returns @true.
  886. */
  887. bool SetToLastWeekDay(WeekDay weekday, Month month = Inv_Month,
  888. int year = Inv_Year);
  889. /**
  890. Sets the date so that it will be the first @a weekday following the
  891. current date.
  892. @return The reference to the modified object itself.
  893. */
  894. wxDateTime& SetToNextWeekDay(WeekDay weekday);
  895. /**
  896. Sets the date so that it will be the last @a weekday before the current
  897. date.
  898. @return The reference to the modified object itself.
  899. */
  900. wxDateTime& SetToPrevWeekDay(WeekDay weekday);
  901. /**
  902. Sets the date to the @e n-th @a weekday in the given month of the given
  903. year (the current month and year are used by default). The parameter
  904. @a n may be either positive (counting from the beginning of the month)
  905. or negative (counting from the end of it).
  906. For example, SetToWeekDay(2, wxDateTime::Wed) will set the date to the
  907. second Wednesday in the current month and
  908. SetToWeekDay(-1, wxDateTime::Sun) will set the date to the last Sunday
  909. in the current month.
  910. @return @true if the date was modified successfully, @false otherwise
  911. meaning that the specified date doesn't exist.
  912. */
  913. bool SetToWeekDay(WeekDay weekday, int n = 1,
  914. Month month = Inv_Month, int year = Inv_Year);
  915. /**
  916. Adjusts the date so that it will still lie in the same week as before,
  917. but its week day will be the given one.
  918. @return The reference to the modified object itself.
  919. */
  920. wxDateTime& SetToWeekDayInSameWeek(WeekDay weekday,
  921. WeekFlags flags = Monday_First);
  922. /**
  923. Sets the date to the day number @a yday in the same year (i.e.\ unlike
  924. the other functions, this one does not use the current year). The day
  925. number should be in the range 1-366 for the leap years and 1-365 for
  926. the other ones.
  927. @return The reference to the modified object itself.
  928. */
  929. wxDateTime& SetToYearDay(wxDateTime_t yday);
  930. //@}
  931. /**
  932. @name Astronomical/Historical Functions
  933. Some degree of support for the date units used in astronomy and/or
  934. history is provided. You can construct a wxDateTime object from a
  935. JDN and you may also get its JDN, MJD or Rata Die number from it.
  936. Related functions in other groups: wxDateTime(double), Set(double)
  937. */
  938. //@{
  939. /**
  940. Synonym for GetJulianDayNumber().
  941. */
  942. double GetJDN() const;
  943. /**
  944. Returns the JDN corresponding to this date. Beware of rounding errors!
  945. @see GetModifiedJulianDayNumber()
  946. */
  947. double GetJulianDayNumber() const;
  948. /**
  949. Synonym for GetModifiedJulianDayNumber().
  950. */
  951. double GetMJD() const;
  952. /**
  953. Returns the @e "Modified Julian Day Number" (MJD) which is, by
  954. definition, is equal to JDN - 2400000.5.
  955. The MJDs are simpler to work with as the integral MJDs correspond to
  956. midnights of the dates in the Gregorian calendar and not the noons like
  957. JDN. The MJD 0 represents Nov 17, 1858.
  958. */
  959. double GetModifiedJulianDayNumber() const;
  960. /**
  961. Return the @e Rata Die number of this date.
  962. By definition, the Rata Die number is a date specified as the number of
  963. days relative to a base date of December 31 of the year 0. Thus January
  964. 1 of the year 1 is Rata Die day 1.
  965. */
  966. double GetRataDie() const;
  967. //@}
  968. /**
  969. @name Time Zone and DST Support
  970. Please see the @ref overview_datetime_timezones "time zone overview"
  971. for more information about time zones. Normally, these functions should
  972. be rarely used.
  973. Related functions in other groups: GetBeginDST(), GetEndDST()
  974. */
  975. //@{
  976. /**
  977. Transform the date from the given time zone to the local one. If
  978. @a noDST is @true, no DST adjustments will be made.
  979. @return The date in the local time zone.
  980. */
  981. wxDateTime FromTimezone(const TimeZone& tz, bool noDST = false) const;
  982. /**
  983. Returns @true if the DST is applied for this date in the given country.
  984. @see GetBeginDST(), GetEndDST()
  985. */
  986. int IsDST(Country country = Country_Default) const;
  987. /**
  988. Same as FromTimezone() but modifies the object in place.
  989. */
  990. wxDateTime& MakeFromTimezone(const TimeZone& tz, bool noDST = false);
  991. /**
  992. Modifies the object in place to represent the date in another time
  993. zone. If @a noDST is @true, no DST adjustments will be made.
  994. */
  995. wxDateTime& MakeTimezone(const TimeZone& tz, bool noDST = false);
  996. /**
  997. This is the same as calling MakeTimezone() with the argument @c GMT0.
  998. */
  999. wxDateTime& MakeUTC(bool noDST = false);
  1000. /**
  1001. Transform the date to the given time zone. If @a noDST is @true, no DST
  1002. adjustments will be made.
  1003. @return The date in the new time zone.
  1004. */
  1005. wxDateTime ToTimezone(const TimeZone& tz, bool noDST = false) const;
  1006. /**
  1007. This is the same as calling ToTimezone() with the argument @c GMT0.
  1008. */
  1009. wxDateTime ToUTC(bool noDST = false) const;
  1010. //@}
  1011. /**
  1012. Converts the year in absolute notation (i.e.\ a number which can be
  1013. negative, positive or zero) to the year in BC/AD notation. For the
  1014. positive years, nothing is done, but the year 0 is year 1 BC and so for
  1015. other years there is a difference of 1.
  1016. This function should be used like this:
  1017. @code
  1018. wxDateTime dt(...);
  1019. int y = dt.GetYear();
  1020. printf("The year is %d%s", wxDateTime::ConvertYearToBC(y), y > 0 ? "AD" : "BC");
  1021. @endcode
  1022. */
  1023. static int ConvertYearToBC(int year);
  1024. /**
  1025. Returns the translations of the strings @c AM and @c PM used for time
  1026. formatting for the current locale. Either of the pointers may be @NULL
  1027. if the corresponding value is not needed.
  1028. */
  1029. static void GetAmPmStrings(wxString* am, wxString* pm);
  1030. /**
  1031. Get the beginning of DST for the given country in the given year
  1032. (current one by default). This function suffers from limitations
  1033. described in the @ref overview_datetime_dst "DST overview".
  1034. @see GetEndDST()
  1035. */
  1036. static wxDateTime GetBeginDST(int year = Inv_Year,
  1037. Country country = Country_Default);
  1038. /**
  1039. Returns the end of DST for the given country in the given year (current
  1040. one by default).
  1041. @see GetBeginDST()
  1042. */
  1043. static wxDateTime GetEndDST(int year = Inv_Year,
  1044. Country country = Country_Default);
  1045. /**
  1046. Get the current century, i.e.\ first two digits of the year, in given
  1047. calendar (only Gregorian is currently supported).
  1048. */
  1049. static int GetCentury(int year);
  1050. /**
  1051. Returns the current default country. The default country is used for
  1052. DST calculations, for example.
  1053. @see SetCountry()
  1054. */
  1055. static Country GetCountry();
  1056. /**
  1057. Get the current month in given calendar (only Gregorian is currently
  1058. supported).
  1059. */
  1060. static Month GetCurrentMonth(Calendar cal = Gregorian);
  1061. /**
  1062. Get the current year in given calendar (only Gregorian is currently
  1063. supported).
  1064. */
  1065. static int GetCurrentYear(Calendar cal = Gregorian);
  1066. /**
  1067. Return the standard English name of the given month.
  1068. This function always returns "January" or "Jan" for January, use
  1069. GetMonthName() to retrieve the name of the month in the users current
  1070. locale.
  1071. @param month
  1072. One of wxDateTime::Jan, ..., wxDateTime::Dec values.
  1073. @param flags
  1074. Either Name_Full (default) or Name_Abbr.
  1075. @see GetEnglishWeekDayName()
  1076. @since 2.9.0
  1077. */
  1078. static wxString GetEnglishMonthName(Month month,
  1079. NameFlags flags = Name_Full);
  1080. /**
  1081. Return the standard English name of the given week day.
  1082. This function always returns "Monday" or "Mon" for Monday, use
  1083. GetWeekDayName() to retrieve the name of the month in the users current
  1084. locale.
  1085. @param weekday
  1086. One of wxDateTime::Sun, ..., wxDateTime::Sat values.
  1087. @param flags
  1088. Either Name_Full (default) or Name_Abbr.
  1089. @see GetEnglishMonthName()
  1090. @since 2.9.0
  1091. */
  1092. static wxString GetEnglishWeekDayName(WeekDay weekday,
  1093. NameFlags flags = Name_Full);
  1094. /**
  1095. Gets the full (default) or abbreviated name of the given month.
  1096. This function returns the name in the current locale, use
  1097. GetEnglishMonthName() to get the untranslated name if necessary.
  1098. @param month
  1099. One of wxDateTime::Jan, ..., wxDateTime::Dec values.
  1100. @param flags
  1101. Either Name_Full (default) or Name_Abbr.
  1102. @see GetWeekDayName()
  1103. */
  1104. static wxString GetMonthName(Month month, NameFlags flags = Name_Full);
  1105. /**
  1106. Returns the number of days in the given year. The only supported value
  1107. for @a cal currently is @c Gregorian.
  1108. */
  1109. static wxDateTime_t GetNumberOfDays(int year, Calendar cal = Gregorian);
  1110. /**
  1111. Returns the number of days in the given month of the given year. The
  1112. only supported value for @a cal currently is @c Gregorian.
  1113. */
  1114. static wxDateTime_t GetNumberOfDays(Month month, int year = Inv_Year,
  1115. Calendar cal = Gregorian);
  1116. /**
  1117. Returns the current time.
  1118. */
  1119. static time_t GetTimeNow();
  1120. /**
  1121. Returns the current time broken down using the buffer whose address is
  1122. passed to the function with @a tm to store the result.
  1123. */
  1124. static tm* GetTmNow(struct tm *tm);
  1125. /**
  1126. Returns the current time broken down. Note that this function returns a
  1127. pointer to a static buffer that's reused by calls to this function and
  1128. certain C library functions (e.g. localtime). If there is any chance
  1129. your code might be used in a multi-threaded application, you really
  1130. should use GetTmNow(struct tm *) instead.
  1131. */
  1132. static tm* GetTmNow();
  1133. /**
  1134. Gets the full (default) or abbreviated name of the given week day.
  1135. This function returns the name in the current locale, use
  1136. GetEnglishWeekDayName() to get the untranslated name if necessary.
  1137. @param weekday
  1138. One of wxDateTime::Sun, ..., wxDateTime::Sat values.
  1139. @param flags
  1140. Either Name_Full (default) or Name_Abbr.
  1141. @see GetMonthName()
  1142. */
  1143. static wxString GetWeekDayName(WeekDay weekday,
  1144. NameFlags flags = Name_Full);
  1145. /**
  1146. Returns @true if DST was used in the given year (the current one by
  1147. default) in the given country.
  1148. */
  1149. static bool IsDSTApplicable(int year = Inv_Year,
  1150. Country country = Country_Default);
  1151. /**
  1152. Returns @true if the @a year is a leap one in the specified calendar.
  1153. This functions supports Gregorian and Julian calendars.
  1154. */
  1155. static bool IsLeapYear(int year = Inv_Year, Calendar cal = Gregorian);
  1156. /**
  1157. This function returns @true if the specified (or default) country is
  1158. one of Western European ones. It is used internally by wxDateTime to
  1159. determine the DST convention and date and time formatting rules.
  1160. */
  1161. static bool IsWestEuropeanCountry(Country country = Country_Default);
  1162. /**
  1163. Returns the object corresponding to the current time.
  1164. Example:
  1165. @code
  1166. wxDateTime now = wxDateTime::Now();
  1167. printf("Current time in Paris:\t%s\n", now.Format("%c", wxDateTime::CET).c_str());
  1168. @endcode
  1169. @note This function is accurate up to seconds. UNow() can be used if
  1170. better precision is required.
  1171. @see Today()
  1172. */
  1173. static wxDateTime Now();
  1174. /**
  1175. Sets the country to use by default. This setting influences the DST
  1176. calculations, date formatting and other things.
  1177. @see GetCountry()
  1178. */
  1179. static void SetCountry(Country country);
  1180. /**
  1181. Set the date to the given @a weekday in the week number @a numWeek of
  1182. the given @a year . The number should be in range 1-53.
  1183. Note that the returned date may be in a different year than the one
  1184. passed to this function because both the week 1 and week 52 or 53 (for
  1185. leap years) contain days from different years. See GetWeekOfYear() for
  1186. the explanation of how the year weeks are counted.
  1187. */
  1188. static wxDateTime SetToWeekOfYear(int year, wxDateTime_t numWeek,
  1189. WeekDay weekday = Mon);
  1190. /**
  1191. Returns the object corresponding to the midnight of the current day
  1192. (i.e.\ the same as Now(), but the time part is set to 0).
  1193. @see Now()
  1194. */
  1195. static wxDateTime Today();
  1196. /**
  1197. Returns the object corresponding to the current UTC time including the
  1198. milliseconds.
  1199. Notice that unlike Now(), this method creates a wxDateTime object
  1200. corresponding to UTC, not local, time.
  1201. @see Now(), wxGetUTCTimeMillis()
  1202. */
  1203. static wxDateTime UNow();
  1204. };
  1205. /**
  1206. Global instance of an empty wxDateTime object.
  1207. @todo Would it be better to rename this wxNullDateTime so it's consistent
  1208. with the rest of the "empty/invalid/null" global objects?
  1209. */
  1210. const wxDateTime wxDefaultDateTime;
  1211. /*
  1212. wxInvalidDateTime is an alias for wxDefaultDateTime.
  1213. */
  1214. #define wxInvalidDateTime wxDefaultDateTime
  1215. /**
  1216. @class wxDateTimeWorkDays
  1217. @todo Write wxDateTimeWorkDays documentation.
  1218. @library{wxbase}
  1219. @category{data}
  1220. */
  1221. class wxDateTimeWorkDays
  1222. {
  1223. public:
  1224. };
  1225. /**
  1226. @class wxDateSpan
  1227. This class is a "logical time span" and is useful for implementing program
  1228. logic for such things as "add one month to the date" which, in general,
  1229. doesn't mean to add 60*60*24*31 seconds to it, but to take the same date
  1230. the next month (to understand that this is indeed different consider adding
  1231. one month to Feb, 15 -- we want to get Mar, 15, of course).
  1232. When adding a month to the date, all lesser components (days, hours, ...)
  1233. won't be changed unless the resulting date would be invalid: for example,
  1234. Jan 31 + 1 month will be Feb 28, not (non-existing) Feb 31.
  1235. Because of this feature, adding and subtracting back again the same
  1236. wxDateSpan will @b not, in general, give back the original date: Feb 28 - 1
  1237. month will be Jan 28, not Jan 31!
  1238. wxDateSpan objects can be either positive or negative. They may be
  1239. multiplied by scalars which multiply all deltas by the scalar: i.e.
  1240. 2*(1 month and 1 day) is 2 months and 2 days. They can be added together
  1241. with wxDateTime or wxTimeSpan, but the type of result is different for each
  1242. case.
  1243. @warning If you specify both weeks and days, the total number of days added
  1244. will be 7*weeks + days! See also GetTotalDays().
  1245. Equality operators are defined for wxDateSpans. Two wxDateSpans are equal
  1246. if and only if they both give the same target date when added to @b every
  1247. source date. Thus wxDateSpan::Months(1) is not equal to
  1248. wxDateSpan::Days(30), because they don't give the same date when added to
  1249. Feb 1st. But wxDateSpan::Days(14) is equal to wxDateSpan::Weeks(2).
  1250. Finally, notice that for adding hours, minutes and so on you don't need
  1251. this class at all: wxTimeSpan will do the job because there are no
  1252. subtleties associated with those (we don't support leap seconds).
  1253. @library{wxbase}
  1254. @category{data}
  1255. @see @ref overview_datetime, wxDateTime
  1256. */
  1257. class wxDateSpan
  1258. {
  1259. public:
  1260. /**
  1261. Constructs the date span object for the given number of years, months,
  1262. weeks and days. Note that the weeks and days add together if both are
  1263. given.
  1264. */
  1265. wxDateSpan(int years = 0, int months = 0, int weeks = 0, int days = 0);
  1266. /**
  1267. Returns the sum of two date spans.
  1268. @return A new wxDateSpan object with the result.
  1269. */
  1270. wxDateSpan Add(const wxDateSpan& other) const;
  1271. /**
  1272. Adds the given wxDateSpan to this wxDateSpan and returns a reference
  1273. to itself.
  1274. */
  1275. wxDateSpan& Add(const wxDateSpan& other);
  1276. /**
  1277. Returns a date span object corresponding to one day.
  1278. @see Days()
  1279. */
  1280. static wxDateSpan Day();
  1281. /**
  1282. Returns a date span object corresponding to the given number of days.
  1283. @see Day()
  1284. */
  1285. static wxDateSpan Days(int days);
  1286. /**
  1287. Returns the number of days (not counting the weeks component) in this
  1288. date span.
  1289. @see GetTotalDays()
  1290. */
  1291. int GetDays() const;
  1292. /**
  1293. Returns the number of the months (not counting the years) in this date
  1294. span.
  1295. */
  1296. int GetMonths() const;
  1297. /**
  1298. Returns the combined number of months in this date span, counting both
  1299. years and months.
  1300. @see GetYears(), GetMonths()
  1301. @since 2.9.5
  1302. */
  1303. int GetTotalMonths() const;
  1304. /**
  1305. Returns the combined number of days in this date span, counting both
  1306. weeks and days. This doesn't take months or years into account.
  1307. @see GetWeeks(), GetDays()
  1308. */
  1309. int GetTotalDays() const;
  1310. /**
  1311. Returns the number of weeks in this date span.
  1312. @see GetTotalDays()
  1313. */
  1314. int GetWeeks() const;
  1315. /**
  1316. Returns the number of years in this date span.
  1317. */
  1318. int GetYears() const;
  1319. /**
  1320. Returns a date span object corresponding to one month.
  1321. @see Months()
  1322. */
  1323. static wxDateSpan Month();
  1324. /**
  1325. Returns a date span object corresponding to the given number of months.
  1326. @see Month()
  1327. */
  1328. static wxDateSpan Months(int mon);
  1329. /**
  1330. Returns the product of the date span by the specified @a factor. The
  1331. product is computed by multiplying each of the components by the
  1332. @a factor.
  1333. @return A new wxDateSpan object with the result.
  1334. */
  1335. wxDateSpan Multiply(int factor) const;
  1336. /**
  1337. Multiplies this date span by the specified @a factor. The product is
  1338. computed by multiplying each of the components by the @a factor.
  1339. @return A reference to this wxDateSpan object modified in place.
  1340. */
  1341. wxDateSpan& Multiply(int factor);
  1342. /**
  1343. Changes the sign of this date span.
  1344. @see Negate()
  1345. */
  1346. wxDateSpan& Neg();
  1347. /**
  1348. Returns a date span with the opposite sign.
  1349. @see Neg()
  1350. */
  1351. wxDateSpan Negate() const;
  1352. /**
  1353. Sets the number of days (without modifying any other components) in
  1354. this date span.
  1355. */
  1356. wxDateSpan& SetDays(int n);
  1357. /**
  1358. Sets the number of months (without modifying any other components) in
  1359. this date span.
  1360. */
  1361. wxDateSpan& SetMonths(int n);
  1362. /**
  1363. Sets the number of weeks (without modifying any other components) in
  1364. this date span.
  1365. */
  1366. wxDateSpan& SetWeeks(int n);
  1367. /**
  1368. Sets the number of years (without modifying any other components) in
  1369. this date span.
  1370. */
  1371. wxDateSpan& SetYears(int n);
  1372. /**
  1373. Returns the difference of two date spans.
  1374. @return A new wxDateSpan object with the result.
  1375. */
  1376. wxDateSpan Subtract(const wxDateSpan& other) const;
  1377. /**
  1378. Subtracts the given wxDateSpan to this wxDateSpan and returns a
  1379. reference to itself.
  1380. */
  1381. wxDateSpan& Subtract(const wxDateSpan& other);
  1382. /**
  1383. Returns a date span object corresponding to one week.
  1384. @see Weeks()
  1385. */
  1386. static wxDateSpan Week();
  1387. /**
  1388. Returns a date span object corresponding to the given number of weeks.
  1389. @see Week()
  1390. */
  1391. static wxDateSpan Weeks(int weeks);
  1392. /**
  1393. Returns a date span object corresponding to one year.
  1394. @see Years()
  1395. */
  1396. static wxDateSpan Year();
  1397. /**
  1398. Returns a date span object corresponding to the given number of years.
  1399. @see Year()
  1400. */
  1401. static wxDateSpan Years(int years);
  1402. /**
  1403. Adds the given wxDateSpan to this wxDateSpan and returns the result.
  1404. */
  1405. wxDateSpan& operator+=(const wxDateSpan& other);
  1406. /**
  1407. Subtracts the given wxDateSpan to this wxDateSpan and returns the
  1408. result.
  1409. */
  1410. wxDateSpan& operator-=(const wxDateSpan& other);
  1411. /**
  1412. Changes the sign of this date span.
  1413. @see Negate()
  1414. */
  1415. wxDateSpan& operator-();
  1416. /**
  1417. Multiplies this date span by the specified @a factor. The product is
  1418. computed by multiplying each of the components by the @a factor.
  1419. @return A reference to this wxDateSpan object modified in place.
  1420. */
  1421. wxDateSpan& operator*=(int factor);
  1422. /**
  1423. Returns @true if this date span is different from the other one.
  1424. */
  1425. bool operator!=(const wxDateSpan& other) const;
  1426. /**
  1427. Returns @true if this date span is equal to the other one. Two date
  1428. spans are considered equal if and only if they have the same number of
  1429. years and months and the same total number of days (counting both days
  1430. and weeks).
  1431. */
  1432. bool operator==(const wxDateSpan& other) const;
  1433. };
  1434. /**
  1435. @class wxTimeSpan
  1436. wxTimeSpan class represents a time interval.
  1437. @library{wxbase}
  1438. @category{data}
  1439. @see @ref overview_datetime, wxDateTime
  1440. */
  1441. class wxTimeSpan
  1442. {
  1443. public:
  1444. /**
  1445. Default constructor, constructs a zero timespan.
  1446. */
  1447. wxTimeSpan();
  1448. /**
  1449. Constructs timespan from separate values for each component, with the
  1450. date set to 0. Hours are not restricted to 0-24 range, neither are
  1451. minutes, seconds or milliseconds.
  1452. */
  1453. wxTimeSpan(long hours, long min = 0, wxLongLong sec = 0, wxLongLong msec = 0);
  1454. /**
  1455. Returns the absolute value of the timespan: does not modify the object.
  1456. */
  1457. wxTimeSpan Abs() const;
  1458. /**
  1459. Returns the sum of two time spans.
  1460. @return A new wxDateSpan object with the result.
  1461. */
  1462. wxTimeSpan Add(const wxTimeSpan& diff) const;
  1463. /**
  1464. Adds the given wxTimeSpan to this wxTimeSpan and returns a reference
  1465. to itself.
  1466. */
  1467. wxTimeSpan& Add(const wxTimeSpan& diff);
  1468. /**
  1469. Returns the timespan for one day.
  1470. */
  1471. static wxTimeSpan Day();
  1472. /**
  1473. Returns the timespan for the given number of days.
  1474. */
  1475. static wxTimeSpan Days(long days);
  1476. /**
  1477. Returns the string containing the formatted representation of the time
  1478. span. The following format specifiers are allowed after %:
  1479. - @c H - Number of Hours
  1480. - @c M - Number of Minutes
  1481. - @c S - Number of Seconds
  1482. - @c l - Number of Milliseconds
  1483. - @c D - Number of Days
  1484. - @c E - Number of Weeks
  1485. - @c % - The percent character
  1486. Note that, for example, the number of hours in the description above is
  1487. not well defined: it can be either the total number of hours (for
  1488. example, for a time span of 50 hours this would be 50) or just the hour
  1489. part of the time span, which would be 2 in this case as 50 hours is
  1490. equal to 2 days and 2 hours.
  1491. wxTimeSpan resolves this ambiguity in the following way: if there had
  1492. been, indeed, the @c %D format specified preceding the @c %H, then it
  1493. is interpreted as 2. Otherwise, it is 50.
  1494. The same applies to all other format specifiers: if they follow a
  1495. specifier of larger unit, only the rest part is taken, otherwise the
  1496. full value is used.
  1497. */
  1498. wxString Format(const wxString& format = wxDefaultTimeSpanFormat) const;
  1499. /**
  1500. Returns the difference in number of days.
  1501. */
  1502. int GetDays() const;
  1503. /**
  1504. Returns the difference in number of hours.
  1505. */
  1506. int GetHours() const;
  1507. /**
  1508. Returns the difference in number of milliseconds.
  1509. */
  1510. wxLongLong GetMilliseconds() const;
  1511. /**
  1512. Returns the difference in number of minutes.
  1513. */
  1514. int GetMinutes() const;
  1515. /**
  1516. Returns the difference in number of seconds.
  1517. */
  1518. wxLongLong GetSeconds() const;
  1519. /**
  1520. Returns the internal representation of timespan.
  1521. */
  1522. wxLongLong GetValue() const;
  1523. /**
  1524. Returns the difference in number of weeks.
  1525. */
  1526. int GetWeeks() const;
  1527. /**
  1528. Returns the timespan for one hour.
  1529. */
  1530. static wxTimeSpan Hour();
  1531. /**
  1532. Returns the timespan for the given number of hours.
  1533. */
  1534. static wxTimeSpan Hours(long hours);
  1535. /**
  1536. Returns @true if two timespans are equal.
  1537. */
  1538. bool IsEqualTo(const wxTimeSpan& ts) const;
  1539. /**
  1540. Compares two timespans: works with the absolute values, i.e.\ -2 hours
  1541. is longer than 1 hour. Also, it will return @false if the timespans are
  1542. equal in absolute value.
  1543. */
  1544. bool IsLongerThan(const wxTimeSpan& ts) const;
  1545. /**
  1546. Returns @true if the timespan is negative.
  1547. */
  1548. bool IsNegative() const;
  1549. /**
  1550. Returns @true if the timespan is empty.
  1551. */
  1552. bool IsNull() const;
  1553. /**
  1554. Returns @true if the timespan is positive.
  1555. */
  1556. bool IsPositive() const;
  1557. /**
  1558. Compares two timespans: works with the absolute values, i.e.\ 1 hour is
  1559. shorter than -2 hours. Also, it will return @false if the timespans are
  1560. equal in absolute value.
  1561. */
  1562. bool IsShorterThan(const wxTimeSpan& ts) const;
  1563. /**
  1564. Returns the timespan for one millisecond.
  1565. */
  1566. static wxTimeSpan Millisecond();
  1567. /**
  1568. Returns the timespan for the given number of milliseconds.
  1569. */
  1570. static wxTimeSpan Milliseconds(wxLongLong ms);
  1571. /**
  1572. Returns the timespan for one minute.
  1573. */
  1574. static wxTimeSpan Minute();
  1575. /**
  1576. Returns the timespan for the given number of minutes.
  1577. */
  1578. static wxTimeSpan Minutes(long min);
  1579. /**
  1580. Returns the product of this time span by @a n.
  1581. @return A new wxTimeSpan object with the result.
  1582. */
  1583. wxTimeSpan Multiply(int n) const;
  1584. /**
  1585. Multiplies this time span by @a n.
  1586. @return A reference to this wxTimeSpan object modified in place.
  1587. */
  1588. wxTimeSpan& Multiply(int n);
  1589. /**
  1590. Negate the value of the timespan.
  1591. @see Negate()
  1592. */
  1593. wxTimeSpan& Neg();
  1594. /**
  1595. Returns timespan with inverted sign.
  1596. @see Neg()
  1597. */
  1598. wxTimeSpan Negate() const;
  1599. /**
  1600. Returns the timespan for one second.
  1601. */
  1602. static wxTimeSpan Second();
  1603. /**
  1604. Returns the timespan for the given number of seconds.
  1605. */
  1606. static wxTimeSpan Seconds(wxLongLong sec);
  1607. /**
  1608. Returns the difference of two time spans.
  1609. @return A new wxDateSpan object with the result.
  1610. */
  1611. wxTimeSpan Subtract(const wxTimeSpan& diff) const;
  1612. /**
  1613. Subtracts the given wxTimeSpan to this wxTimeSpan and returns a
  1614. reference to itself.
  1615. */
  1616. wxTimeSpan& Subtract(const wxTimeSpan& diff);
  1617. /**
  1618. Returns the timespan for one week.
  1619. */
  1620. static wxTimeSpan Week();
  1621. /**
  1622. Returns the timespan for the given number of weeks.
  1623. */
  1624. static wxTimeSpan Weeks(long weeks);
  1625. /**
  1626. Adds the given wxTimeSpan to this wxTimeSpan and returns the result.
  1627. */
  1628. wxTimeSpan& operator+=(const wxTimeSpan& diff);
  1629. /**
  1630. Multiplies this time span by @a n.
  1631. @return A reference to this wxTimeSpan object modified in place.
  1632. */
  1633. wxTimeSpan& operator*=(int n);
  1634. /**
  1635. Negate the value of the timespan.
  1636. @see Negate()
  1637. */
  1638. wxTimeSpan& operator-();
  1639. /**
  1640. Subtracts the given wxTimeSpan to this wxTimeSpan and returns the
  1641. result.
  1642. */
  1643. wxTimeSpan& operator-=(const wxTimeSpan& diff);
  1644. };
  1645. /**
  1646. @class wxDateTimeHolidayAuthority
  1647. @todo Write wxDateTimeHolidayAuthority documentation.
  1648. @library{wxbase}
  1649. @category{data}
  1650. */
  1651. class wxDateTimeHolidayAuthority
  1652. {
  1653. public:
  1654. };