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

Static Public Member Functions

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

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.