wxDateTime class represents an absolute moment in the time.
+ The type @c wxDateTime_t is typedefed as <tt>unsigned short</tt> and is
+ used to contain the number of years, hours, minutes, seconds and
+ milliseconds.
+
+
+ @section datetime_constants Constants
+
+ Global constant wxDefaultDateTime and synonym for it wxInvalidDateTime are
+ defined. This constant will be different from any valid wxDateTime object.
+
+ All the following constants are defined inside wxDateTime class (i.e., to
+ refer to them you should prepend their names with "wxDateTime::").
+
+ Time zone symbolic names:
+
+ @code
+ enum TZ
+ {
+ // the time in the current time zone
+ Local,
+
+ // zones from GMT (= Greenwhich Mean Time): they're guaranteed to be
+ // consequent numbers, so writing something like `GMT0 + offset' is
+ // safe if abs(offset) <= 12
+
+ // underscore stands for minus
+ GMT_12, GMT_11, GMT_10, GMT_9, GMT_8, GMT_7,
+ GMT_6, GMT_5, GMT_4, GMT_3, GMT_2, GMT_1,
+ GMT0,
+ GMT1, GMT2, GMT3, GMT4, GMT5, GMT6,
+ GMT7, GMT8, GMT9, GMT10, GMT11, GMT12, GMT13,
+ // Note that GMT12 and GMT_12 are not the same: there is a difference
+ // of exactly one day between them
+
+ // some symbolic names for TZ
+
+ // Europe
+ WET = GMT0, // Western Europe Time
+ WEST = GMT1, // Western Europe Summer Time
+ CET = GMT1, // Central Europe Time
+ CEST = GMT2, // Central Europe Summer Time
+ EET = GMT2, // Eastern Europe Time
+ EEST = GMT3, // Eastern Europe Summer Time
+ MSK = GMT3, // Moscow Time
+ MSD = GMT4, // Moscow Summer Time
+
+ // US and Canada
+ AST = GMT_4, // Atlantic Standard Time
+ ADT = GMT_3, // Atlantic Daylight Time
+ EST = GMT_5, // Eastern Standard Time
+ EDT = GMT_4, // Eastern Daylight Saving Time
+ CST = GMT_6, // Central Standard Time
+ CDT = GMT_5, // Central Daylight Saving Time
+ MST = GMT_7, // Mountain Standard Time
+ MDT = GMT_6, // Mountain Daylight Saving Time
+ PST = GMT_8, // Pacific Standard Time
+ PDT = GMT_7, // Pacific Daylight Saving Time
+ HST = GMT_10, // Hawaiian Standard Time
+ AKST = GMT_9, // Alaska Standard Time
+ AKDT = GMT_8, // Alaska Daylight Saving Time
+
+ // Australia
+
+ A_WST = GMT8, // Western Standard Time
+ A_CST = GMT13 + 1, // Central Standard Time (+9.5)
+ A_EST = GMT10, // Eastern Standard Time
+ A_ESST = GMT11, // Eastern Summer Time
+
+ // New Zealand
+ NZST = GMT12, // Standard Time
+ NZDT = GMT13, // Daylight Saving Time
+
+ // Universal Coordinated Time = the new and politically correct name
+ // for GMT
+ UTC = GMT0
+ };
+ @endcode
+
+ Month names: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec and
+ Inv_Month for an invalid month are the values of @c wxDateTime::Month enum.
+
+ Likewise, Sun, Mon, Tue, Wed, Thu, Fri, Sat, and Inv_WeekDay are the values
+ in @c wxDateTime::WeekDay enum.
+
+ Finally, Inv_Year is defined to be an invalid value for year parameter.
+
+ GetMonthName() and GetWeekDayName() functions use the following flags:
+
+ @code
+ enum NameFlags
+ {
+ Name_Full = 0x01, // return full name
+ Name_Abbr = 0x02 // return abbreviated name
+ };
+ @endcode
+
+ Several functions accept an extra parameter specifying the calendar to use
+ (although most of them only support now the Gregorian calendar). This
+ parameters is one of the following values:
+
+ @code
+ enum Calendar
+ {
+ Gregorian, // calendar currently in use in Western countries
+ Julian // calendar in use since -45 until the 1582 (or later)
+ };
+ @endcode
+
+ Date calculations often depend on the country and wxDateTime allows to set
+ the country whose conventions should be used using SetCountry(). It takes
+ one of the following values as parameter:
+
+ @code
+ enum Country
+ {
+ Country_Unknown, // no special information for this country
+ Country_Default, // set the default country with SetCountry() method
+ // or use the default country with any other
+
+ Country_WesternEurope_Start,
+ Country_EEC = Country_WesternEurope_Start,
+ France,
+ Germany,
+ UK,
+ Country_WesternEurope_End = UK,
+
+ Russia,
+
+ USA
+ };
+ @endcode
+
+ Different parts of the world use different conventions for the week start.
+ In some countries, the week starts on Sunday, while in others -- on Monday.
+ The ISO standard doesn't address this issue, so we support both conventions
+ in the functions whose result depends on it (GetWeekOfYear() and
+ GetWeekOfMonth()).
+
+ The desired behvaiour may be specified by giving one of the following
+ constants as argument to these functions:
+
+ @code
+ enum WeekFlags
+ {
+ Default_First, // Sunday_First for US, Monday_First for the rest
+ Monday_First, // week starts with a Monday
+ Sunday_First // week starts with a Sunday
+ };
+ @endcode
+
+
+ @section datetime_static Static Functions
+
+ All static functions either set or return the static variables of
+ wxDateSpan (the country), return the current moment, year, month or number
+ of days in it, or do some general calendar-related actions.
+
+ Please note that although several function accept an extra Calendar
+ parameter, it is currently ignored as only the Gregorian calendar is
+ supported. Future versions will support other calendars.
+
+ @beginWxPythonOnly
+ These methods are standalone functions named
+ "wxDateTime_<StaticMethodName>" in wxPython.
+ @endWxPythonOnly
+
+
+ @section datetime_formatting Date Formatting and Parsing
+
+ The date formatting and parsing functions convert wxDateTime objects to and
+ from text. The conversions to text are mostly trivial: you can either do it
+ using the default date and time representations for the current locale
+ (FormatDate() and FormatTime()), using the international standard
+ representation defined by ISO 8601 (FormatISODate(), FormatISOTime() and
+ FormatISOCombined()) or by specifying any format at all and using Format()
+ directly.
+
+ The conversions from text are more interesting, as there are much more
+ possibilities to care about. The simplest cases can be taken care of with
+ ParseFormat() which can parse any date in the given (rigid) format.
+ ParseRfc822Date() is another function for parsing dates in predefined
+ format -- the one of RFC 822 which (still...) defines the format of email
+ messages on the Internet. This format can not be described with
+ @c strptime(3)-like format strings used by Format(), hence the need for a
+ separate function.
+
+ But the most interesting functions are ParseTime(), ParseDate() and
+ ParseDateTime(). They try to parse the date and time (or only one of them)
+ in 'free' format, i.e. allow them to be specified in any of possible ways.
+ These functions will usually be used to parse the (interactive) user input
+ which is not bound to be in any predefined format. As an example,
+ ParseDateTime() can parse the strings such as "tomorrow", "March first" and
+ even "next Sunday".
+
+ Finally notice that each of the parsing functions is available in several
+ overloads: if the input string is a narrow (@c char *) string, then a
+ narrow pointer is returned. If the input string is a wide string, a wide
+ char pointer is returned. Finally, if the input parameter is a wxString, a
+ narrow char pointer is also returned for backwards compatibility but there
+ is also an additional argument of wxString::const_iterator type in which,
+ if it is not @NULL, an iterator pointing to the end of the scanned string
+ part is returned.
+
+
@library{wxbase}
@category{data}
- @see @ref overview_wxdatetimeoverview "Date classes overview", wxTimeSpan,
- wxDateSpan, wxCalendarCtrl
+ @stdobjects
+ - ::wxDefaultDateTime
+
+ @see @ref overview_datetime, wxTimeSpan, wxDateSpan, wxCalendarCtrl
*/
class wxDateTime
{
public:
/**
- Same as @ref setdate() Set
+ @name Constructors, Assignment Operators and Setters
+
+ Constructors and various Set() methods are collected here. If you
+ construct a date object from separate values for day, month and year,
+ you should use IsValid() method to check that the values were correct
+ as constructors can not return an error code.
*/
- wxDateTime(wxDateTime_t day, Month month = Inv_Month,
- int Inv_Year, wxDateTime_t hour = 0,
- wxDateTime_t minute = 0,
- wxDateTime_t second = 0,
- wxDateTime_t millisec = 0);
+ //@{
/**
- Here are the trivial accessors. Other functions, which might have to perform
- some more complicated calculations to find the answer are under the
- @ref overview_datetimecalculations "Calendar calculations" section.
- IsValid()
-
- GetTicks()
-
- GetCentury()
-
- GetYear()
-
- GetMonth()
-
- GetDay()
-
- GetWeekDay()
-
- GetHour()
-
- GetMinute()
-
- GetSecond()
-
- GetMillisecond()
-
- GetDayOfYear()
-
- GetWeekOfYear()
-
- GetWeekOfMonth()
+ Default constructor. Use one of the Set() functions to initialize the
+ object later.
+ */
+ wxDateTime();
+ /**
+ Same as Set().
- GetYearDay()
+ @beginWxPythonOnly
+ This constructor is named "wxDateTimeFromTimeT" in wxPython.
+ @endWxPythonOnly
+ */
+ wxDateTime& wxDateTime(time_t timet);
+ /**
+ Same as Set().
- IsWorkDay()
+ @beginWxPythonOnly Unsupported. @endWxPythonOnly
+ */
+ wxDateTime& wxDateTime(const struct tm& tm);
+ /**
+ Same as Set().
- IsGregorianDate()
+ @beginWxPythonOnly
+ This constructor is named "wxDateTimeFromJDN" in wxPython.
+ @endWxPythonOnly
+ */
+ wxDateTime& wxDateTime(double jdn);
+ /**
+ Same as Set().
- GetAsDOS()
+ @beginWxPythonOnly
+ This constructor is named "wxDateTimeFromHMS" in wxPython.
+ @endWxPythonOnly
*/
+ wxDateTime& wxDateTime(wxDateTime_t hour, wxDateTime_t minute = 0,
+ wxDateTime_t second = 0, wxDateTime_t millisec = 0);
+ /**
+ Same as Set().
+ @beginWxPythonOnly
+ This constructor is named "wxDateTimeFromDMY" in wxPython.
+ @endWxPythonOnly
+ */
+ wxDateTime(wxDateTime_t day, Month month = Inv_Month,
+ int year = Inv_Year, wxDateTime_t hour = 0,
+ wxDateTime_t minute = 0, wxDateTime_t second = 0,
+ wxDateTime_t millisec = 0);
- //@{
/**
- Adds the given date span to this object.
+ Reset time to midnight (00:00:00) without changing the date.
*/
- wxDateTime Add(const wxDateSpan& diff);
- const wxDateTime& Add(const wxDateSpan& diff);
- wxDateTime operator+=(const wxDateSpan& diff);
- //@}
+ wxDateTime& ResetTime();
/**
- Some degree of support for the date units used in astronomy and/or history is
- provided. You can construct a wxDateTime object from a
- @ref setjdn() JDN and you may also get its JDN,
- @ref getmodifiedjuliandaynumber() MJD or
- @ref getratadie() "Rata Die number" from it.
- @ref wxdatetimejdn() "wxDateTime(double jdn)"
-
- @ref setjdn() "Set(double jdn)"
+ Constructs the object from @a timet value holding the number of seconds
+ since Jan 1, 1970.
- GetJulianDayNumber()
-
- GetJDN()
-
- GetModifiedJulianDayNumber()
-
- GetMJD()
-
- GetRataDie()
+ @beginWxPythonOnly
+ This method is named "SetTimeT" in wxPython.
+ @endWxPythonOnly
*/
-
-
+ wxDateTime& Set(time_t timet);
/**
- The functions in this section perform the basic calendar calculations, mostly
- related to the week days. They allow to find the given week day in the
- week with given number (either in the month or in the year) and so on.
- All (non-const) functions in this section don't modify the time part of the
- wxDateTime -- they only work with the date part of it.
- SetToWeekDayInSameWeek()
-
- GetWeekDayInSameWeek()
-
- SetToNextWeekDay()
+ Sets the date and time from the broken down representation in the
+ standard @a tm structure.
- GetNextWeekDay()
-
- SetToPrevWeekDay()
-
- GetPrevWeekDay()
-
- SetToWeekDay()
-
- @ref wxDateTime::getweekday2 GetWeekDay
-
- SetToLastWeekDay()
-
- GetLastWeekDay()
-
- SetToWeekOfYear()
-
- SetToLastMonthDay()
-
- GetLastMonthDay()
-
- SetToYearDay()
-
- GetYearDay()
+ @beginWxPythonOnly Unsupported. @endWxPythonOnly
*/
-
-
+ wxDateTime& Set(const struct tm& tm);
/**
- Constructors and various @c Set() methods are collected here. If you
- construct a date object from separate values for day, month and year, you
- should use IsValid() method to check that the
- values were correct as constructors can not return an error code.
- @ref wxdatetimedef() wxDateTime
-
- @ref wxdatetimetimet() wxDateTime(time_t)
-
- @ref wxdatetimetm() "wxDateTime(struct tm)"
+ Sets the date from the so-called Julian Day Number.
- @ref wxdatetimejdn() "wxDateTime(double jdn)"
+ By definition, the Julian Day Number, usually abbreviated as JDN, of a
+ particular instant is the fractional number of days since 12 hours
+ Universal Coordinated Time (Greenwich mean noon) on January 1 of the
+ year -4712 in the Julian proleptic calendar.
- @ref wxdatetimetime() "wxDateTime(h, m, s, ms)"
-
- @ref wxdatetimedate() "wxDateTime(day, mon, year, h, m, s, ms)"
-
- SetToCurrent()
-
- @ref settimet() Set(time_t)
-
- @ref settm() "Set(struct tm)"
-
- @ref setjdn() "Set(double jdn)"
-
- @ref settime() "Set(h, m, s, ms)"
-
- @ref setdate() "Set(day, mon, year, h, m, s, ms)"
-
- @ref setfromdos() "SetFromDOS(unsigned long ddt)"
-
- ResetTime()
-
- SetYear()
-
- SetMonth()
-
- @ref setdate() SetDay
-
- SetHour()
+ @beginWxPythonOnly
+ This method is named "SetJDN" in wxPython.
+ @endWxPythonOnly
+ */
+ wxDateTime& Set(double jdn);
+ /**
+ Sets the date to be equal to Today() and the time from supplied
+ parameters.
- SetMinute()
+ @beginWxPythonOnly
+ This method is named "SetHMS" in wxPython.
+ @endWxPythonOnly
+ */
+ wxDateTime& Set(wxDateTime_t hour, wxDateTime_t minute = 0,
+ wxDateTime_t second = 0, wxDateTime_t millisec = 0);
+ /**
+ Sets the date and time from the parameters.
+ */
+ wxDateTime& Set(wxDateTime_t day, Month month = Inv_Month,
+ int year = Inv_Year, wxDateTime_t hour = 0,
+ wxDateTime_t minute = 0, wxDateTime_t second = 0,
+ wxDateTime_t millisec = 0);
- SetSecond()
+ /**
+ Sets the day without changing other date components.
+ */
+ wxDateTime& SetDay(short unsigned int);
- SetMillisecond()
+ /**
+ Sets the date from the date and time in DOS format.
+ */
+ wxDateTime& SetFromDOS(unsigned long ddt);
- @ref operatoreqtimet() operator=(time_t)
+ /**
+ Sets the hour without changing other date components.
+ */
+ wxDateTime& SetHour(short unsigned int);
- @ref operatoreqtm() "operator=(struct tm)"
+ /**
+ Sets the millisecond without changing other date components.
*/
+ wxDateTime& SetMillisecond(short unsigned int);
+ /**
+ Sets the minute without changing other date components.
+ */
+ wxDateTime& SetMinute(short unsigned int);
/**
- Converts the year in absolute notation (i.e. a number which can be negative,
- positive or zero) to the year in BC/AD notation. For the positive years,
- nothing is done, but the year 0 is year 1 BC and so for other years there is a
- difference of 1.
- This function should be used like this:
+ Sets the month without changing other date components.
*/
- static int ConvertYearToBC(int year);
+ wxDateTime& SetMonth(Month month);
/**
- These functions carry out arithmetics() on the wxDateTime
- objects. As explained in the overview, either wxTimeSpan or wxDateSpan may be
- added to wxDateTime, hence all functions are overloaded to accept both
- arguments.
- Also, both @c Add() and @c Subtract() have both const and non-const
- version. The first one returns a new object which represents the
- sum/difference of the original one with the argument while the second form
- modifies the object to which it is applied. The operators -= and += are
- defined to be equivalent to the second forms of these functions.
- @ref addts() Add(wxTimeSpan)
+ Sets the second without changing other date components.
+ */
+ wxDateTime& SetSecond(short unsigned int);
- @ref addds() Add(wxDateSpan)
+ /**
+ Sets the date and time of to the current values. Same as assigning the
+ result of Now() to this object.
+ */
+ wxDateTime& SetToCurrent();
- @ref subtractts() Subtract(wxTimeSpan)
+ /**
+ Sets the year without changing other date components.
+ */
+ wxDateTime& SetYear(int year);
- @ref subtractds() Subtract(wxDateSpan)
+ /**
+ Same as Set().
+ */
+ wxDateTime& operator=(time_t timet);
+ /**
+ Same as Set().
+ */
+ wxDateTime& operator=(const struct tm& tm);
- @ref subtractdt() Subtract(wxDateTime)
+ //@}
- @ref addts() oparator+=(wxTimeSpan)
- @ref addds() oparator+=(wxDateSpan)
- @ref subtractts() oparator-=(wxTimeSpan)
+ /**
+ @name Accessors
- @ref subtractds() oparator-=(wxDateSpan)
+ Here are the trivial accessors. Other functions, which might have to
+ perform some more complicated calculations to find the answer are under
+ the "Date Arithmetics" section.
*/
-
+ //@{
/**
- There are several function to allow date comparison. To supplement them, a few
- global operators , etc taking wxDateTime are defined.
- IsEqualTo()
-
- IsEarlierThan()
-
- IsLaterThan()
-
- IsStrictlyBetween()
+ Returns the date and time in DOS format.
+ */
+ long unsigned int GetAsDOS() const;
- IsBetween()
+ /**
+ Returns the century of this date.
+ */
+ int GetCentury(const TimeZone& tz = Local) const;
- IsSameDate()
+ /**
+ Returns the object having the same date component as this one but time
+ of 00:00:00.
- IsSameTime()
+ @since 2.8.2
- IsEqualUpTo()
+ @see ResetTime()
*/
-
+ wxDateTime GetDateOnly() const;
/**
- This function does the same as the standard ANSI C @c strftime(3) function.
- Please see its description for the meaning of @a format parameter.
- It also accepts a few wxWidgets-specific extensions: you can optionally specify
- the width of the field to follow using @c printf(3)-like syntax and the
- format specification @c %l can be used to get the number of milliseconds.
-
- @see ParseFormat()
+ Returns the day in the given timezone (local one by default).
*/
- wxString Format(const wxChar* format = wxDefaultDateTimeFormat,
- const TimeZone& tz = Local) const;
+ short unsigned int GetDay(const TimeZone& tz = Local) const;
/**
- Identical to calling Format() with @c "%x"
- argument (which means 'preferred date representation for the current locale').
+ Returns the day of the year (in 1-366 range) in the given timezone
+ (local one by default).
*/
- wxString FormatDate() const;
+ short unsigned int GetDayOfYear(const TimeZone& tz = Local) const;
/**
- Returns the combined date-time representation in the ISO 8601 format
- (YYYY-MM-DDTHH:MM:SS). The @a sep parameter default value produces the
- result exactly corresponding to the ISO standard, but it can also be useful to
- use a space as seprator if a more human-readable combined date-time
- representation is needed.
+ Returns the hour in the given timezone (local one by default).
+ */
+ short unsigned int GetHour(const TimeZone& tz = Local) const;
- @see FormatISODate(), FormatISOTime(),
- ParseISOCombined()
+ /**
+ Returns the milliseconds in the given timezone (local one by default).
*/
- wxString FormatISOCombined(char sep = 'T') const;
+ short unsigned int GetMillisecond(const TimeZone& tz = Local) const;
/**
- This function returns the date representation in the ISO 8601 format
- (YYYY-MM-DD).
+ Returns the minute in the given timezone (local one by default).
*/
- wxString FormatISODate() const;
+ short unsigned int GetMinute(const TimeZone& tz = Local) const;
/**
- This function returns the time representation in the ISO 8601 format
- (HH:MM:SS).
+ Returns the month in the given timezone (local one by default).
*/
- wxString FormatISOTime() const;
+ Month GetMonth(const TimeZone& tz = Local) const;
/**
- Identical to calling Format() with @c "%X"
- argument (which means 'preferred time representation for the current locale').
+ Returns the seconds in the given timezone (local one by default).
*/
- wxString FormatTime() const;
+ short unsigned int GetSecond(const TimeZone& tz = Local) const;
/**
- Transform the date from the given time zone to the local one. If @a noDST is
- @true, no DST adjustments will be made.
- Returns the date in the local time zone.
+ Returns the number of seconds since Jan 1, 1970. An assert failure will
+ occur if the date is not in the range covered by @c time_t type.
*/
- wxDateTime FromTimezone(const TimeZone& tz,
- bool noDST = false) const;
+ time_t GetTicks() const;
/**
- Returns the translations of the strings @c AM and @c PM used for time
- formatting for the current locale. Either of the pointers may be @NULL if
- the corresponding value is not needed.
+ Returns broken down representation of the date and time.
*/
- static void GetAmPmStrings(wxString* am, wxString* pm);
+ Tm GetTm(const TimeZone& tz = Local) const;
/**
- Returns the date and time in
- DOS
- format.
+ Returns the week day in the given timezone (local one by default).
*/
- unsigned long GetAsDOS() const;
+ WeekDay GetWeekDay(const TimeZone& tz = Local) const;
/**
- Get the beginning of DST for the given country in the given year (current one
- by default). This function suffers from limitations described in
- @ref overview_tdatedst "DST overview".
+ Returns the ordinal number of the week in the month (in 1-5 range).
- @see GetEndDST()
+ As GetWeekOfYear(), this function supports both conventions for the
+ week start. See the description of these @c WeekFlags in the
+ @ref datetime_constants section.
*/
- static wxDateTime GetBeginDST(int year = Inv_Year,
- Country country = Country_Default);
+ wxDateTime_t GetWeekOfMonth(WeekFlags flags = Monday_First,
+ const TimeZone& tz = Local) const;
/**
- Returns the century of this date.
+ Returns the number of the week of the year this date is in. The first
+ week of the year is, according to international standards, the one
+ containing Jan 4 or, equivalently, the first week which has Thursday in
+ this year. Both of these definitions are the same as saying that the
+ first week of the year must contain more than half of its days in this
+ year. Accordingly, the week number will always be in 1-53 range (52 for
+ non-leap years).
+
+ The function depends on the @ref datetime_constants "week start"
+ convention specified by the @a flags argument but its results for
+ @c Sunday_First are not well-defined as the ISO definition quoted above
+ applies to the weeks starting on Monday only.
*/
- int GetCentury(const TimeZone& tz = Local) const;
+ wxDateTime_t GetWeekOfYear(WeekFlags flags = Monday_First,
+ const TimeZone& tz = Local) const;
/**
- Returns the current default country. The default country is used for DST
- calculations, for example.
-
- @see SetCountry()
+ Returns the year in the given timezone (local one by default).
*/
- static Country GetCountry();
+ int GetYear(const TimeZone& tz = Local) const;
/**
- Get the current month in given calendar (only Gregorian is currently supported).
+ Returns @true if the given date is later than the date of adoption of
+ the Gregorian calendar in the given country (and hence the Gregorian
+ calendar calculations make sense for it).
*/
- static Month GetCurrentMonth(Calendar cal = Gregorian);
+ bool IsGregorianDate(GregorianAdoption country = Gr_Standard) const;
/**
- Get the current year in given calendar (only Gregorian is currently supported).
+ Returns @true if the object represents a valid time moment.
*/
- static int GetCurrentYear(Calendar cal = Gregorian);
+ bool IsValid() const;
/**
- Returns the object having the same date component as this one but time of
- 00:00:00.
+ Returns @true is this day is not a holiday in the given country.
+ */
+ bool IsWorkDay(Country country = Country_Default) const;
+
+ //@}
- @wxsince{2.8.2}
- @see ResetTime()
- */
- wxDateTime GetDateOnly() const;
/**
- Returns the day in the given timezone (local one by default).
+ @name Date Comparison
+
+ There are several functions to allow date comparison. To supplement
+ them, a few global operators, etc taking wxDateTime are defined.
*/
- wxDateTime_t GetDay(const TimeZone& tz = Local) const;
+ //@{
/**
- Returns the day of the year (in 1...366 range) in the given timezone
- (local one by default).
+ Returns @true if this date precedes the given one.
*/
- wxDateTime_t GetDayOfYear(const TimeZone& tz = Local) const;
+ bool IsEarlierThan(const wxDateTime& datetime) const;
/**
- Returns the end of DST for the given country in the given year (current one by
- default).
-
- @see GetBeginDST()
+ Returns @true if the two dates are strictly identical.
*/
- static wxDateTime GetEndDST(int year = Inv_Year,
- Country country = Country_Default);
+ bool IsEqualTo(const wxDateTime& datetime) const;
/**
- Returns the hour in the given timezone (local one by default).
+ Returns @true if the date is equal to another one up to the given time
+ interval, i.e. if the absolute difference between the two dates is less
+ than this interval.
*/
- wxDateTime_t GetHour(const TimeZone& tz = Local) const;
+ bool IsEqualUpTo(const wxDateTime& dt, const wxTimeSpan& ts) const;
/**
- Synonym for GetJulianDayNumber().
+ Returns @true if this date is later than the given one.
*/
- double GetJDN() const;
+ bool IsLaterThan(const wxDateTime& datetime) const;
/**
- Returns the @ref setjdn() JDN corresponding to this date. Beware
- of rounding errors!
-
- @see GetModifiedJulianDayNumber()
+ Returns @true if the date is the same without comparing the time parts.
*/
- double GetJulianDayNumber() const;
+ bool IsSameDate(const wxDateTime& dt) const;
/**
- Returns the copy of this object to which
- SetToLastMonthDay() was applied.
+ Returns @true if the time is the same (although dates may differ).
*/
- wxDateTime GetLastMonthDay(Month month = Inv_Month,
- int year = Inv_Year) const;
+ bool IsSameTime(const wxDateTime& dt) const;
/**
- Returns the copy of this object to which
- SetToLastWeekDay() was applied.
+ Returns @true if this date lies strictly between the two given dates.
+
+ @see IsBetween()
*/
- wxDateTime GetLastWeekDay(WeekDay weekday,
- Month month = Inv_Month,
- int year = Inv_Year);
+ bool IsStrictlyBetween(const wxDateTime& t1,
+ const wxDateTime& t2) const;
/**
- Synonym for GetModifiedJulianDayNumber().
+ Returns @true if IsStrictlyBetween() is @true or if the date is equal
+ to one of the limit values.
+
+ @see IsStrictlyBetween()
*/
- double GetMJD() const;
+ bool IsBetween(const wxDateTime& t1, const wxDateTime& t2) const;
+
+ //@}
+
+
/**
- Returns the milliseconds in the given timezone (local one by default).
+ @name Date Arithmetics
+
+ These functions carry out
+ @ref overview_datetime_arithmetics "arithmetics" on the wxDateTime
+ objects. As explained in the overview, either wxTimeSpan or wxDateSpan
+ may be added to wxDateTime, hence all functions are overloaded to
+ accept both arguments.
+
+ Also, both Add() and Subtract() have both const and non-const version.
+ The first one returns a new object which represents the sum/difference
+ of the original one with the argument while the second form modifies
+ the object to which it is applied. The operators "-=" and "+=" are
+ defined to be equivalent to the second forms of these functions.
*/
- wxDateTime_t GetMillisecond(const TimeZone& tz = Local) const;
+ //@{
/**
- Returns the minute in the given timezone (local one by default).
+ Adds the given date span to this object.
+
+ @beginWxPythonOnly
+ This method is named "AddDS" in wxPython.
+ @endWxPythonOnly
+ */
+ wxDateTime Add(const wxDateSpan& diff) const;
+ /**
+ Adds the given date span to this object.
+
+ @beginWxPythonOnly
+ This method is named "AddDS" in wxPython.
+ @endWxPythonOnly
*/
- wxDateTime_t GetMinute(const TimeZone& tz = Local) const;
+ wxDateTime Add(const wxDateSpan& diff);
+ /**
+ Adds the given time span to this object.
+ @beginWxPythonOnly
+ This method is named "AddTS" in wxPython.
+ @endWxPythonOnly
+ */
+ wxDateTime Add(const wxTimeSpan& diff) const;
/**
- Returns the @e Modified Julian Day Number (MJD) which is, by definition,
- equal to JDN - 2400000.5. The MJDs are simpler to work with as the integral
- MJDs correspond to midnights of the dates in the Gregorian calendar and not th
- noons like JDN. The MJD 0 is Nov 17, 1858.
+ Adds the given time span to this object.
+
+ @beginWxPythonOnly
+ This method is named "AddTS" in wxPython.
+ @endWxPythonOnly
*/
- double GetModifiedJulianDayNumber() const;
+ wxDateTime& Add(const wxTimeSpan& diff);
/**
- Returns the month in the given timezone (local one by default).
+ Subtracts the given time span from this object.
+
+ @beginWxPythonOnly
+ This method is named "SubtractTS" in wxPython.
+ @endWxPythonOnly
*/
- Month GetMonth(const TimeZone& tz = Local) const;
+ wxDateTime Subtract(const wxTimeSpan& diff) const;
+ /**
+ Subtracts the given time span from this object.
+ @beginWxPythonOnly
+ This method is named "SubtractTS" in wxPython.
+ @endWxPythonOnly
+ */
+ wxDateTime& Subtract(const wxTimeSpan& diff);
/**
- Gets the full (default) or abbreviated (specify @c Name_Abbr name of the
- given month.
+ Subtracts the given date span from this object.
- @see GetWeekDayName()
+ @beginWxPythonOnly
+ This method is named "SubtractDS" in wxPython.
+ @endWxPythonOnly
*/
- static wxString GetMonthName(Month month,
- NameFlags flags = Name_Full);
+ wxDateTime Subtract(const wxDateSpan& diff) const;
+ /**
+ Subtracts the given date span from this object.
+ @beginWxPythonOnly
+ This method is named "SubtractDS" in wxPython.
+ @endWxPythonOnly
+ */
+ wxDateTime& Subtract(const wxDateSpan& diff);
/**
- Returns the copy of this object to which
- SetToNextWeekDay() was applied.
+ Subtracts another date from this one and returns the difference between
+ them as a wxTimeSpan.
*/
- wxDateTime GetNextWeekDay(WeekDay weekday) const;
+ wxTimeSpan Subtract(const wxDateTime& dt) const;
- //@{
/**
- Returns the number of days in the given year or in the given month of the
- year.
- The only supported value for @a cal parameter is currently @c Gregorian.
+ Adds the given date span to this object.
*/
- static wxDateTime_t GetNumberOfDays(int year,
- Calendar cal = Gregorian);
- static wxDateTime_t GetNumberOfDays(Month month,
- int year = Inv_Year,
- Calendar cal = Gregorian);
+ wxDateTime operator+=(const wxDateSpan& diff);
+ /**
+ Subtracts the given date span from this object.
+ */
+ wxDateTime& operator-=(const wxDateSpan& diff);
+ /**
+ Adds the given time span to this object.
+ */
+ wxDateTime& operator+=(const wxTimeSpan& diff);
+ /**
+ Subtracts the given time span from this object.
+ */
+ wxDateTime& operator-=(const wxTimeSpan& diff);
+
//@}
+
+
/**
- Returns the copy of this object to which
- SetToPrevWeekDay() was applied.
+ @name Date Formatting and Parsing
+
+ See @ref datetime_formatting
*/
- wxDateTime GetPrevWeekDay(WeekDay weekday) const;
+ //@{
/**
- Return the @e Rata Die number of this date.
- By definition, the Rata Die number is a date specified as the number of days
- relative to a base date of December 31 of the year 0. Thus January 1 of the
- year 1 is Rata Die day 1.
+ This function does the same as the standard ANSI C @c strftime(3)
+ function. Please see its description for the meaning of @a format
+ parameter.
+
+ It also accepts a few wxWidgets-specific extensions: you can optionally
+ specify the width of the field to follow using @c printf(3)-like syntax
+ and the format specification @c "%l" can be used to get the number of
+ milliseconds.
+
+ @see ParseFormat()
*/
- double GetRataDie() const;
+ wxString Format(const wxChar* format = wxDefaultDateTimeFormat,
+ const TimeZone& tz = Local) const;
/**
- Returns the seconds in the given timezone (local one by default).
+ Identical to calling Format() with @c "%x" argument (which means
+ "preferred date representation for the current locale").
*/
- wxDateTime_t GetSecond(const TimeZone& tz = Local) const;
+ wxString FormatDate() const;
/**
- Returns the number of seconds since Jan 1, 1970. An assert failure will occur
- if the date is not in the range covered by @c time_t type.
+ Returns the combined date-time representation in the ISO 8601 format
+ @c "YYYY-MM-DDTHH:MM:SS". The @a sep parameter default value produces
+ the result exactly corresponding to the ISO standard, but it can also
+ be useful to use a space as seprator if a more human-readable combined
+ date-time representation is needed.
+
+ @see FormatISODate(), FormatISOTime(), ParseISOCombined()
*/
- time_t GetTicks() const;
+ wxString FormatISOCombined(char sep = 'T') const;
/**
- Returns the current time.
+ This function returns the date representation in the ISO 8601 format
+ @c "YYYY-MM-DD".
*/
- static time_t GetTimeNow();
+ wxString FormatISODate() const;
/**
- Returns broken down representation of the date and time.
+ This function returns the time representation in the ISO 8601 format
+ @c "HH:MM:SS".
*/
- Tm GetTm(const TimeZone& tz = Local) const;
+ wxString FormatISOTime() const;
/**
- Returns the current time broken down. Note that this function returns a
- pointer to a static buffer that's reused by calls to this function and
- certain C library functions (e.g. localtime). If there is any chance your
- code might be used in a multi-threaded application, you really should use
- the flavour of function GetTmNow()
- taking a parameter.
+ Identical to calling Format() with @c "%X" argument (which means
+ "preferred time representation for the current locale").
*/
- static struct tm* GetTmNow();
+ wxString FormatTime() const;
/**
- Returns the copy of this object to which
- SetToWeekDay() was applied.
+ This function is like ParseDateTime(), but it only allows the date to
+ be specified. It is thus less flexible then ParseDateTime(), but also
+ has less chances to misinterpret the user input.
+
+ @returns @NULL if the conversion failed, otherwise return the pointer
+ to the character which stopped the scan.
*/
- wxDateTime GetWeekDay(WeekDay weekday, int n = 1,
- Month month = Inv_Month,
- int year = Inv_Year) const;
+ const char* ParseDate(const wxString& date,
+ wxString::const_iterator* end = NULL);
+ /**
+ This function is like ParseDateTime(), but it only allows the date to
+ be specified. It is thus less flexible then ParseDateTime(), but also
+ has less chances to misinterpret the user input.
+ @returns @NULL if the conversion failed, otherwise return the pointer
+ to the character which stopped the scan.
+ */
+ const char* ParseDate(const char* date);
/**
- Returns the copy of this object to which
- SetToWeekDayInSameWeek() was
- applied.
+ This function is like ParseDateTime(), but it only allows the date to
+ be specified. It is thus less flexible then ParseDateTime(), but also
+ has less chances to misinterpret the user input.
+
+ @returns @NULL if the conversion failed, otherwise return the pointer
+ to the character which stopped the scan.
*/
- wxDateTime GetWeekDayInSameWeek(WeekDay weekday,
- WeekFlags flags = Monday_First) const;
+ const wchar_t* ParseDate(const wchar_t* date);
/**
- Gets the full (default) or abbreviated (specify @c Name_Abbr name of the
- given week day.
+ Parses the string @a datetime containing the date and time in free
+ format. This function tries as hard as it can to interpret the given
+ string as date and time. Unlike ParseRfc822Date(), it will accept
+ anything that may be accepted and will only reject strings which can
+ not be parsed in any way at all.
- @see GetMonthName()
+ @returns @NULL if the conversion failed, otherwise return the pointer
+ to the character which stopped the scan.
*/
- static wxString GetWeekDayName(WeekDay weekday,
- NameFlags flags = Name_Full);
+ const char* ParseDateTime(const wxString& datetime,
+ wxString::const_iterator* end = NULL);
+ /**
+ Parses the string @a datetime containing the date and time in free
+ format. This function tries as hard as it can to interpret the given
+ string as date and time. Unlike ParseRfc822Date(), it will accept
+ anything that may be accepted and will only reject strings which can
+ not be parsed in any way at all.
+ @returns @NULL if the conversion failed, otherwise return the pointer
+ to the character which stopped the scan.
+ */
+ const char* ParseDateTime(const char* datetime);
/**
- Returns the ordinal number of the week in the month (in 1...5 range).
- As GetWeekOfYear(), this function supports
- both conventions for the week start. See the description of these
- @ref overview_wxdatetime "week start" conventions.
+ Parses the string @a datetime containing the date and time in free
+ format. This function tries as hard as it can to interpret the given
+ string as date and time. Unlike ParseRfc822Date(), it will accept
+ anything that may be accepted and will only reject strings which can
+ not be parsed in any way at all.
+
+ @returns @NULL if the conversion failed, otherwise return the pointer
+ to the character which stopped the scan.
*/
- wxDateTime_t GetWeekOfMonth(WeekFlags flags = Monday_First,
- const TimeZone& tz = Local) const;
+ const wchar_t* ParseDateTime(const wchar_t* datetime);
/**
- Returns the number of the week of the year this date is in. The first week of
- the year is, according to international standards, the one containing Jan 4 or,
- equivalently, the first week which has Thursday in this year. Both of these
- definitions are the same as saying that the first week of the year must contain
- more than half of its days in this year. Accordingly, the week number will
- always be in 1...53 range (52 for non-leap years).
- The function depends on the @ref overview_wxdatetime "week start" convention
- specified by the @a flags argument but its results for
- @c Sunday_First are not well-defined as the ISO definition quoted above
- applies to the weeks starting on Monday only.
+ This function parses the string @a date according to the given
+ @e format. The system @c strptime(3) function is used whenever
+ available, but even if it is not, this function is still implemented,
+ although support for locale-dependent format specifiers such as
+ @c "%c", @c "%x" or @c "%X" may not be perfect and GNU extensions such
+ as @c "%z" and @c "%Z" are not implemented. This function does handle
+ the month and weekday names in the current locale on all platforms,
+ however.
+
+ Please see the description of the ANSI C function @c strftime(3) for
+ the syntax of the format string.
+
+ The @a dateDef parameter is used to fill in the fields which could not
+ be determined from the format string. For example, if the format is
+ @c "%d" (the day of the month), the month and the year are taken from
+ @a dateDef. If it is not specified, Today() is used as the default
+ date.
+
+ @returns @NULL if the conversion failed, otherwise return the pointer
+ to the character which stopped the scan.
*/
- wxDateTime_t GetWeekOfYear(WeekFlags flags = Monday_First,
- const TimeZone& tz = Local) const;
+ const char* ParseFormat(const wxString& date,
+ const wxString& format = wxDefaultDateTimeFormat,
+ const wxDateTime& dateDef = wxDefaultDateTime,
+ wxString::const_iterator* end = NULL);
+ /**
+ This function parses the string @a date according to the given
+ @e format. The system @c strptime(3) function is used whenever
+ available, but even if it is not, this function is still implemented,
+ although support for locale-dependent format specifiers such as
+ @c "%c", @c "%x" or @c "%X" may not be perfect and GNU extensions such
+ as @c "%z" and @c "%Z" are not implemented. This function does handle
+ the month and weekday names in the current locale on all platforms,
+ however.
+
+ Please see the description of the ANSI C function @c strftime(3) for
+ the syntax of the format string.
+
+ The @a dateDef parameter is used to fill in the fields which could not
+ be determined from the format string. For example, if the format is
+ @c "%d" (the day of the month), the month and the year are taken from
+ @a dateDef. If it is not specified, Today() is used as the default
+ date.
+ @returns @NULL if the conversion failed, otherwise return the pointer
+ to the character which stopped the scan.
+ */
+ const char* ParseFormat(const char* date,
+ const wxString& format = wxDefaultDateTimeFormat,
+ const wxDateTime& dateDef = wxDefaultDateTime);
/**
- Returns the year in the given timezone (local one by default).
+ This function parses the string @a date according to the given
+ @e format. The system @c strptime(3) function is used whenever
+ available, but even if it is not, this function is still implemented,
+ although support for locale-dependent format specifiers such as
+ @c "%c", @c "%x" or @c "%X" may not be perfect and GNU extensions such
+ as @c "%z" and @c "%Z" are not implemented. This function does handle
+ the month and weekday names in the current locale on all platforms,
+ however.
+
+ Please see the description of the ANSI C function @c strftime(3) for
+ the syntax of the format string.
+
+ The @a dateDef parameter is used to fill in the fields which could not
+ be determined from the format string. For example, if the format is
+ @c "%d" (the day of the month), the month and the year are taken from
+ @a dateDef. If it is not specified, Today() is used as the default
+ date.
+
+ @returns @NULL if the conversion failed, otherwise return the pointer
+ to the character which stopped the scan.
*/
- int GetYear(const TimeZone& tz = Local) const;
+ const wchar_t* ParseFormat(const wchar_t* date,
+ const wxString& format = wxDefaultDateTimeFormat,
+ const wxDateTime& dateDef = wxDefaultDateTime);
/**
- Returns the copy of this object to which
- SetToYearDay() was applied.
+ This function parses the string containing the date and time in ISO
+ 8601 combined format @c "YYYY-MM-DDTHH:MM:SS". The separator between
+ the date and time parts must be equal to @a sep for the function to
+ succeed.
+
+ @returns @true if the entire string was parsed successfully, @false
+ otherwise.
*/
- wxDateTime GetYearDay(wxDateTime_t yday) const;
+ bool ParseISOCombined(const wxString& date, char sep = 'T');
/**
- Returns @true if IsStrictlyBetween()
- is @true or if the date is equal to one of the limit values.
+ This function parses the date in ISO 8601 format @c "YYYY-MM-DD".
- @see IsStrictlyBetween()
+ @returns @true if the entire string was parsed successfully, @false
+ otherwise.
*/
- bool IsBetween(const wxDateTime& t1, const wxDateTime& t2) const;
+ bool ParseISODate(const wxString& date);
/**
- Returns @true if the DST is applied for this date in the given country.
+ This function parses the time in ISO 8601 format @c "HH:MM:SS".
+
+ @returns @true if the entire string was parsed successfully, @false
+ otherwise.
*/
- int IsDST(Country country = Country_Default) const;
+ bool ParseISOTime(const wxString& date);
/**
- Returns @true if DST was used n the given year (the current one by
- default) in the given country.
+ Parses the string @a date looking for a date formatted according to the
+ RFC 822 in it. The exact description of this format may, of course, be
+ found in the RFC (section 5), but, briefly, this is the format used in
+ the headers of Internet email messages and one of the most common
+ strings expressing date in this format may be something like
+ @c "Sat, 18 Dec 1999 00:48:30 +0100".
+
+ Returns @NULL if the conversion failed, otherwise return the pointer to
+ the character immediately following the part of the string which could
+ be parsed. If the entire string contains only the date in RFC 822
+ format, the returned pointer will be pointing to a @c NUL character.
+
+ This function is intentionally strict, it will return an error for any
+ string which is not RFC 822 compliant. If you need to parse date
+ formatted in more free ways, you should use ParseDateTime() or
+ ParseDate() instead.
*/
- static bool IsDSTApplicable(int year = Inv_Year,
- Country country = Country_Default);
+ const char* ParseRfc822Date(const wxString& date,
+ wxString::const_iterator* end = NULL);
+ /**
+ Parses the string @a date looking for a date formatted according to the
+ RFC 822 in it. The exact description of this format may, of course, be
+ found in the RFC (section 5), but, briefly, this is the format used in
+ the headers of Internet email messages and one of the most common
+ strings expressing date in this format may be something like
+ @c "Sat, 18 Dec 1999 00:48:30 +0100".
+ Returns @NULL if the conversion failed, otherwise return the pointer to
+ the character immediately following the part of the string which could
+ be parsed. If the entire string contains only the date in RFC 822
+ format, the returned pointer will be pointing to a @c NUL character.
+
+ This function is intentionally strict, it will return an error for any
+ string which is not RFC 822 compliant. If you need to parse date
+ formatted in more free ways, you should use ParseDateTime() or
+ ParseDate() instead.
+ */
+ const char* ParseRfc822Date(const char* date);
/**
- Returns @true if this date precedes the given one.
+ Parses the string @a date looking for a date formatted according to the
+ RFC 822 in it. The exact description of this format may, of course, be
+ found in the RFC (section 5), but, briefly, this is the format used in
+ the headers of Internet email messages and one of the most common
+ strings expressing date in this format may be something like
+ @c "Sat, 18 Dec 1999 00:48:30 +0100".
+
+ Returns @NULL if the conversion failed, otherwise return the pointer to
+ the character immediately following the part of the string which could
+ be parsed. If the entire string contains only the date in RFC 822
+ format, the returned pointer will be pointing to a @c NUL character.
+
+ This function is intentionally strict, it will return an error for any
+ string which is not RFC 822 compliant. If you need to parse date
+ formatted in more free ways, you should use ParseDateTime() or
+ ParseDate() instead.
*/
- bool IsEarlierThan(const wxDateTime& datetime) const;
+ const wchar_t* ParseRfc822Date(const wchar_t* date);
/**
- Returns @true if the two dates are strictly identical.
+ This functions is like ParseDateTime(), but only allows the time to be
+ specified in the input string.
+
+ @returns @NULL if the conversion failed, otherwise return the pointer
+ to the character which stopped the scan.
*/
- bool IsEqualTo(const wxDateTime& datetime) const;
+ const char* ParseTime(const wxString& time,
+ wxString::const_iterator* end = NULL);
+ /**
+ This functions is like ParseDateTime(), but only allows the time to be
+ specified in the input string.
+ @returns @NULL if the conversion failed, otherwise return the pointer
+ to the character which stopped the scan.
+ */
+ const char* ParseTime(const char* time);
/**
- Returns @true if the date is equal to another one up to the given time
- interval, i.e. if the absolute difference between the two dates is less than
- this interval.
+ This functions is like ParseDateTime(), but only allows the time to be
+ specified in the input string.
+
+ @returns @NULL if the conversion failed, otherwise return the pointer
+ to the character which stopped the scan.
*/
- bool IsEqualUpTo(const wxDateTime& dt, const wxTimeSpan& ts) const;
+ const wchar_t* ParseTime(const wchar_t* time);
+
+ //@}
+
+
/**
- Returns @true if the given date is later than the date of adoption of the
- Gregorian calendar in the given country (and hence the Gregorian calendar
- calculations make sense for it).
+ @name Calendar Calculations
+
+ The functions in this section perform the basic calendar calculations,
+ mostly related to the week days. They allow to find the given week day
+ in the week with given number (either in the month or in the year) and
+ so on.
+
+ None of the functions in this section modify the time part of the
+ wxDateTime, they only work with the date part of it.
*/
- bool IsGregorianDate(GregorianAdoption country = Gr_Standard) const;
+ //@{
/**
- Returns @true if this date is later than the given one.
+ Returns the copy of this object to which SetToLastMonthDay() was
+ applied.
*/
- bool IsLaterThan(const wxDateTime& datetime) const;
+ wxDateTime GetLastMonthDay(Month month = Inv_Month,
+ int year = Inv_Year) const;
/**
- Returns @true if the @a year is a leap one in the specified calendar.
- This functions supports Gregorian and Julian calendars.
+ Returns the copy of this object to which SetToLastWeekDay() was
+ applied.
*/
- static bool IsLeapYear(int year = Inv_Year,
- Calendar cal = Gregorian);
+ wxDateTime GetLastWeekDay(WeekDay weekday, Month month = Inv_Month,
+ int year = Inv_Year);
/**
- Returns @true if the date is the same without comparing the time parts.
+ Returns the copy of this object to which SetToNextWeekDay() was
+ applied.
*/
- bool IsSameDate(const wxDateTime& dt) const;
+ wxDateTime GetNextWeekDay(WeekDay weekday) const;
/**
- Returns @true if the time is the same (although dates may differ).
+ Returns the copy of this object to which SetToPrevWeekDay() was
+ applied.
*/
- bool IsSameTime(const wxDateTime& dt) const;
+ wxDateTime GetPrevWeekDay(WeekDay weekday) const;
/**
- Returns @true if this date lies strictly between the two others,
-
- @see IsBetween()
+ Returns the copy of this object to which SetToWeekDay() was applied.
*/
- bool IsStrictlyBetween(const wxDateTime& t1,
- const wxDateTime& t2) const;
+ wxDateTime GetWeekDay(WeekDay weekday, int n = 1, Month month = Inv_Month,
+ int year = Inv_Year) const;
/**
- Returns @true if the object represents a valid time moment.
+ Returns the copy of this object to which SetToWeekDayInSameWeek() was
+ applied.
*/
- bool IsValid() const;
+ wxDateTime GetWeekDayInSameWeek(WeekDay weekday,
+ WeekFlags flags = Monday_First) const;
/**
- This function returns @true if the specified (or default) country is one
- of Western European ones. It is used internally by wxDateTime to determine the
- DST convention and date and time formatting rules.
+ Returns the copy of this object to which SetToYearDay() was applied.
*/
- static bool IsWestEuropeanCountry(Country country = Country_Default);
+ wxDateTime GetYearDay(wxDateTime_t yday) const;
/**
- Returns @true is this day is not a holiday in the given country.
+ Sets the date to the last day in the specified month (the current one
+ by default).
+
+ @returns The reference to the modified object itself.
*/
- bool IsWorkDay(Country country = Country_Default) const;
+ wxDateTime SetToLastMonthDay(Month month = Inv_Month,
+ int year = Inv_Year);
/**
- Same as FromTimezone() but modifies the object
- in place.
+ The effect of calling this function is the same as of calling
+ @c SetToWeekDay(-1, weekday, month, year). The date will be set to the
+ last @a weekday in the given month and year (the current ones by
+ default). Always returns @true.
*/
- wxDateTime MakeFromTimezone(const TimeZone& tz,
- bool noDST = false);
+ bool SetToLastWeekDay(WeekDay weekday, Month month = Inv_Month,
+ int year = Inv_Year);
/**
- Modifies the object in place to represent the date in another time zone. If
- @a noDST is @true, no DST adjustments will be made.
+ Sets the date so that it will be the first @a weekday following the
+ current date.
+
+ @returns The reference to the modified object itself.
*/
- wxDateTime MakeTimezone(const TimeZone& tz,
- bool noDST = false);
+ wxDateTime& SetToNextWeekDay(WeekDay weekday);
/**
- This is the same as calling MakeTimezone() with
- the argument @c GMT0.
+ Sets the date so that it will be the last @a weekday before the current
+ date.
+
+ @returns The reference to the modified object itself.
*/
- wxDateTime MakeUTC(bool noDST = false);
+ wxDateTime& SetToPrevWeekDay(WeekDay weekday);
/**
- Returns the object corresponding to the current time.
- Example:
+ Sets the date to the @e n-th @a weekday in the given month of the given
+ year (the current month and year are used by default). The parameter
+ @a n may be either positive (counting from the beginning of the month)
+ or negative (counting from the end of it).
- Note that this function is accurate up to second:
- UNow() should be used for better precision
- (but it is less efficient and might not be available on all platforms).
+ For example, SetToWeekDay(2, wxDateTime::Wed) will set the date to the
+ second Wednesday in the current month and
+ SetToWeekDay(-1, wxDateTime::Sun) will set the date to the last Sunday
+ in the current month.
- @see Today()
+ @returns @true if the date was modified successfully, @false otherwise
+ meaning that the specified date doesn't exist.
*/
- static wxDateTime Now();
+ bool SetToWeekDay(WeekDay weekday, int n = 1,
+ Month month = Inv_Month, int year = Inv_Year);
- //@{
/**
- This function is like ParseDateTime(), but it
- only allows the date to be specified. It is thus less flexible then
- ParseDateTime(), but also has less chances to
- misinterpret the user input.
- Returns @NULL if the conversion failed, otherwise return the pointer to
- the character which stopped the scan.
- */
- const char* ParseDate(const wxString& date,
- wxString::const_iterator* end = NULL);
- const char* ParseDate(const char* date);
- const wchar_t* ParseDate(const wchar_t* date);
- //@}
+ Adjusts the date so that it will still lie in the same week as before,
+ but its week day will be the given one.
- //@{
- /**
- Parses the string @a datetime containing the date and time in free format.
- This function tries as hard as it can to interpret the given string as date
- and time. Unlike wxDateTime::ParseRfc822Date, it
- will accept anything that may be accepted and will only reject strings which
- can not be parsed in any way at all.
- Returns @NULL if the conversion failed, otherwise return the pointer to
- the character which stopped the scan.
+ @returns The reference to the modified object itself.
*/
- const char* ParseDateTime(const wxString& datetime,
- wxString::const_iterator* end = NULL);
- const char* ParseDateTime(const char* datetime);
- const wchar_t* ParseDateTime(const wchar_t* datetime);
- //@}
+ wxDateTime SetToWeekDayInSameWeek(WeekDay weekday,
+ WeekFlags flags = Monday_First);
- //@{
/**
- This function parses the string @a date according to the given
- @e format. The system @c strptime(3) function is used whenever available,
- but even if it is not, this function is still implemented, although support
- for locale-dependent format specifiers such as @c "%c", @c "%x" or @c "%X" may
- not be perfect and GNU extensions such as @c "%z" and @c "%Z" are
- not implemented. This function does handle the month and weekday
- names in the current locale on all platforms, however.
- Please see the description of the ANSI C function @c strftime(3) for the syntax
- of the format string.
- The @a dateDef parameter is used to fill in the fields which could not be
- determined from the format string. For example, if the format is @c "%d" (the
- ay of the month), the month and the year are taken from @e dateDef. If
- it is not specified, Today() is used as the
- default date.
- Returns @NULL if the conversion failed, otherwise return the pointer to
- the character which stopped the scan.
+ Sets the date to the day number @a yday in the same year (i.e., unlike
+ the other functions, this one does not use the current year). The day
+ number should be in the range 1-366 for the leap years and 1-365 for
+ the other ones.
+
+ @returns The reference to the modified object itself.
*/
- const char* ParseFormat(const wxString& date,
- const wxString& format = wxDefaultDateTimeFormat,
- const wxDateTime& dateDef = wxDefaultDateTime,
- wxString::const_iterator* end = NULL);
- const char* ParseFormat(const char* date,
- const wxString& format = wxDefaultDateTimeFormat,
- const wxDateTime& dateDef = wxDefaultDateTime);
- const wchar_t* ParseFormat(const wchar_t* date,
- const wxString& format = wxDefaultDateTimeFormat,
- const wxDateTime& dateDef = wxDefaultDateTime);
+ wxDateTime& SetToYearDay(wxDateTime_t yday);
+
//@}
+
+
/**
- This function parses the string containing the date and time in ISO 8601
- combined format (YYYY-MM-DDTHH:MM:SS). The separator between the date and time
- parts must be equal to @a sep for the function to succeed.
- Returns @true if the entire string was parsed successfully, @false
- otherwise.
+ @name Astronomical/Historical Functions
+
+ Some degree of support for the date units used in astronomy and/or
+ history is provided. You can construct a wxDateTime object from a
+ JDN and you may also get its JDN, MJD or Rata Die number from it.
+
+ Related functions in other groups: wxDateTime(double), Set(double)
*/
- bool ParseISOCombined(const wxString& date, char sep = 'T');
+ //@{
/**
- This function parses the date in ISO 8601 format (YYYY-MM-DD).
- Returns @true if the entire string was parsed successfully, @false
- otherwise.
+ Synonym for GetJulianDayNumber().
*/
- bool ParseISODate(const wxString& date);
+ double GetJDN() const;
/**
- This function parses the time in ISO 8601 format (HH:MM:SS).
- Returns @true if the entire string was parsed successfully, @false
- otherwise.
+ Returns the JDN corresponding to this date. Beware of rounding errors!
+
+ @see GetModifiedJulianDayNumber()
*/
- bool ParseISOTime(const wxString& date);
+ double GetJulianDayNumber() const;
- //@{
/**
- Parses the string @a date looking for a date formatted according to the RFC
- 822 in it. The exact description of this format may, of course, be found in
- the RFC (section 5), but, briefly, this is the format used in the headers of
- Internet email messages and one of the most common strings expressing date in
- this format may be something like @c "Sat, 18 Dec 1999 00:48:30 +0100".
- Returns @NULL if the conversion failed, otherwise return the pointer to
- the character immediately following the part of the string which could be
- parsed. If the entire string contains only the date in RFC 822 format,
- the returned pointer will be pointing to a @c NUL character.
- This function is intentionally strict, it will return an error for any string
- which is not RFC 822 compliant. If you need to parse date formatted in more
- free ways, you should use ParseDateTime() or
- ParseDate() instead.
+ Synonym for GetModifiedJulianDayNumber().
*/
- const char* ParseRfc822Date(const wxString& date,
- wxString::const_iterator* end = NULL);
- const char* ParseRfc822Date(const char* date);
- const wchar_t* ParseRfc822Date(const wchar_t* date);
- //@}
+ double GetMJD() const;
- //@{
/**
- This functions is like ParseDateTime(), but
- only allows the time to be specified in the input string.
- Returns @NULL if the conversion failed, otherwise return the pointer to
- the character which stopped the scan.
+ Returns the @e "Modified Julian Day Number" (MJD) which is, by
+ definition, is equal to JDN - 2400000.5. The MJDs are simpler to work
+ with as the integral MJDs correspond to midnights of the dates in the
+ Gregorian calendar and not the noons like JDN. The MJD 0 represents
+ Nov 17, 1858.
*/
- const char* ParseTime(const wxString& time,
- wxString::const_iterator* end = NULL);
- const char* ParseTime(const char* time);
- const wchar_t* ParseTime(const wchar_t* time);
- //@}
+ double GetModifiedJulianDayNumber() const;
/**
- These functions convert wxDateTime objects to and from text. The
- conversions to text are mostly trivial: you can either do it using the default
- date and time representations for the current locale (
- FormatDate() and
- wxDateTime::FormatTime), using the international standard
- representation defined by ISO 8601 (
- FormatISODate(),
- FormatISOTime() and
- wxDateTime::FormatISOCombined) or by specifying any
- format at all and using Format() directly.
- The conversions from text are more interesting, as there are much more
- possibilities to care about. The simplest cases can be taken care of with
- ParseFormat() which can parse any date in the
- given (rigid) format. wxDateTime::ParseRfc822Date is
- another function for parsing dates in predefined format -- the one of RFC 822
- which (still...) defines the format of email messages on the Internet. This
- format can not be described with @c strptime(3)-like format strings used by
- Format(), hence the need for a separate function.
- But the most interesting functions are
- ParseTime(),
- ParseDate() and
- ParseDateTime(). They try to parse the date
- ans time (or only one of them) in 'free' format, i.e. allow them to be
- specified in any of possible ways. These functions will usually be used to
- parse the (interactive) user input which is not bound to be in any predefined
- format. As an example, ParseDateTime() can
- parse the strings such as @c "tomorrow", @c "March first" and even
- @c "next Sunday".
- Finally notice that each of the parsing functions is available in several
- overloads: if the input string is a narrow (@c char *) string, then a
- narrow pointer is returned. If the input string is a wide string, a wide char
- pointer is returned. Finally, if the input parameter is a wxString, a narrow
- char pointer is also returned for backwards compatibility but there is also an
- additional argument of wxString::const_iterator type in which, if it is not
- @NULL, an iterator pointing to the end of the scanned string part is returned.
- ParseFormat()
-
- ParseDateTime()
-
- ParseDate()
+ Return the @e Rata Die number of this date.
- ParseTime()
+ By definition, the Rata Die number is a date specified as the number of
+ days relative to a base date of December 31 of the year 0. Thus January
+ 1 of the year 1 is Rata Die day 1.
+ */
+ double GetRataDie() const;
- ParseISODate()
+ //@}
- ParseISOTime()
- ParseISOCombined()
- wxDateTime::ParseRfc822Date
+ /**
+ @name Time Zone and DST Support
- Format()
+ Please see the @ref overview_datetime_timezones "time zone overview"
+ for more information about time zones. Normally, these functions should
+ be rarely used.
- FormatDate()
+ Related functions in other groups: GetBeginDST(), GetEndDST()
+ */
+ //@{
- FormatTime()
+ /**
+ Transform the date from the given time zone to the local one. If
+ @a noDST is @true, no DST adjustments will be made.
- FormatISOCombined()
+ @returns The date in the local time zone.
+ */
+ wxDateTime FromTimezone(const TimeZone& tz, bool noDST = false) const;
- FormatISODate()
+ /**
+ Returns @true if the DST is applied for this date in the given country.
- FormatISOTime()
+ @see GetBeginDST(), GetEndDST()
*/
+ int IsDST(Country country = Country_Default) const;
+ /**
+ Same as FromTimezone() but modifies the object in place.
+ */
+ wxDateTime MakeFromTimezone(const TimeZone& tz, bool noDST = false);
/**
- Reset time to midnight (00:00:00) without changing the date.
+ Modifies the object in place to represent the date in another time
+ zone. If @a noDST is @true, no DST adjustments will be made.
*/
- wxDateTime ResetTime();
+ wxDateTime MakeTimezone(const TimeZone& tz, bool noDST = false);
/**
- Sets the date and time from the parameters.
+ This is the same as calling MakeTimezone() with the argument @c GMT0.
*/
- wxDateTime Set(wxDateTime_t day, Month month = Inv_Month,
- int year = Inv_Year,
- wxDateTime_t hour = 0,
- wxDateTime_t minute = 0,
- wxDateTime_t second = 0,
- wxDateTime_t millisec = 0);
+ wxDateTime& MakeUTC(bool noDST = false);
/**
- Sets the country to use by default. This setting influences the DST
- calculations, date formatting and other things.
- The possible values for @a country parameter are enumerated in
- @ref overview_wxdatetime "wxDateTime constants section".
+ Transform the date to the given time zone. If @a noDST is @true, no DST
+ adjustments will be made.
- @see GetCountry()
+ @returns The date in the new time zone.
*/
- static void SetCountry(Country country);
+ wxDateTime ToTimezone(const TimeZone& tz, bool noDST = false) const;
/**
- Sets the day without changing other date components.
+ This is the same as calling ToTimezone() with the argument @c GMT0.
*/
- wxDateTime SetDay(wxDateTime_t day);
+ wxDateTime ToUTC(bool noDST = false) const;
+
+ //@}
+
+
+
+
/**
- Sets the date from the date and time in
- DOS
- format.
+ Converts the year in absolute notation (i.e. a number which can be
+ negative, positive or zero) to the year in BC/AD notation. For the
+ positive years, nothing is done, but the year 0 is year 1 BC and so for
+ other years there is a difference of 1.
+
+ This function should be used like this:
+
+ @code
+ wxDateTime dt(...);
+ int y = dt.GetYear();
+ printf("The year is %d%s", wxDateTime::ConvertYearToBC(y), y > 0 ? "AD" : "BC");
+ @endcode
*/
- wxDateTime Set(unsigned long ddt);
+ static int ConvertYearToBC(int year);
/**
- Sets the hour without changing other date components.
+ Returns the translations of the strings @c AM and @c PM used for time
+ formatting for the current locale. Either of the pointers may be @NULL
+ if the corresponding value is not needed.
*/
- wxDateTime SetHour(wxDateTime_t hour);
+ static void GetAmPmStrings(wxString* am, wxString* pm);
/**
- Sets the millisecond without changing other date components.
+ Get the beginning of DST for the given country in the given year
+ (current one by default). This function suffers from limitations
+ described in the @ref overview_datetime_dst "DST overview".
+
+ @see GetEndDST()
*/
- wxDateTime SetMillisecond(wxDateTime_t millisecond);
+ static wxDateTime GetBeginDST(int year = Inv_Year,
+ Country country = Country_Default);
/**
- Sets the minute without changing other date components.
+ Returns the end of DST for the given country in the given year (current
+ one by default).
+
+ @see GetBeginDST()
*/
- wxDateTime SetMinute(wxDateTime_t minute);
+ static wxDateTime GetEndDST(int year = Inv_Year,
+ Country country = Country_Default);
/**
- Sets the month without changing other date components.
+ Get the current century, i.e. first two digits of the year, in given
+ calendar (only Gregorian is currently supported).
*/
- wxDateTime SetMonth(Month month);
+ static int GetCentury(int year);
/**
- Sets the second without changing other date components.
+ Returns the current default country. The default country is used for
+ DST calculations, for example.
+
+ @see SetCountry()
*/
- wxDateTime SetSecond(wxDateTime_t second);
+ static Country GetCountry();
/**
- Sets the date and time of to the current values. Same as assigning the result
- of Now() to this object.
+ Get the current month in given calendar (only Gregorian is currently
+ supported).
*/
- wxDateTime SetToCurrent();
+ static Month GetCurrentMonth(Calendar cal = Gregorian);
/**
- Sets the date to the last day in the specified month (the current one by
- default).
- Returns the reference to the modified object itself.
+ Get the current year in given calendar (only Gregorian is currently
+ supported).
*/
- wxDateTime SetToLastMonthDay(Month month = Inv_Month,
- int year = Inv_Year);
+ static int GetCurrentYear(Calendar cal = Gregorian);
/**
- The effect of calling this function is the same as of calling
- @c SetToWeekDay(-1, weekday, month, year). The date will be set to the last
- @a weekday in the given month and year (the current ones by default).
- Always returns @true.
+ Gets the full (default) or abbreviated (specify @c Name_Abbr name of
+ the given month.
+
+ @see GetWeekDayName()
*/
- bool SetToLastWeekDay(WeekDay weekday, Month month = Inv_Month,
- int year = Inv_Year);
+ static wxString GetMonthName(Month month, NameFlags flags = Name_Full);
/**
- Sets the date so that it will be the first @a weekday following the current
- date.
- Returns the reference to the modified object itself.
+ Returns the number of days in the given year. The only supported value
+ for @a cal currently is @c Gregorian.
+
+ @beginWxPythonOnly
+ This method is named "GetNumberOfDaysInYear" in wxPython.
+ @endWxPythonOnly
*/
- wxDateTime SetToNextWeekDay(WeekDay weekday);
+ static wxDateTime_t GetNumberOfDays(int year, Calendar cal = Gregorian);
/**
- Sets the date so that it will be the last @a weekday before the current
- date.
- Returns the reference to the modified object itself.
+ Returns the number of days in the given month of the given year. The
+ only supported value for @a cal currently is @c Gregorian.
+
+ @beginWxPythonOnly
+ This method is named "GetNumberOfDaysInMonth" in wxPython.
+ @endWxPythonOnly
*/
- wxDateTime SetToPrevWeekDay(WeekDay weekday);
+ static wxDateTime_t GetNumberOfDays(Month month, int year = Inv_Year,
+ Calendar cal = Gregorian);
/**
- Sets the date to the @e n-th @a weekday in the given month of the given
- year (the current month and year are used by default). The parameter @e n
- may be either positive (counting from the beginning of the month) or negative
- (counting from the end of it).
- For example, @c SetToWeekDay(2, wxDateTime::Wed) will set the date to the
- second Wednesday in the current month and
- @c SetToWeekDay(-1, wxDateTime::Sun) -- to the last Sunday in it.
- Returns @true if the date was modified successfully, @false
- otherwise meaning that the specified date doesn't exist.
+ Returns the current time.
*/
- bool SetToWeekDay(WeekDay weekday, int n = 1,
- Month month = Inv_Month,
- int year = Inv_Year);
+ static time_t GetTimeNow();
/**
- Adjusts the date so that it will still lie in the same week as before, but its
- week day will be the given one.
- Returns the reference to the modified object itself.
+ Returns the current time broken down using the buffer whose adress is
+ passed to the function with @a tm to store the result.
*/
- wxDateTime SetToWeekDayInSameWeek(WeekDay weekday,
- WeekFlags flags = Monday_First);
+ static struct tm* GetTmNow(struct tm *tm);
/**
- Set the date to the given @a weekday in the week number @a numWeek of the
- given @a year . The number should be in range 1...53.
- Note that the returned date may be in a different year than the one passed to
- this function because both the week 1 and week 52 or 53 (for leap years)
- contain days from different years. See
- GetWeekOfYear() for the explanation of how the
- year weeks are counted.
+ Returns the current time broken down. Note that this function returns a
+ pointer to a static buffer that's reused by calls to this function and
+ certain C library functions (e.g. localtime). If there is any chance
+ your code might be used in a multi-threaded application, you really
+ should use GetTmNow(struct tm *) instead.
*/
- static wxDateTime SetToWeekOfYear(int year, wxDateTime_t numWeek,
- WeekDay weekday = Mon);
+ static struct tm* GetTmNow();
/**
- Sets the date to the day number @a yday in the same year (i.e., unlike the
- other functions, this one does not use the current year). The day number
- should be in the range 1...366 for the leap years and 1...365 for
- the other ones.
- Returns the reference to the modified object itself.
+ Gets the full (default) or abbreviated (specify @c Name_Abbr) name of
+ the given week day.
+
+ @see GetMonthName()
*/
- wxDateTime SetToYearDay(wxDateTime_t yday);
+ static wxString GetWeekDayName(WeekDay weekday,
+ NameFlags flags = Name_Full);
/**
- Sets the year without changing other date components.
+ Returns @true if DST was used n the given year (the current one by
+ default) in the given country.
*/
- wxDateTime SetYear(int year);
+ static bool IsDSTApplicable(int year = Inv_Year,
+ Country country = Country_Default);
/**
- For convenience, all static functions are collected here. These functions
- either set or return the static variables of wxDateSpan (the country), return
- the current moment, year, month or number of days in it, or do some general
- calendar-related actions.
- Please note that although several function accept an extra @e Calendar
- parameter, it is currently ignored as only the Gregorian calendar is
- supported. Future versions will support other calendars.
-
- SetCountry()
-
- GetCountry()
-
- IsWestEuropeanCountry()
-
- GetCurrentYear()
-
- ConvertYearToBC()
-
- GetCurrentMonth()
-
- IsLeapYear()
-
- @ref getcenturystatic() GetCentury
-
- GetNumberOfDays()
-
- GetNumberOfDays()
-
- GetMonthName()
-
- GetWeekDayName()
-
- GetAmPmStrings()
-
- IsDSTApplicable()
-
- GetBeginDST()
-
- GetEndDST()
-
- Now()
-
- UNow()
-
- Today()
+ Returns @true if the @a year is a leap one in the specified calendar.
+ This functions supports Gregorian and Julian calendars.
*/
-
+ static bool IsLeapYear(int year = Inv_Year, Calendar cal = Gregorian);
/**
- Subtracts another date from this one and returns the difference between them
- as wxTimeSpan.
+ This function returns @true if the specified (or default) country is
+ one of Western European ones. It is used internally by wxDateTime to
+ determine the DST convention and date and time formatting rules.
*/
- wxTimeSpan Subtract(const wxDateTime& dt) const;
+ static bool IsWestEuropeanCountry(Country country = Country_Default);
/**
- Please see the @ref overview_tdatetimezones "time zone overview" for more
- information about time zones. Normally, these functions should be rarely used.
- FromTimezone()
-
- ToTimezone()
+ Returns the object corresponding to the current time.
- MakeTimezone()
+ Example:
- MakeFromTimezone()
+ @code
+ wxDateTime now = wxDateTime::Now();
+ printf("Current time in Paris:\t%s\n", now.Format("%c", wxDateTime::CET).c_str());
+ @endcode
- ToUTC()
+ @note This function is accurate up to seconds. UNow() should be used
+ for better precision, but it is less efficient and might not be
+ available on all platforms.
- MakeUTC()
+ @see Today()
+ */
+ static wxDateTime Now();
- GetBeginDST()
+ /**
+ Sets the country to use by default. This setting influences the DST
+ calculations, date formatting and other things.
- GetEndDST()
+ The possible values for @a country parameter are enumerated in the
+ @ref datetime_constants section.
- IsDST()
+ @see GetCountry()
*/
-
+ static void SetCountry(Country country);
/**
- Transform the date to the given time zone. If @a noDST is @true, no
- DST adjustments will be made.
- Returns the date in the new time zone.
- */
- wxDateTime ToTimezone(const TimeZone& tz, bool noDST = false) const;
+ Set the date to the given @a weekday in the week number @a numWeek of
+ the given @a year . The number should be in range 1-53.
- /**
- This is the same as calling ToTimezone() with
- the argument @c GMT0.
+ Note that the returned date may be in a different year than the one
+ passed to this function because both the week 1 and week 52 or 53 (for
+ leap years) contain days from different years. See GetWeekOfYear() for
+ the explanation of how the year weeks are counted.
*/
- wxDateTime ToUTC(bool noDST = false) const;
+ static wxDateTime SetToWeekOfYear(int year, wxDateTime_t numWeek,
+ WeekDay weekday = Mon);
/**
- Returns the object corresponding to the midnight of the current day (i.e. the
- same as Now(), but the time part is set to 0).
+ Returns the object corresponding to the midnight of the current day
+ (i.e. the same as Now(), but the time part is set to 0).
@see Now()
*/
/**
Returns the object corresponding to the current time including the
- milliseconds if a function to get time with such precision is available on the
- current platform (supported under most Unices and Win32).
+ milliseconds if a function to get time with such precision is available
+ on the current platform (supported under most Unices and Win32).
@see Now()
*/
static wxDateTime UNow();
-
- /**
- Same as @ref settm() Set.
- */
- wxDateTime operator(const struct tm& tm);
};
+/**
+ Global instance of an empty wxDateTime object.
+
+ @todo Would it be better to rename this wxNullDateTime so it's consistent
+ with the rest of the "empty/invalid/null" global objects?
+*/
+const wxDateTime wxDefaultDateTime;
+
/**
@class wxDateTimeWorkDays
@wxheader{datetime.h}
+ @todo Write wxDateTimeWorkDays documentation.
@library{wxbase}
- @category{FIXME}
+ @category{data}
*/
class wxDateTimeWorkDays
{
Jan 31 + 1 month will be Feb 28, not (non-existing) Feb 31.
Because of this feature, adding and subtracting back again the same
- wxDateSpan will @b not, in general give back the original date: Feb 28 - 1
+ wxDateSpan will @b not, in general, give back the original date: Feb 28 - 1
month will be Jan 28, not Jan 31!
wxDateSpan objects can be either positive or negative. They may be
multiplied by scalars which multiply all deltas by the scalar: i.e.
- 2*(1 month and 1 day) is 2 months and 2 days. They can
- be added together and with wxDateTime or
- wxTimeSpan, but the type of result is different for each
+ 2*(1 month and 1 day) is 2 months and 2 days. They can be added together
+ with wxDateTime or wxTimeSpan, but the type of result is different for each
case.
- Beware about weeks: if you specify both weeks and days, the total number of
- days added will be 7*weeks + days! See also GetTotalDays()
- function.
+ @warning If you specify both weeks and days, the total number of days added
+ will be 7*weeks + days! See also GetTotalDays().
- Equality operators are defined for wxDateSpans. Two datespans are equal if
- and only if they both give the same target date when added to @b every
- source date. Thus wxDateSpan::Months(1) is not equal to wxDateSpan::Days(30),
- because they don't give the same date when added to 1 Feb. But
- wxDateSpan::Days(14) is equal to wxDateSpan::Weeks(2)
+ Equality operators are defined for wxDateSpans. Two wxDateSpans are equal
+ if and only if they both give the same target date when added to @b every
+ source date. Thus wxDateSpan::Months(1) is not equal to
+ wxDateSpan::Days(30), because they don't give the same date when added to
+ Feb 1st. But wxDateSpan::Days(14) is equal to wxDateSpan::Weeks(2).
- Finally, notice that for adding hours, minutes and so on you don't need this
- class at all: wxTimeSpan will do the job because there
- are no subtleties associated with those (we don't support leap seconds).
+ Finally, notice that for adding hours, minutes and so on you don't need
+ this class at all: wxTimeSpan will do the job because there are no
+ subtleties associated with those (we don't support leap seconds).
@library{wxbase}
@category{data}
- @see @ref overview_wxdatetimeoverview "Date classes overview", wxDateTime
+ @see @ref overview_datetime, wxDateTime
*/
class wxDateSpan
{
public:
/**
- Constructs the date span object for the given number of years, months, weeks
- and days. Note that the weeks and days add together if both are given.
+ Constructs the date span object for the given number of years, months,
+ weeks and days. Note that the weeks and days add together if both are
+ given.
*/
- wxDateSpan(int years = 0, int months = 0, int weeks = 0,
- int days = 0);
+ wxDateSpan(int years = 0, int months = 0, int weeks = 0, int days = 0);
- //@{
/**
- Returns the sum of two date spans. The first version returns a new object, the
- second and third ones modify this object in place.
+ Returns the sum of two date spans.
+
+ @returns A new wxDateSpan object with the result.
*/
- wxDateSpan Add(const wxDateSpan& other);
- const wxDateSpan& Add(const wxDateSpan& other);
- wxDateSpan operator+=(const wxDateSpan& other);
- //@}
+ wxDateSpan Add(const wxDateSpan& other) const;
+ /**
+ Adds the given wxDateSpan to this wxDateSpan and returns a reference
+ to itself.
+ */
+ wxDateSpan& Add(const wxDateSpan& other);
/**
Returns a date span object corresponding to one day.
static wxDateSpan Days(int days);
/**
- Returns the number of days (only, that it not counting the weeks component!)
- in this date span.
+ Returns the number of days (not counting the weeks component) in this
+ date span.
@see GetTotalDays()
*/
int GetDays() const;
/**
- Returns the number of the months (not counting the years) in this date span.
+ Returns the number of the months (not counting the years) in this date
+ span.
*/
int GetMonths() const;
/**
- Returns the combined number of days in this date span, counting both weeks and
- days. It still doesn't take neither months nor years into the account.
+ Returns the combined number of days in this date span, counting both
+ weeks and days. This doesn't take months or years into account.
@see GetWeeks(), GetDays()
*/
*/
static wxDateSpan Months(int mon);
- //@{
/**
- Returns the product of the date span by the specified @e factor. The
- product is computed by multiplying each of the components by the factor.
- The first version returns a new object, the second and third ones modify this
- object in place.
+ Returns the product of the date span by the specified @a factor. The
+ product is computed by multiplying each of the components by the
+ @a factor.
+
+ @returns A new wxDateSpan object with the result.
*/
- wxDateSpan Multiply(int factor);
- const wxDateSpan& Multiply(int factor);
- wxDateSpan operator*=(int factor);
- //@}
+ wxDateSpan Multiply(int factor) const;
+ /**
+ Multiplies this date span by the specified @a factor. The product is
+ computed by multiplying each of the components by the @a factor.
+
+ @returns A reference to this wxDateSpan object modified in place.
+ */
+ wxDateSpan& Multiply(int factor);
- //@{
/**
Changes the sign of this date span.
@see Negate()
*/
- wxDateSpan Neg();
- wxDateSpan operator-();
- //@}
+ wxDateSpan& Neg();
/**
- Returns the date span with the opposite sign.
+ Returns a date span with the opposite sign.
@see Neg()
*/
wxDateSpan Negate() const;
/**
- Sets the number of days (without modifying any other components) in this date
- span.
+ Sets the number of days (without modifying any other components) in
+ this date span.
*/
- wxDateSpan SetDays(int n);
+ wxDateSpan& SetDays(int n);
/**
- Sets the number of months (without modifying any other components) in this
- date span.
+ Sets the number of months (without modifying any other components) in
+ this date span.
*/
- wxDateSpan SetMonths(int n);
+ wxDateSpan& SetMonths(int n);
/**
- Sets the number of weeks (without modifying any other components) in this date
- span.
+ Sets the number of weeks (without modifying any other components) in
+ this date span.
*/
- wxDateSpan SetWeeks(int n);
+ wxDateSpan& SetWeeks(int n);
/**
- Sets the number of years (without modifying any other components) in this date
- span.
+ Sets the number of years (without modifying any other components) in
+ this date span.
*/
- wxDateSpan SetYears(int n);
+ wxDateSpan& SetYears(int n);
- //@{
/**
- Returns the difference of two date spans. The first version returns a new
- object, the second and third ones modify this object in place.
+ Returns the difference of two date spans.
+
+ @returns A new wxDateSpan object with the result.
*/
- wxDateSpan Subtract(const wxDateSpan& other);
- const wxDateSpan& Subtract(const wxDateSpan& other);
- wxDateSpan operator+=(const wxDateSpan& other);
- //@}
+ wxDateSpan Subtract(const wxDateSpan& other) const;
+ /**
+ Subtracts the given wxDateSpan to this wxDateSpan and returns a
+ reference to itself.
+ */
+ wxDateSpan& Subtract(const wxDateSpan& other);
/**
Returns a date span object corresponding to one week.
*/
static wxDateSpan Years(int years);
+ /**
+ Adds the given wxDateSpan to this wxDateSpan and returns the result.
+ */
+ wxDateSpan& operator+=(const wxDateSpan& other);
+
+ /**
+ Subtracts the given wxDateSpan to this wxDateSpan and returns the
+ result.
+ */
+ wxDateSpan& operator-=(const wxDateSpan& other);
+
+ /**
+ Changes the sign of this date span.
+
+ @see Negate()
+ */
+ wxDateSpan& operator-();
+
+ /**
+ Multiplies this date span by the specified @a factor. The product is
+ computed by multiplying each of the components by the @a factor.
+
+ @returns A reference to this wxDateSpan object modified in place.
+ */
+ wxDateSpan& operator*=(int factor);
+
/**
Returns @true if this date span is different from the other one.
*/
- bool operator!=(wxDateSpan& other) const;
+ bool operator!=(const wxDateSpan&) const;
/**
- Returns @true if this date span is equal to the other one. Two date spans
- are considered equal if and only if they have the same number of years and
- months and the same total number of days (counting both days and weeks).
+ Returns @true if this date span is equal to the other one. Two date
+ spans are considered equal if and only if they have the same number of
+ years and months and the same total number of days (counting both days
+ and weeks).
*/
- bool operator==(wxDateSpan& other) const;
+ bool operator==(const wxDateSpan&) const;
};
@library{wxbase}
@category{data}
- @see @ref overview_wxdatetimeoverview "Date classes overview", wxDateTime
+ @see @ref overview_datetime, wxDateTime
*/
class wxTimeSpan
{
public:
- //@{
/**
- Constructs timespan from separate values for each component, with the date
- set to 0. Hours are not restricted to 0..24 range, neither are
- minutes, seconds or milliseconds.
+ Default constructor, constructs a zero timespan.
*/
wxTimeSpan();
+ /**
+ Constructs timespan from separate values for each component, with the
+ date set to 0. Hours are not restricted to 0-24 range, neither are
+ minutes, seconds or milliseconds.
+ */
wxTimeSpan(long hours, long min, long sec, long msec);
- //@}
/**
- Returns the absolute value of the timespan: does not modify the
- object.
+ Returns the absolute value of the timespan: does not modify the object.
*/
wxTimeSpan Abs() const;
/**
- GetSeconds()
-
- GetMinutes()
+ Returns the sum of two time spans.
- GetHours()
-
- GetDays()
-
- GetWeeks()
-
- GetValue()
- */
-
-
- //@{
- /**
- Returns the sum of two timespans.
+ @returns A new wxDateSpan object with the result.
*/
- wxTimeSpan Add(const wxTimeSpan& diff);
- const wxTimeSpan& Add(const wxTimeSpan& diff);
- wxTimeSpan operator+=(const wxTimeSpan& diff);
- //@}
-
+ wxTimeSpan Add(const wxTimeSpan& diff) const;
/**
- @ref ctor() wxTimeSpan
+ Adds the given wxTimeSpan to this wxTimeSpan and returns a reference
+ to itself.
*/
-
+ wxTimeSpan& Add(const wxTimeSpan& diff);
/**
Returns the timespan for one day.
static wxTimespan Days(long days);
/**
- Returns the string containing the formatted representation of the time span.
- The following format specifiers are allowed after %:
-
- H
-
- number of @b Hours
-
- M
-
- number of @b Minutes
-
- S
+ Returns the string containing the formatted representation of the time
+ span. The following format specifiers are allowed after %:
- number of @b Seconds
+ - @c H - Number of Hours
+ - @c M - Number of Minutes
+ - @c S - Number of Seconds
+ - @c l - Number of Milliseconds
+ - @c D - Number of Days
+ - @c E - Number of Weeks
+ - @c % - The percent character
- l
+ Note that, for example, the number of hours in the description above is
+ not well defined: it can be either the total number of hours (for
+ example, for a time span of 50 hours this would be 50) or just the hour
+ part of the time span, which would be 2 in this case as 50 hours is
+ equal to 2 days and 2 hours.
- number of mi@b lliseconds
+ wxTimeSpan resolves this ambiguity in the following way: if there had
+ been, indeed, the @c %D format specified preceding the @c %H, then it
+ is interpreted as 2. Otherwise, it is 50.
- D
-
- number of @b Days
-
- E
-
- number of w@b Eeks
-
- %
-
- the percent character
-
- Note that, for example, the number of hours in the description above is not
- well defined: it can be either the total number of hours (for example, for a
- time span of 50 hours this would be 50) or just the hour part of the time
- span, which would be 2 in this case as 50 hours is equal to 2 days and
- 2 hours.
- wxTimeSpan resolves this ambiguity in the following way: if there had been,
- indeed, the @c %D format specified preceding the @c %H, then it is
- interpreted as 2. Otherwise, it is 50.
- The same applies to all other format specifiers: if they follow a specifier of
- larger unit, only the rest part is taken, otherwise the full value is used.
- */
- wxString Format(const wxChar* format = wxDefaultTimeSpanFormat);
-
- /**
- Format()
+ The same applies to all other format specifiers: if they follow a
+ specifier of larger unit, only the rest part is taken, otherwise the
+ full value is used.
*/
-
+ wxString Format(const wxString& = wxDefaultTimeSpanFormat) const;
/**
Returns the difference in number of days.
bool IsEqualTo(const wxTimeSpan& ts) const;
/**
- Compares two timespans: works with the absolute values, i.e. -2
- hours is longer than 1 hour. Also, it will return @false if
- the timespans are equal in absolute value.
+ Compares two timespans: works with the absolute values, i.e. -2 hours
+ is longer than 1 hour. Also, it will return @false if the timespans are
+ equal in absolute value.
*/
bool IsLongerThan(const wxTimeSpan& ts) const;
bool IsPositive() const;
/**
- Compares two timespans: works with the absolute values, i.e. 1
- hour is shorter than -2 hours. Also, it will return @false if
- the timespans are equal in absolute value.
+ Compares two timespans: works with the absolute values, i.e. 1 hour is
+ shorter than -2 hours. Also, it will return @false if the timespans are
+ equal in absolute value.
*/
bool IsShorterThan(const wxTimeSpan& ts) const;
*/
static wxTimespan Minutes(long min);
- //@{
/**
- Multiplies timespan by a scalar.
- */
- wxTimeSpan Multiply(int n);
- const wxTimeSpan& Multiply(int n);
- wxTimeSpan operator*=(int n);
- //@}
+ Returns the product of this time span by @a n.
- //@{
- /**
- Negate the value of the timespan.
+ @returns A new wxTimeSpan object with the result.
*/
- wxTimeSpan Neg();
- wxTimeSpan operator-();
- //@}
-
+ wxTimeSpan Multiply(int n) const;
/**
- Returns timespan with inverted sign.
+ Multiplies this time span by @a n.
+
+ @returns A reference to this wxTimeSpan object modified in place.
*/
- wxTimeSpan Negate() const;
+ wxTimeSpan& Multiply(int n);
/**
- Add()
-
- Subtract()
-
- Multiply()
+ Negate the value of the timespan.
- Negate()
+ @see Negate()
+ */
+ wxTimeSpan& Neg();
- Neg()
+ /**
+ Returns timespan with inverted sign.
- Abs()
+ @see Neg()
*/
-
+ wxTimeSpan Negate() const;
/**
Returns the timespan for one second.
static wxTimespan Seconds(long sec);
/**
- Milliseconds()
-
- Millisecond()
+ Returns the difference of two time spans.
- Seconds()
-
- Second()
-
- Minutes()
-
- Minute()
-
- Hours()
-
- Hour()
-
- Days()
-
- Day()
-
- Weeks()
-
- Week()
+ @returns A new wxDateSpan object with the result.
*/
-
-
- //@{
+ wxTimeSpan Subtract(const wxTimeSpan& diff) const;
/**
- Returns the difference of two timespans.
+ Subtracts the given wxTimeSpan to this wxTimeSpan and returns a
+ reference to itself.
*/
- wxTimeSpan Subtract(const wxTimeSpan& diff);
- const wxTimeSpan& Subtract(const wxTimeSpan& diff);
- wxTimeSpan operator-=(const wxTimeSpan& diff);
- //@}
+ wxTimeSpan& Subtract(const wxTimeSpan& diff);
/**
- IsNull()
-
- IsPositive()
+ Returns the timespan for one week.
+ */
+ static wxTimespan Week();
- IsNegative()
+ /**
+ Returns the timespan for the given number of weeks.
+ */
+ static wxTimespan Weeks(long weeks);
- IsEqualTo()
+ /**
+ Adds the given wxTimeSpan to this wxTimeSpan and returns the result.
+ */
+ wxTimeSpan& operator+=(const wxTimeSpan& diff);
- IsLongerThan()
+ /**
+ Multiplies this time span by @a n.
- IsShorterThan()
+ @returns A reference to this wxTimeSpan object modified in place.
*/
-
+ wxTimeSpan& operator*=(int n);
/**
- Returns the timespan for one week.
+ Negate the value of the timespan.
+
+ @see Negate()
*/
- static wxTimespan Week();
+ wxTimeSpan& operator-();
/**
- Returns the timespan for the given number of weeks.
+ Subtracts the given wxTimeSpan to this wxTimeSpan and returns the
+ result.
*/
- static wxTimespan Weeks(long weeks);
+ wxTimeSpan& operator-=(const wxTimeSpan& diff);
};
@class wxDateTimeHolidayAuthority
@wxheader{datetime.h}
+ @todo Write wxDateTimeHolidayAuthority documentation.
@library{wxbase}
- @category{FIXME}
+ @category{misc}
*/
class wxDateTimeHolidayAuthority
{