Version: 3.2.6
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() [1/2]

wxTimeSpan::wxTimeSpan ( )

Default constructor, constructs a zero timespan.

◆ wxTimeSpan() [2/2]

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

◆ Abs()

wxTimeSpan wxTimeSpan::Abs ( ) const

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

◆ Add() [1/2]

wxTimeSpan& wxTimeSpan::Add ( const wxTimeSpan diff)

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

◆ Add() [2/2]

wxTimeSpan wxTimeSpan::Add ( const wxTimeSpan diff) const

Returns the sum of two time spans.

Returns
A new wxDateSpan object with the result.

◆ Day()

static wxTimeSpan wxTimeSpan::Day ( )
static

Returns the timespan for one day.

◆ Days()

static wxTimeSpan wxTimeSpan::Days ( long  days)
static

Returns the timespan for the given number of days.

◆ Format()

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.

◆ GetDays()

int wxTimeSpan::GetDays ( ) const

Returns the difference in number of days.

◆ GetHours()

int wxTimeSpan::GetHours ( ) const

Returns the difference in number of hours.

◆ GetMilliseconds()

wxLongLong wxTimeSpan::GetMilliseconds ( ) const

Returns the difference in number of milliseconds.

◆ GetMinutes()

int wxTimeSpan::GetMinutes ( ) const

Returns the difference in number of minutes.

◆ GetSeconds()

wxLongLong wxTimeSpan::GetSeconds ( ) const

Returns the difference in number of seconds.

◆ GetValue()

wxLongLong wxTimeSpan::GetValue ( ) const

Returns the internal representation of timespan.

◆ GetWeeks()

int wxTimeSpan::GetWeeks ( ) const

Returns the difference in number of weeks.

◆ Hour()

static wxTimeSpan wxTimeSpan::Hour ( )
static

Returns the timespan for one hour.

◆ Hours()

static wxTimeSpan wxTimeSpan::Hours ( long  hours)
static

Returns the timespan for the given number of hours.

◆ IsEqualTo()

bool wxTimeSpan::IsEqualTo ( const wxTimeSpan ts) const

Returns true if two timespans are equal.

◆ IsLongerThan()

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.

◆ IsNegative()

bool wxTimeSpan::IsNegative ( ) const

Returns true if the timespan is negative.

◆ IsNull()

bool wxTimeSpan::IsNull ( ) const

Returns true if the timespan is empty.

◆ IsPositive()

bool wxTimeSpan::IsPositive ( ) const

Returns true if the timespan is positive.

◆ IsShorterThan()

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.

◆ Millisecond()

static wxTimeSpan wxTimeSpan::Millisecond ( )
static

Returns the timespan for one millisecond.

◆ Milliseconds()

static wxTimeSpan wxTimeSpan::Milliseconds ( wxLongLong  ms)
static

Returns the timespan for the given number of milliseconds.

◆ Minute()

static wxTimeSpan wxTimeSpan::Minute ( )
static

Returns the timespan for one minute.

◆ Minutes()

static wxTimeSpan wxTimeSpan::Minutes ( long  min)
static

Returns the timespan for the given number of minutes.

◆ Multiply() [1/2]

wxTimeSpan& wxTimeSpan::Multiply ( int  n)

Multiplies this time span by n.

Returns
A reference to this wxTimeSpan object modified in place.

◆ Multiply() [2/2]

wxTimeSpan wxTimeSpan::Multiply ( int  n) const

Returns the product of this time span by n.

Returns
A new wxTimeSpan object with the result.

◆ Neg()

wxTimeSpan& wxTimeSpan::Neg ( )

Negate the value of the timespan.

See also
Negate()

◆ Negate()

wxTimeSpan wxTimeSpan::Negate ( ) const

Returns timespan with inverted sign.

See also
Neg()

◆ operator*=()

wxTimeSpan& wxTimeSpan::operator*= ( int  n)

Multiplies this time span by n.

Returns
A reference to this wxTimeSpan object modified in place.

◆ operator+=()

wxTimeSpan& wxTimeSpan::operator+= ( const wxTimeSpan diff)

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

◆ operator-()

wxTimeSpan& wxTimeSpan::operator- ( )

Negate the value of the timespan.

See also
Negate()

◆ operator-=()

wxTimeSpan& wxTimeSpan::operator-= ( const wxTimeSpan diff)

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

◆ Second()

static wxTimeSpan wxTimeSpan::Second ( )
static

Returns the timespan for one second.

◆ Seconds()

static wxTimeSpan wxTimeSpan::Seconds ( wxLongLong  sec)
static

Returns the timespan for the given number of seconds.

◆ Subtract() [1/2]

wxTimeSpan& wxTimeSpan::Subtract ( const wxTimeSpan diff)

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

◆ Subtract() [2/2]

wxTimeSpan wxTimeSpan::Subtract ( const wxTimeSpan diff) const

Returns the difference of two time spans.

Returns
A new wxDateSpan object with the result.

◆ Week()

static wxTimeSpan wxTimeSpan::Week ( )
static

Returns the timespan for one week.

◆ Weeks()

static wxTimeSpan wxTimeSpan::Weeks ( long  weeks)
static

Returns the timespan for the given number of weeks.