DCMTK Version 3.6.8
OFFIS DICOM Toolkit
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Private Attributes | Friends | List of all members
OFTime Class Reference

This class provides a collection of time functions. More...

Public Member Functions

 OFTime ()
 default constructor. More...
 
 OFTime (const OFTime &timeVal)
 copy constructor More...
 
 OFTime (const unsigned int hour, const unsigned int minute, const double second, const double timeZone=0)
 constructor with init values More...
 
virtual ~OFTime ()
 destructor
 
virtual OFTimeoperator= (const OFTime &timeVal)
 assignment operator More...
 
virtual OFBool operator== (const OFTime &timeVal) const
 comparison operator (equal). More...
 
virtual OFBool operator!= (const OFTime &timeVal) const
 comparison operator (unequal) Please note that the time values are first transformed to the Coordinated Universal Time (UTC) before they are compared. More...
 
virtual OFBool operator< (const OFTime &timeVal) const
 comparison operator (less than) Please note that the time values are first transformed to the Coordinated Universal Time (UTC) before they are compared. More...
 
virtual OFBool operator<= (const OFTime &timeVal) const
 comparison operator (less than or equal) Please note that the time values are first transformed to the Coordinated Universal Time (UTC) before they are compared. More...
 
virtual OFBool operator>= (const OFTime &timeVal) const
 comparison operator (greater than or equal) Please note that the time values are first transformed to the Coordinated Universal Time (UTC) before they are compared. More...
 
virtual OFBool operator> (const OFTime &timeVal) const
 comparison operator (greater than) Please note that the time values are first transformed to the Coordinated Universal Time (UTC) before they are compared. More...
 
virtual void clear ()
 reset the time value. More...
 
virtual OFBool isValid () const
 check whether the currently stored time value is valid. More...
 
OFBool setTime (const unsigned int hour, const unsigned int minute, const double second, const double timeZone=0)
 set the time value to the specified time. More...
 
OFBool setHour (const unsigned int hour)
 set the time value to the specified hour. More...
 
OFBool setMinute (const unsigned int minute)
 set the time value to the specified minute. More...
 
OFBool setSecond (const double second)
 set the time value to the specified second. More...
 
OFBool setTimeZone (const double timeZone)
 set the time zone to the specified value. More...
 
OFBool setTimeZone (const signed int hour, const unsigned int minute)
 set the time zone to the specified value. More...
 
OFBool setTimeInSeconds (const double seconds, const double timeZone=0, const OFBool normalize=OFTrue)
 set the time to the specified number of seconds More...
 
OFBool setTimeInHours (const double hours, const double timeZone=0, const OFBool normalize=OFTrue)
 set the time to the specified number of hours More...
 
OFBool setCurrentTime ()
 set the time value to the current system time. More...
 
OFBool setISOFormattedTime (const OFString &formattedTime)
 set the time value to the given ISO formatted time string. More...
 
unsigned int getHour () const
 get the currently stored hour value More...
 
unsigned int getMinute () const
 get the currently stored minute value More...
 
double getSecond () const
 get the currently stored second value More...
 
unsigned int getIntSecond () const
 get the integral part of the currently stored second value More...
 
unsigned int getMilliSecond () const
 get the milli second part of the currently stored second value More...
 
unsigned int getMicroSecond () const
 get the micro second part of the currently stored second value More...
 
double getTimeZone () const
 get the currently stored time zone value. More...
 
double getTimeInSeconds (const OFBool useTimeZone=OFFalse, const OFBool normalize=OFTrue) const
 get the currently stored time in seconds More...
 
double getTimeInHours (const OFBool useTimeZone=OFFalse, const OFBool normalize=OFTrue) const
 get the currently stored time in hours. More...
 
OFTime getCoordinatedUniversalTime () const
 get the currently stored time as Coordinated Universal Time. More...
 
OFTime getLocalTime () const
 get the currently stored time in local time. More...
 
OFBool getISOFormattedTime (OFString &formattedTime, const OFBool showSeconds=OFTrue, const OFBool showFraction=OFFalse, const OFBool showTimeZone=OFFalse, const OFBool showDelimiter=OFTrue, const OFString &timeZoneSeparator=" ") const
 get the current time value in ISO format. More...
 

Static Public Member Functions

static OFTime getCurrentTime ()
 get the current system time More...
 
static double getLocalTimeZone ()
 get the local time zone. More...
 

Protected Member Functions

OFBool setCurrentTime (const time_t &tt)
 set the time value to the current system time. More...
 

Static Protected Member Functions

static OFBool isTimeValid (const unsigned int hour, const unsigned int minute, const double second, const double timeZone)
 check whether the given time is valid. More...
 
static double getTimeInSeconds (const unsigned int hour, const unsigned int minute, const double second, const double timeZone=0, const OFBool normalize=OFTrue)
 get the given time in seconds. More...
 
static double getTimeInHours (const unsigned int hour, const unsigned int minute, const double second, const double timeZone=0, const OFBool normalize=OFTrue)
 get the given time in hours. More...
 

Private Attributes

unsigned int Hour
 currently stored hour value
 
unsigned int Minute
 currently stored minute value
 
double Second
 currently stored second value (incl. fraction of seconds)
 
double TimeZone
 currently stored time zone value
 

Friends

class OFDateTime
 

Detailed Description

This class provides a collection of time functions.

Note
Please note that support for the leap second is limited: a value of 60 seconds is accepted (i.e. regarded as valid) but calculations based on such a time value might be incorrect.

Constructor & Destructor Documentation

◆ OFTime() [1/3]

OFTime::OFTime ( )

default constructor.

Initializes Hour, Minute, Second and TimeZone to 0.

◆ OFTime() [2/3]

OFTime::OFTime ( const OFTime timeVal)

copy constructor

Parameters
timeValtime object to be copied

◆ OFTime() [3/3]

OFTime::OFTime ( const unsigned int  hour,
const unsigned int  minute,
const double  second,
const double  timeZone = 0 
)

constructor with init values

Parameters
hourhour value to be set
minuteminute value to be set
secondsecond value to be set (incl. fraction of seconds)
timeZoneoptional offset to Coordinated Universal Time (UTC) in hours

Member Function Documentation

◆ clear()

virtual void OFTime::clear ( )
virtual

reset the time value.

Sets the hour, minute, second and time zone to "0".

◆ getCoordinatedUniversalTime()

OFTime OFTime::getCoordinatedUniversalTime ( ) const

get the currently stored time as Coordinated Universal Time.

The resulting time object always has a time zone of "+00:00" since the time is corrected regarding the Coordinated Universal Time (UTC).

Returns
time object with the UTC corrected time set

◆ getCurrentTime()

static OFTime OFTime::getCurrentTime ( )
static

get the current system time

Returns
time object with the current system time set

◆ getHour()

unsigned int OFTime::getHour ( ) const

get the currently stored hour value

Returns
hour value (might be invalid, i.e. out of range)

◆ getIntSecond()

unsigned int OFTime::getIntSecond ( ) const

get the integral part of the currently stored second value

Returns
second value (might be invalid, i.e. out of range)

◆ getISOFormattedTime()

OFBool OFTime::getISOFormattedTime ( OFString formattedTime,
const OFBool  showSeconds = OFTrue,
const OFBool  showFraction = OFFalse,
const OFBool  showTimeZone = OFFalse,
const OFBool  showDelimiter = OFTrue,
const OFString timeZoneSeparator = " " 
) const

get the current time value in ISO format.

The two ISO time formats supported by this function are

  • "HH:MM[:SS[.FFFFFF]] [&ZZ:ZZ]" (with delimiters) and
  • "HHMM[SS[.FFFFFF]][&ZZZZ]" (without delimiters, useful for DICOM time type) where the brackets enclose optional parts.
    Parameters
    formattedTimereference to string variable where the result is stored
    showSecondsadd optional seconds (":SS" or "SS") to the resulting string if OFTrue
    showFractionadd optional fractional part of a second (".FFFFFF") if OFTrue. Requires parameter 'seconds' to be also OFTrue.
    showTimeZoneadd optional time zone ("&ZZ:ZZ" or "&ZZZZ") to the resulting string if OFTrue. The time zone indicates the offset from the Coordinated Universal Time (UTC) in hours and minutes. The "&" is a placeholder for the sign symbol ("+" or "-").
    showDelimiterflag, indicating whether to use delimiters (":") or not
    timeZoneSeparatorseparator between ISO time value and time zone. Only used if 'showDelimiter' is true.
    Returns
    OFTrue if result variable has been set, OFFalse otherwise

◆ getLocalTime()

OFTime OFTime::getLocalTime ( ) const

get the currently stored time in local time.

The resulting time object always has the local time zone.

Returns
time object with the corrected time set

◆ getLocalTimeZone()

static double OFTime::getLocalTimeZone ( )
static

get the local time zone.

This function uses operating system dependent routines. If they are unavailable for some reason the Coordinated Universal Time is assumed (time zone offset = 0). Also please note that time zones in the range ]+12.0,+14.0] cannot be detected due to the internally used algorithm.

Returns
local time zone if available, 0 otherwise

◆ getMicroSecond()

unsigned int OFTime::getMicroSecond ( ) const

get the micro second part of the currently stored second value

Returns
micro second part (0..999999)

◆ getMilliSecond()

unsigned int OFTime::getMilliSecond ( ) const

get the milli second part of the currently stored second value

Returns
milli second part (0..999)

◆ getMinute()

unsigned int OFTime::getMinute ( ) const

get the currently stored minute value

Returns
minute value (might be invalid, i.e. out of range)

◆ getSecond()

double OFTime::getSecond ( ) const

get the currently stored second value

Returns
second value (might be invalid, i.e. out of range)

◆ getTimeInHours() [1/2]

double OFTime::getTimeInHours ( const OFBool  useTimeZone = OFFalse,
const OFBool  normalize = OFTrue 
) const

get the currently stored time in hours.

Parameters
useTimeZoneuse the currently set time zone to correct the result
normalizeif OFTrue results larger than or equal 24.0 (hours) are normalized to a valid range
Returns
number of hours since "00:00:00" (incl. fraction of hours)

◆ getTimeInHours() [2/2]

static double OFTime::getTimeInHours ( const unsigned int  hour,
const unsigned int  minute,
const double  second,
const double  timeZone = 0,
const OFBool  normalize = OFTrue 
)
staticprotected

get the given time in hours.

Parameters
hourhour value of the given time
minuteminute value of the given time
secondsecond value of the given time
timeZoneoffset to Coordinated Universal Time (UTC) in hours
normalizeif OFTrue results larger than or equal 24.0 (hours) are normalized to a valid range
Returns
number of hours since "00:00:00" (incl. fraction of hours)

◆ getTimeInSeconds() [1/2]

double OFTime::getTimeInSeconds ( const OFBool  useTimeZone = OFFalse,
const OFBool  normalize = OFTrue 
) const

get the currently stored time in seconds

Parameters
useTimeZoneuse the currently set time zone to correct the result
normalizeif OFTrue results larger than or equal 86400.0 (seconds) are normalized to a valid range
Returns
number of seconds since "00:00:00"

◆ getTimeInSeconds() [2/2]

static double OFTime::getTimeInSeconds ( const unsigned int  hour,
const unsigned int  minute,
const double  second,
const double  timeZone = 0,
const OFBool  normalize = OFTrue 
)
staticprotected

get the given time in seconds.

Parameters
hourhour value of the given time
minuteminute value of the given time
secondsecond value of the given time
timeZoneoffset to Coordinated Universal Time (UTC) in hours
normalizeif OFTrue results larger than or equal 86400.0 (seconds) are normalized to a valid range
Returns
number of seconds since "00:00:00"

◆ getTimeZone()

double OFTime::getTimeZone ( ) const

get the currently stored time zone value.

The time zone is given as the offset (in hours) to the Coordinated Universal Time (UTC). Valid values are for instance "+1.0" (plus one hour) and "-2.5" (minus two and a half hour, i.e. 2 hours and 30 minutes).

Returns
time zone value (might be invalid, i.e. out of range)

◆ isTimeValid()

static OFBool OFTime::isTimeValid ( const unsigned int  hour,
const unsigned int  minute,
const double  second,
const double  timeZone 
)
staticprotected

check whether the given time is valid.

Valid ranges: [0,24[ for 'hour', [0,60[ for 'minute', [0.0,60.0[ for 'second' and [-12.0,+14.0] for 'timeZone'

Parameters
hourhour value to be checked
minuteminute value to be checked
secondsecond value to be checked
timeZoneoffset to Coordinated Universal Time (UTC) in hours
Returns
OFTrue if the current value is valid, OFFalse otherwise

◆ isValid()

virtual OFBool OFTime::isValid ( ) const
virtual

check whether the currently stored time value is valid.

Valid ranges: [0,24[ for 'hour', [0,60[ for 'minute', [0.0,60.0] for 'second' (including leap second) and [-12.0,+14.0] for 'timeZone'

Returns
OFTrue if the current value is valid, OFFalse otherwise

◆ operator!=()

virtual OFBool OFTime::operator!= ( const OFTime timeVal) const
virtual

comparison operator (unequal) Please note that the time values are first transformed to the Coordinated Universal Time (UTC) before they are compared.

Parameters
timeValtime value compared with the current value
Returns
OFTrue if given time is unequal, OFFalse otherwise

◆ operator<()

virtual OFBool OFTime::operator< ( const OFTime timeVal) const
virtual

comparison operator (less than) Please note that the time values are first transformed to the Coordinated Universal Time (UTC) before they are compared.

Parameters
timeValtime value compared with the current value
Returns
OFTrue if current time is earlier than the given value, OFFalse otherwise

◆ operator<=()

virtual OFBool OFTime::operator<= ( const OFTime timeVal) const
virtual

comparison operator (less than or equal) Please note that the time values are first transformed to the Coordinated Universal Time (UTC) before they are compared.

Parameters
timeValtime value compared with the current value
Returns
OFTrue if current time is earlier than or identical to the given value, OFFalse otherwise

◆ operator=()

virtual OFTime & OFTime::operator= ( const OFTime timeVal)
virtual

assignment operator

Parameters
timeValtime value to be set
Returns
reference to this object (with new value)

◆ operator==()

virtual OFBool OFTime::operator== ( const OFTime timeVal) const
virtual

comparison operator (equal).

Please note that the time values are first transformed to the Coordinated Universal Time (UTC) before they are compared.

Parameters
timeValtime value compared with the current value
Returns
OFTrue if given time is equal, OFFalse otherwise

◆ operator>()

virtual OFBool OFTime::operator> ( const OFTime timeVal) const
virtual

comparison operator (greater than) Please note that the time values are first transformed to the Coordinated Universal Time (UTC) before they are compared.

Parameters
timeValtime value compared with the current value
Returns
OFTrue if current time is later than the given value, OFFalse otherwise

◆ operator>=()

virtual OFBool OFTime::operator>= ( const OFTime timeVal) const
virtual

comparison operator (greater than or equal) Please note that the time values are first transformed to the Coordinated Universal Time (UTC) before they are compared.

Parameters
timeValtime value compared with the current value
Returns
OFTrue if current time is later than or identical to the given value, OFFalse otherwise

◆ setCurrentTime() [1/2]

OFBool OFTime::setCurrentTime ( )

set the time value to the current system time.

This function uses operating system dependent routines. If they are unavailable for some reason the current value is not modified.

Returns
OFTrue if the current system time has been set, OFFalse otherwise

◆ setCurrentTime() [2/2]

OFBool OFTime::setCurrentTime ( const time_t &  tt)
protected

set the time value to the current system time.

This function uses operating system dependent routines. If they are unavailable for some reason the current value is not modified.

Parameters
ttcurrent system time (as returned by the time() function )
Returns
OFTrue if the current system time has been set, OFFalse otherwise

◆ setHour()

OFBool OFTime::setHour ( const unsigned int  hour)

set the time value to the specified hour.

Before the new value is set it is checked using the "isValid()" routine.

Parameters
hournew hour value to be set
Returns
OFTrue if the new value is valid and has been set, OFFalse otherwise

◆ setISOFormattedTime()

OFBool OFTime::setISOFormattedTime ( const OFString formattedTime)

set the time value to the given ISO formatted time string.

The two ISO time formats supported by this function are

  • "HH:MM[:SS [&ZZ:ZZ]]" (with arbitrary delimiters) and
  • "HHMM[SS[&ZZZZ]]" (without delimiters) where the brackets enclose optional parts. Please note that the optional fractional part of a second ".FFFFFF" (see getISOFormattedTime()) is not yet supported.
    Parameters
    formattedTimeISO formatted time value to be set
    Returns
    OFTrue if input is valid and result variable has been set, OFFalse otherwise

◆ setMinute()

OFBool OFTime::setMinute ( const unsigned int  minute)

set the time value to the specified minute.

Before the new value is set it is checked using the "isValid()" routine.

Parameters
minutenew minute value to be set
Returns
OFTrue if the new value is valid and has been set, OFFalse otherwise

◆ setSecond()

OFBool OFTime::setSecond ( const double  second)

set the time value to the specified second.

Before the new value is set it is checked using the "isValid()" routine.

Parameters
secondnew second value to be set (incl. fraction of seconds)
Returns
OFTrue if the new value is valid and has been set, OFFalse otherwise

◆ setTime()

OFBool OFTime::setTime ( const unsigned int  hour,
const unsigned int  minute,
const double  second,
const double  timeZone = 0 
)

set the time value to the specified time.

Before the new value is set it is checked using the "isValid()" routine.

Parameters
hournew hour value to be set
minutenew minute value to be set
secondnew second value to be set (incl. fraction of seconds)
timeZoneoptional offset to Coordinated Universal Time (UTC) in hours
Returns
OFTrue if the new value is valid and has been set, OFFalse otherwise

◆ setTimeInHours()

OFBool OFTime::setTimeInHours ( const double  hours,
const double  timeZone = 0,
const OFBool  normalize = OFTrue 
)

set the time to the specified number of hours

Parameters
hoursnumber of hours since "00:00:00" specifying time to set
timeZoneoptional offset to Coordinated Universal Time (UTC) in hours
normalizeif OFTrue the 'hours' value is normalized to the valid range [0.0,24.0[ otherwise the value is checked as is
Returns
OFTrue if the new value is valid and has been set, OFFalse otherwise

◆ setTimeInSeconds()

OFBool OFTime::setTimeInSeconds ( const double  seconds,
const double  timeZone = 0,
const OFBool  normalize = OFTrue 
)

set the time to the specified number of seconds

Parameters
secondsnumber of seconds since "00:00:00" specifying time to set
timeZoneoptional offset to Coordinated Universal Time (UTC) in hours
normalizeif OFTrue the 'seconds' value is normalized to the valid range [0.0,86400.0[ otherwise the value is checked as is
Returns
OFTrue if the new value is valid and has been set, OFFalse otherwise

◆ setTimeZone() [1/2]

OFBool OFTime::setTimeZone ( const double  timeZone)

set the time zone to the specified value.

The time zone is given as the offset (in hours) to the Coordinated Universal Time (UTC). Valid values are for instance "+1.0" (plus one hour) and "-2.5" (minus two and a half hour, i.e. 2 hours and 30 minutes). Before the new value is set it is checked using the "isValid()" routine.

Parameters
timeZonenew timeZone value to be set
Returns
OFTrue if the new value is valid and has been set, OFFalse otherwise

◆ setTimeZone() [2/2]

OFBool OFTime::setTimeZone ( const signed int  hour,
const unsigned int  minute 
)

set the time zone to the specified value.

The time zone is given as the offset (in hours and minutes) to the Coordinated Universal Time (UTC). Before the new value is set it is checked using the "isValid()" routine.

Parameters
hournew hour value to be set for the time zone
minutenew minute value to be set for the time zone
Returns
OFTrue if the new value is valid and has been set, OFFalse otherwise

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


Generated on Tue Dec 19 2023 for DCMTK Version 3.6.8 by Doxygen 1.9.4