DCMTK: OFTime Class Reference

DCMTK Version 3.6.9 OFFIS DICOM Toolkit

Loading...
Searching...
No Matches
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.
| OFTime (const OFTime &timeVal)
| copy constructor
| OFTime (const unsigned int hour, const unsigned int minute, const double second, const double timeZone=0)
| constructor with init values
virtual | ~OFTime ()
| destructor
virtual OFTime & | operator= (const OFTime &timeVal)
| assignment operator
virtual OFBool | operator== (const OFTime &timeVal) const
| comparison operator (equal).
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.
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.
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.
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.
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.
virtual void | clear ()
| reset the time value.
virtual OFBool | isValid () const
| check whether the currently stored time value is valid.
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.
OFBool | setHour (const unsigned int hour)
| set the time value to the specified hour.
OFBool | setMinute (const unsigned int minute)
| set the time value to the specified minute.
OFBool | setSecond (const double second)
| set the time value to the specified second.
OFBool | setTimeZone (const double timeZone)
| set the time zone to the specified value.
OFBool | setTimeZone (const signed int hour, const unsigned int minute)
| set the time zone to the specified value.
OFBool | setTimeInSeconds (const double seconds, const double timeZone=0, const OFBool normalize=OFTrue)
| set the time to the specified number of seconds
OFBool | setTimeInHours (const double hours, const double timeZone=0, const OFBool normalize=OFTrue)
| set the time to the specified number of hours
OFBool | setCurrentTime ()
| set the time value to the current system time.
OFBool | setISOFormattedTime (const OFString &formattedTime)
| set the time value to the given ISO formatted time string.
unsigned int | getHour () const
| get the currently stored hour value
unsigned int | getMinute () const
| get the currently stored minute value
double | getSecond () const
| get the currently stored second value
unsigned int | getIntSecond () const
| get the integral part of the currently stored second value
unsigned int | getMilliSecond () const
| get the milli second part of the currently stored second value
unsigned int | getMicroSecond () const
| get the micro second part of the currently stored second value
double | getTimeZone () const
| get the currently stored time zone value.
double | getTimeInSeconds (const OFBool useTimeZone=OFFalse, const OFBool normalize=OFTrue) const
| get the currently stored time in seconds
double | getTimeInHours (const OFBool useTimeZone=OFFalse, const OFBool normalize=OFTrue) const
| get the currently stored time in hours.
OFTime | getCoordinatedUniversalTime () const
| get the currently stored time as Coordinated Universal Time.
OFTime | getLocalTime () const
| get the currently stored time in local time.
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.

## Static Public Member Functions
static OFTime | getCurrentTime ()
| get the current system time
static double | getLocalTimeZone ()
| get the local time zone.

## Protected Member Functions
OFBool | setCurrentTime (const time_t &tt)
| set the time value to the current system time.

## 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.
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.
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.

## 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.

Referenced by OFTime(), getCoordinatedUniversalTime(), getCurrentTime(), getLocalTime(), operator!=(), operator<(), operator<=(), operator=(), operator==(), operator>(), and operator>=().

## ◆ OFTime() [2/3]

OFTime::OFTime | ( | const OFTime & | timeVal | ) |

copy constructor

Parameters

  timeVal | time object to be copied

References OFTime().

## ◆ 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

  hour | hour value to be set
  minute | minute value to be set
  second | second value to be set (incl. fraction of seconds)
  timeZone | optional 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

References OFTime().

## ◆ getCurrentTime()

static OFTime OFTime::getCurrentTime | ( |  | ) |
| static

get the current system time

Returns
  time object with the current system time set

References OFTime().

## ◆ 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

    formattedTime | reference to string variable where the result is stored
    showSeconds | add optional seconds (":SS" or "SS") to the resulting string if OFTrue
    showFraction | add optional fractional part of a second (".FFFFFF") if OFTrue. Requires parameter 'seconds' to be also OFTrue.
    showTimeZone | add 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 "-").
    showDelimiter | flag, indicating whether to use delimiters (":") or not
    timeZoneSeparator | separator 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

References OFTime().

## ◆ 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

  useTimeZone | use the currently set time zone to correct the result
  normalize | if 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

  hour | hour value of the given time
  minute | minute value of the given time
  second | second value of the given time
  timeZone | offset to Coordinated Universal Time (UTC) in hours
  normalize | if 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

  useTimeZone | use the currently set time zone to correct the result
  normalize | if 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

  hour | hour value of the given time
  minute | minute value of the given time
  second | second value of the given time
  timeZone | offset to Coordinated Universal Time (UTC) in hours
  normalize | if 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

  hour | hour value to be checked
  minute | minute value to be checked
  second | second value to be checked
  timeZone | offset 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

  timeVal | time value compared with the current value

Returns
  OFTrue if given time is unequal, OFFalse otherwise

References OFTime().

## ◆ 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

  timeVal | time value compared with the current value

Returns
  OFTrue if current time is earlier than the given value, OFFalse otherwise

References OFTime().

## ◆ 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

  timeVal | time value compared with the current value

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

References OFTime().

## ◆ operator=()

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

assignment operator

Parameters

  timeVal | time value to be set

Returns
  reference to this object (with new value)

References OFTime().

## ◆ 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

  timeVal | time value compared with the current value

Returns
  OFTrue if given time is equal, OFFalse otherwise

References OFTime().

## ◆ 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

  timeVal | time value compared with the current value

Returns
  OFTrue if current time is later than the given value, OFFalse otherwise

References OFTime().

## ◆ 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

  timeVal | time value compared with the current value

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

References OFTime().

## ◆ 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

  tt | current 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

  hour | new 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

    formattedTime | ISO 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

  minute | new 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

  second | new 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

  hour | new hour value to be set
  minute | new minute value to be set
  second | new second value to be set (incl. fraction of seconds)
  timeZone | optional 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

  hours | number of hours since "00:00:00" specifying time to set
  timeZone | optional offset to Coordinated Universal Time (UTC) in hours
  normalize | if 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

  seconds | number of seconds since "00:00:00" specifying time to set
  timeZone | optional offset to Coordinated Universal Time (UTC) in hours
  normalize | if 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

  timeZone | new 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

  hour | new hour value to be set for the time zone
  minute | new 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:

- ofstd/include/dcmtk/ofstd/oftime.h

Generated on Wed Apr 30 2025 for DCMTK Version 3.6.9 by Doxygen 1.13.2