Version: 3.0.3
wxTimeSpan Class Reference

#include <wx/datetime.h>

Detailed Description

wxTimeSpan class represents a time interval.

Library:  wxBase
Category:  Data Structures
See also
Date and Time, wxDateTime

Public Member Functions

 wxTimeSpan ()
 Default constructor, constructs a zero timespan. More...
 
 wxTimeSpan (long hours, long min=0, wxLongLong sec=0, wxLongLong msec=0)
 Constructs timespan from separate values for each component, with the date set to 0. More...
 
wxTimeSpan Abs () const
 Returns the absolute value of the timespan: does not modify the object. More...
 
wxTimeSpan Add (const wxTimeSpan &diff) const
 Returns the sum of two time spans. More...
 
wxTimeSpanAdd (const wxTimeSpan &diff)
 Adds the given wxTimeSpan to this wxTimeSpan and returns a reference to itself. More...
 
wxString Format (const wxString &format=wxDefaultTimeSpanFormat) const
 Returns the string containing the formatted representation of the time span. More...
 
int GetDays () const
 Returns the difference in number of days. More...
 
int GetHours () const
 Returns the difference in number of hours. More...
 
wxLongLong GetMilliseconds () const
 Returns the difference in number of milliseconds. More...
 
int GetMinutes () const
 Returns the difference in number of minutes. More...
 
wxLongLong GetSeconds () const
 Returns the difference in number of seconds. More...
 
wxLongLong GetValue () const
 Returns the internal representation of timespan. More...
 
int GetWeeks () const
 Returns the difference in number of weeks. More...
 
bool IsEqualTo (const wxTimeSpan &ts) const
 Returns true if two timespans are equal. More...
 
bool IsLongerThan (const wxTimeSpan &ts) const
 Compares two timespans: works with the absolute values, i.e. -2 hours is longer than 1 hour. More...
 
bool IsNegative () const
 Returns true if the timespan is negative. More...
 
bool IsNull () const
 Returns true if the timespan is empty. More...
 
bool IsPositive () const
 Returns true if the timespan is positive. More...
 
bool IsShorterThan (const wxTimeSpan &ts) const
 Compares two timespans: works with the absolute values, i.e. 1 hour is shorter than -2 hours. More...
 
wxTimeSpan Multiply (int n) const
 Returns the product of this time span by n. More...
 
wxTimeSpanMultiply (int n)
 Multiplies this time span by n. More...
 
wxTimeSpanNeg ()
 Negate the value of the timespan. More...
 
wxTimeSpan Negate () const
 Returns timespan with inverted sign. More...
 
wxTimeSpan Subtract (const wxTimeSpan &diff) const
 Returns the difference of two time spans. More...
 
wxTimeSpanSubtract (const wxTimeSpan &diff)
 Subtracts the given wxTimeSpan to this wxTimeSpan and returns a reference to itself. More...
 
wxTimeSpanoperator+= (const wxTimeSpan &diff)
 Adds the given wxTimeSpan to this wxTimeSpan and returns the result. More...
 
wxTimeSpanoperator*= (int n)
 Multiplies this time span by n. More...
 
wxTimeSpanoperator- ()
 Negate the value of the timespan. More...
 
wxTimeSpanoperator-= (const wxTimeSpan &diff)
 Subtracts the given wxTimeSpan to this wxTimeSpan and returns the result. More...
 

Static Public Member Functions

static wxTimeSpan Day ()
 Returns the timespan for one day. More...
 
static wxTimeSpan Days (long days)
 Returns the timespan for the given number of days. More...
 
static wxTimeSpan Hour ()
 Returns the timespan for one hour. More...
 
static wxTimeSpan Hours (long hours)
 Returns the timespan for the given number of hours. More...
 
static wxTimeSpan Millisecond ()
 Returns the timespan for one millisecond. More...
 
static wxTimeSpan Milliseconds (wxLongLong ms)
 Returns the timespan for the given number of milliseconds. More...
 
static wxTimeSpan Minute ()
 Returns the timespan for one minute. More...
 
static wxTimeSpan Minutes (long min)
 Returns the timespan for the given number of minutes. More...
 
static wxTimeSpan Second ()
 Returns the timespan for one second. More...
 
static wxTimeSpan Seconds (wxLongLong sec)
 Returns the timespan for the given number of seconds. More...
 
static wxTimeSpan Week ()
 Returns the timespan for one week. More...
 
static wxTimeSpan Weeks (long weeks)
 Returns the timespan for the given number of weeks. More...
 

Constructor & Destructor Documentation

wxTimeSpan::wxTimeSpan ( )

Default constructor, constructs a zero timespan.

wxTimeSpan::wxTimeSpan ( long  hours,
long  min = 0,
wxLongLong  sec = 0,
wxLongLong  msec = 0 
)

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.

Member Function Documentation

wxTimeSpan wxTimeSpan::Abs ( ) const

Returns the absolute value of the timespan: does not modify the object.

wxTimeSpan wxTimeSpan::Add ( const wxTimeSpan diff) const

Returns the sum of two time spans.

Returns
A new wxDateSpan object with the result.
wxTimeSpan& wxTimeSpan::Add ( const wxTimeSpan diff)

Adds the given wxTimeSpan to this wxTimeSpan and returns a reference to itself.

static wxTimeSpan wxTimeSpan::Day ( )
static

Returns the timespan for one day.

static wxTimeSpan wxTimeSpan::Days ( long  days)
static

Returns the timespan for the given number of days.

wxString wxTimeSpan::Format ( const wxString format = wxDefaultTimeSpanFormat) const

Returns the string containing the formatted representation of the time span.

The following format specifiers are allowed after %:

  • H - Number of Hours
  • M - Number of Minutes
  • S - Number of Seconds
  • l - Number of Milliseconds
  • D - Number of Days
  • E - Number of Weeks
  • % - 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 D format specified preceding the 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.

int wxTimeSpan::GetDays ( ) const

Returns the difference in number of days.

int wxTimeSpan::GetHours ( ) const

Returns the difference in number of hours.

wxLongLong wxTimeSpan::GetMilliseconds ( ) const

Returns the difference in number of milliseconds.

int wxTimeSpan::GetMinutes ( ) const

Returns the difference in number of minutes.

wxLongLong wxTimeSpan::GetSeconds ( ) const

Returns the difference in number of seconds.

wxLongLong wxTimeSpan::GetValue ( ) const

Returns the internal representation of timespan.

int wxTimeSpan::GetWeeks ( ) const

Returns the difference in number of weeks.

static wxTimeSpan wxTimeSpan::Hour ( )
static

Returns the timespan for one hour.

static wxTimeSpan wxTimeSpan::Hours ( long  hours)
static

Returns the timespan for the given number of hours.

bool wxTimeSpan::IsEqualTo ( const wxTimeSpan ts) const

Returns true if two timespans are equal.

bool wxTimeSpan::IsLongerThan ( 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.

bool wxTimeSpan::IsNegative ( ) const

Returns true if the timespan is negative.

bool wxTimeSpan::IsNull ( ) const

Returns true if the timespan is empty.

bool wxTimeSpan::IsPositive ( ) const

Returns true if the timespan is positive.

bool wxTimeSpan::IsShorterThan ( const wxTimeSpan ts) 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.

static wxTimeSpan wxTimeSpan::Millisecond ( )
static

Returns the timespan for one millisecond.

static wxTimeSpan wxTimeSpan::Milliseconds ( wxLongLong  ms)
static

Returns the timespan for the given number of milliseconds.

static wxTimeSpan wxTimeSpan::Minute ( )
static

Returns the timespan for one minute.

static wxTimeSpan wxTimeSpan::Minutes ( long  min)
static

Returns the timespan for the given number of minutes.

wxTimeSpan wxTimeSpan::Multiply ( int  n) const

Returns the product of this time span by n.

Returns
A new wxTimeSpan object with the result.
wxTimeSpan& wxTimeSpan::Multiply ( int  n)

Multiplies this time span by n.

Returns
A reference to this wxTimeSpan object modified in place.
wxTimeSpan& wxTimeSpan::Neg ( )

Negate the value of the timespan.

See also
Negate()
wxTimeSpan wxTimeSpan::Negate ( ) const

Returns timespan with inverted sign.

See also
Neg()
wxTimeSpan& wxTimeSpan::operator*= ( int  n)

Multiplies this time span by n.

Returns
A reference to this wxTimeSpan object modified in place.
wxTimeSpan& wxTimeSpan::operator+= ( const wxTimeSpan diff)

Adds the given wxTimeSpan to this wxTimeSpan and returns the result.

wxTimeSpan& wxTimeSpan::operator- ( )

Negate the value of the timespan.

See also
Negate()
wxTimeSpan& wxTimeSpan::operator-= ( const wxTimeSpan diff)

Subtracts the given wxTimeSpan to this wxTimeSpan and returns the result.

static wxTimeSpan wxTimeSpan::Second ( )
static

Returns the timespan for one second.

static wxTimeSpan wxTimeSpan::Seconds ( wxLongLong  sec)
static

Returns the timespan for the given number of seconds.

wxTimeSpan wxTimeSpan::Subtract ( const wxTimeSpan diff) const

Returns the difference of two time spans.

Returns
A new wxDateSpan object with the result.
wxTimeSpan& wxTimeSpan::Subtract ( const wxTimeSpan diff)

Subtracts the given wxTimeSpan to this wxTimeSpan and returns a reference to itself.

static wxTimeSpan wxTimeSpan::Week ( )
static

Returns the timespan for one week.

static wxTimeSpan wxTimeSpan::Weeks ( long  weeks)
static

Returns the timespan for the given number of weeks.