TSDuck v3.44-4572
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches

The ISOTime class convert dates, times, and durations with ISO 8601 representation. More...

#include <tsISOTime.h>

Public Types

enum  TimeType {
  NONE = 0x00 ,
  TIME = 0x01 ,
  DURATION = 0x02 ,
  START_END = 0x04 ,
  START_DURATION = 0x08 ,
  DURATION_END = 0x10 ,
  RECURRING = 0x20 ,
  ANY_INTERVAL = 0x1E ,
  ANY = 0x3F
}
 Type of time data which can be represented in ISO 8601. More...
 

Public Member Functions

 ISOTime ()=default
 Default constructor.
 
template<class Rep , class Period >
 ISOTime (cn::duration< Rep, Period > duration, const Time &end, size_t recurrences=0)
 Constructor using a duration and an end.
 
template<class Rep , class Period >
 ISOTime (cn::duration< Rep, Period > duration, size_t recurrences=0)
 Constructor using a duration not associated with any start or end.
 
template<class Rep , class Period >
 ISOTime (const Time &start, cn::duration< Rep, Period > duration, size_t recurrences=0)
 Constructor using a start and a duration.
 
 ISOTime (const Time &start, const Time &end, size_t recurrences=0)
 Constructor using a start and end date.
 
 ISOTime (const Time &time)
 Constructor using one date & time value.
 
 ISOTime (const UString &str)
 Constructor from a string in ISO 8601 format.
 
void clear ()
 Reset the content of the object to an invalid state.
 
cn::milliseconds duration () const
 Get the duration of the time interval.
 
Time end () const
 Get the time interval end time.
 
bool fromString (const UString &str)
 Set the value of this object from a string in ISO 8601 format.
 
bool isInterval () const
 Check if this object contains a time interval (recurring or not).
 
bool isRecurring () const
 Check if this object contains a recurring interval.
 
bool isSingleTime () const
 Check if this object contains a single date & time value.
 
bool isUnbounded () const
 Check if this object contains an unbounded recurring interval.
 
bool isValid () const
 Check if this object contains a valid value.
 
 operator Time () const
 Conversion to a Time value.
 
size_t recurrences () const
 Get the number of recurrences of the time interval.
 
Time start () const
 Get the time interval start time.
 
UString toString (TimeType format=NONE) const
 Format this object as a ISO 8601 string.
 
TimeType type () const
 Get the type of ISO 8601 time data.
 

Static Public Member Functions

static cn::milliseconds DurationFromISO (const UString &str)
 Decode a duration from an ISO 8601 representation.
 
static Time TimeFromISO (const UString &str)
 Decode a time from an ISO 8601 representation.
 
template<class Rep , class Period >
static UString ToISO (cn::duration< Rep, Period > duration)
 Format a duration in ISO 8601 representation.
 
static UString ToISO (const Time &time)
 Format a time in ISO 8601 representation.
 
template<class Rep , class Period >
static UString ToISO (const Time &time, cn::duration< Rep, Period > utc_offset)
 Format a time in ISO 8601 representation, including an offset from UTC time.
 

Static Public Attributes

static constexpr size_t UNBOUNDED_RECURRENCES = std::numeric_limits<size_t>::max()
 Number of time-interval recurrences meaning "unbounded".
 

Detailed Description

The ISOTime class convert dates, times, and durations with ISO 8601 representation.

Member Enumeration Documentation

◆ TimeType

Type of time data which can be represented in ISO 8601.

Enumerator
NONE 

No data, invalid object.

TIME 

One date & time value.

DURATION 

A duration not associated with any start or end.

START_END 

A start and an end.

START_DURATION 

A start and a duration.

DURATION_END 

A duration and an end.

RECURRING 

Additional flag: recurring time interval.

ANY_INTERVAL 

A bit mask of all time-interval formats (non-recurring).

ANY 

A bit mask of all possible formats.

Constructor & Destructor Documentation

◆ ISOTime() [1/6]

ts::ISOTime::ISOTime ( const UString str)
inline

Constructor from a string in ISO 8601 format.

Parameters
[in]strA string in ISO 8601 format.

◆ ISOTime() [2/6]

ts::ISOTime::ISOTime ( const Time time)
inline

Constructor using one date & time value.

Parameters
[in]timeThe date & time to set.

◆ ISOTime() [3/6]

template<class Rep , class Period >
ts::ISOTime::ISOTime ( cn::duration< Rep, Period >  duration,
size_t  recurrences = 0 
)
inline

Constructor using a duration not associated with any start or end.

Parameters
[in]durationTime interval duration.
[in]recurrencesIf non-zero, the time-interval is recurring, with that number of recurrences.

◆ ISOTime() [4/6]

ts::ISOTime::ISOTime ( const Time start,
const Time end,
size_t  recurrences = 0 
)
inline

Constructor using a start and end date.

Parameters
[in]startInterval start time.
[in]endInterval end time.
[in]recurrencesIf non-zero, the time-interval is recurring, with that number of recurrences.

◆ ISOTime() [5/6]

template<class Rep , class Period >
ts::ISOTime::ISOTime ( const Time start,
cn::duration< Rep, Period >  duration,
size_t  recurrences = 0 
)
inline

Constructor using a start and a duration.

Parameters
[in]startInterval start time.
[in]durationTime interval duration.
[in]recurrencesIf non-zero, the time-interval is recurring, with that number of recurrences.

◆ ISOTime() [6/6]

template<class Rep , class Period >
ts::ISOTime::ISOTime ( cn::duration< Rep, Period >  duration,
const Time end,
size_t  recurrences = 0 
)
inline

Constructor using a duration and an end.

Parameters
[in]durationTime interval duration.
[in]endInterval end time.
[in]recurrencesIf non-zero, the time-interval is recurring, with that number of recurrences.

Member Function Documentation

◆ isValid()

bool ts::ISOTime::isValid ( ) const
inline

Check if this object contains a valid value.

Returns
True if this object contains a valid value, false otherwise.

◆ isSingleTime()

bool ts::ISOTime::isSingleTime ( ) const
inline

Check if this object contains a single date & time value.

Returns
True if this object contains a single date & time value, false otherwise.

◆ isInterval()

bool ts::ISOTime::isInterval ( ) const
inline

Check if this object contains a time interval (recurring or not).

Returns
True if this object contains a time interval, false otherwise.

◆ isRecurring()

bool ts::ISOTime::isRecurring ( ) const
inline

Check if this object contains a recurring interval.

Returns
True if this object contains a recurring interval, false otherwise.

◆ isUnbounded()

bool ts::ISOTime::isUnbounded ( ) const
inline

Check if this object contains an unbounded recurring interval.

Returns
True if this object contains an unbounded recurring interval, false otherwise.

◆ type()

TimeType ts::ISOTime::type ( ) const
inline

Get the type of ISO 8601 time data.

Returns
The type of ISO 8601 time data.

◆ toString()

UString ts::ISOTime::toString ( TimeType  format = NONE) const

Format this object as a ISO 8601 string.

Parameters
[in]formatRequired format. In NONE, use the default format for that object.
Returns
The corresponding ISO 8601 string.

◆ fromString()

bool ts::ISOTime::fromString ( const UString str)

Set the value of this object from a string in ISO 8601 format.

Parameters
[in]strA string in ISO 8601 format.
Returns
True on success, false on error (the object is then invalid).

◆ operator Time()

ts::ISOTime::operator Time ( ) const
inline

Conversion to a Time value.

Returns
The single date and time or the start date for a time interval. Return ts::Time::Epoch on error.

◆ start()

Time ts::ISOTime::start ( ) const

Get the time interval start time.

Returns
The start date for a time interval or single date and time. Return ts::Time::Epoch on error.

◆ end()

Time ts::ISOTime::end ( ) const

Get the time interval end time.

Returns
The end date for a time interval or single date and time. Return ts::Time::Epoch on error.

◆ duration()

cn::milliseconds ts::ISOTime::duration ( ) const

Get the duration of the time interval.

Returns
The duration of the time interval, zero otherwise.

◆ recurrences()

size_t ts::ISOTime::recurrences ( ) const
inline

Get the number of recurrences of the time interval.

Returns
The number of recurrences of the time interval for a recurring interval, zero otherwise.

◆ TimeFromISO()

static Time ts::ISOTime::TimeFromISO ( const UString str)
static

Decode a time from an ISO 8601 representation.

Missing date fields default to the current UTC time. Missing time fields default to zero. The mpeg7:timePointType format is an extension of ISO 8601 and is also recognized here.

Parameters
[in]strA string describing a date and time in ISO 8601 representation.
Returns
The converted time or ts::Time::Epoch if the string cannot be decoded.

◆ DurationFromISO()

static cn::milliseconds ts::ISOTime::DurationFromISO ( const UString str)
static

Decode a duration from an ISO 8601 representation.

Parameters
[in]strA string describing a duration in ISO 8601 representation.
Returns
The converted duration in milliseconds or a negative value if the string cannot be decoded.

◆ ToISO() [1/3]

static UString ts::ISOTime::ToISO ( const Time time)
inlinestatic

Format a time in ISO 8601 representation.

Parameters
[in]timeThe date and time to format.
Returns
A string describing the date and time in ISO 8601 representation.

◆ ToISO() [2/3]

template<class Rep , class Period >
static UString ts::ISOTime::ToISO ( const Time time,
cn::duration< Rep, Period >  utc_offset 
)
inlinestatic

Format a time in ISO 8601 representation, including an offset from UTC time.

Parameters
[in]timeThe date and time to format.
[in]utc_offsetThe offset from UTC time to include in the representation.
Returns
A string describing the date and time in ISO 8601 representation.

◆ ToISO() [3/3]

template<class Rep , class Period >
static UString ts::ISOTime::ToISO ( cn::duration< Rep, Period >  duration)
inlinestatic

Format a duration in ISO 8601 representation.

Parameters
[in]durationTime interval duration.
Returns
A string describing the duration in ISO 8601 representation.

The documentation for this class was generated from the following file: