DCMTK Version 3.7.1
OFFIS DICOM Toolkit
Loading...
Searching...
No Matches
OFDateTime Class Reference

This class is a combination of OFDate and OFTime. More...

Public Member Functions

 OFDateTime ()
 default constructor.
 OFDateTime (const OFDateTime &dateTime)
 copy constructor
 OFDateTime (const OFDate &dateVal, const OFTime &timeVal)
 copy constructor
 OFDateTime (const unsigned int year, const unsigned int month, const unsigned int day, const unsigned int hour, const unsigned int minute, const double second, const double timeZone=OFTime::unspecifiedTimeZone)
 constructor
virtual ~OFDateTime ()
 destructor
virtual OFDateTime & operator= (const OFDateTime &dateTime)
 assignment operator
virtual OFBool operator== (const OFDateTime &dateTime) const
 comparison operator (equal).
virtual OFBool operator!= (const OFDateTime &dateTime) const
 comparison operator (unequal).
virtual OFBool operator< (const OFDateTime &dateTime) const
 comparison operator (less than).
virtual OFBool operator<= (const OFDateTime &dateTime) const
 comparison operator (less than or equal).
virtual OFBool operator>= (const OFDateTime &dateTime) const
 comparison operator (greater than or equal).
virtual OFBool operator> (const OFDateTime &dateTime) const
 comparison operator (greater than).
virtual void clear ()
 reset the date/time value.
virtual OFBool isValid () const
 check whether the currently stored date and time value is valid.
OFBool setDateTime (const unsigned int year, const unsigned int month, const unsigned int day, const unsigned int hour, const unsigned int minute, const double second, const double timeZone=OFTime::unspecifiedTimeZone)
 set the date/time value.
OFBool setDate (const OFDate &dateVal)
 set the date component to the specified date.
OFBool setTime (const OFTime &timeVal)
 set the time component to the specified time.
OFBool setDateTime (const OFDate &dateVal, const OFTime &timeVal)
 set the date and time component to the specified date/time.
OFBool setCurrentDateTime ()
 set the date and time value to the current system date and time.
OFBool setISOFormattedDateTime (const OFString &formattedDateTime)
 set the date/time value to the given ISO formatted date/time string.
const OFDate & getDate () const
 get the current date component
const OFTime & getTime () const
 get the current time component
OFBool getISOFormattedDateTime (OFString &formattedDateTime, const OFBool showSeconds=OFTrue, const OFBool showFraction=OFFalse, const OFBool showTimeZone=OFFalse, const OFBool showDelimiter=OFTrue, const OFBool createMissingPart=OFFalse, const OFString &dateTimeSeparator=" ", const OFString &timeZoneSeparator=" ") const
 get the current date/time value in ISO format.

Static Public Member Functions

static OFDateTime getCurrentDateTime ()
 get the current system date and time

Private Attributes

OFDate Date
 currently stored date value
OFTime Time
 currently stored time value

Friends

class DcmDateTime
 let DcmDateTime access the members directly
class DcmAttributeMatching
 let DcmAttributeMatching access the members directly

Detailed Description

This class is a combination of OFDate and OFTime.

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

◆ OFDateTime() [1/4]

OFDateTime::OFDateTime ( )

default constructor.

Initializes Date and Time to 0.

Referenced by OFDateTime(), getCurrentDateTime(), operator!=(), operator<(), operator<=(), operator=(), operator==(), operator>(), and operator>=().

◆ OFDateTime() [2/4]

OFDateTime::OFDateTime ( const OFDateTime & dateTime)

copy constructor

Parameters
dateTimedate/time object to be copied

References OFDateTime().

◆ OFDateTime() [3/4]

OFDateTime::OFDateTime ( const OFDate & dateVal,
const OFTime & timeVal )

copy constructor

Parameters
dateValdate object to be copied
timeValtime object to be copied

◆ OFDateTime() [4/4]

OFDateTime::OFDateTime ( const unsigned int year,
const unsigned int month,
const unsigned int day,
const unsigned int hour,
const unsigned int minute,
const double second,
const double timeZone = OFTime::unspecifiedTimeZone )

constructor

Parameters
yearyear value to be set
monthmonth value to be set
daynew value to be set
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

References OFTime::unspecifiedTimeZone.

Member Function Documentation

◆ clear()

virtual void OFDateTime::clear ( )
virtual

reset the date/time value.

Sets all date and all time components to "0" (or "unspecified" in case of the time zone). Please note that the date becomes invalid.

◆ getCurrentDateTime()

OFDateTime OFDateTime::getCurrentDateTime ( )
static

get the current system date and time

Returns
date/time object with the current system date and time set

References OFDateTime().

◆ getDate()

const OFDate & OFDateTime::getDate ( ) const

get the current date component

Returns
reference to date object

◆ getISOFormattedDateTime()

OFBool OFDateTime::getISOFormattedDateTime ( OFString & formattedDateTime,
const OFBool showSeconds = OFTrue,
const OFBool showFraction = OFFalse,
const OFBool showTimeZone = OFFalse,
const OFBool showDelimiter = OFTrue,
const OFBool createMissingPart = OFFalse,
const OFString & dateTimeSeparator = " ",
const OFString & timeZoneSeparator = " " ) const

get the current date/time value in ISO format.

The ISO time formats supported by this function are

  • "YYYY-MM-DD HH:MM[:SS[.FFFFFF]] [&ZZ:ZZ]" (with delimiters),
  • "YYYY-MM-DD'T'HH:MM[:SS[.FFFFFF]][&ZZ:ZZ]" (according to ISO 8601) and
  • "YYYYMMDDHHMM[SS[.FFFFFF]][&ZZZZ]" (without delimiters, useful for DICOM datetime type)

where the brackets enclose optional parts, the 'T' stands for the literal symbol "T", and the "&" is a placeholder for the sign symbol ("+" or "-").

Parameters
formattedDateTimereference to string variable where the result is stored
showSecondsadd optional seconds (":SS" or "SS") to the resulting string if OFTrue. By default, the seconds are only added if a value is specified.
showFractionadd optional fractional part of a second (".FFFFFF") if OFTrue. Requires parameter 'seconds' to be also OFTrue. By default, the fractional part is only added if the second value is not an integer (see OFTime::hasFractionOfSecond()).
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 time zone is only added if a value is specified.
showDelimiterflag, indicating whether to use delimiters ("-", ":" and " ") or not
createMissingPartif OFTrue, create optional parts (seconds and fractional part of a second) even if not specified (see OFTime::hasSecond() and OFTime::hasFractionOfSecond())
dateTimeSeparatorseparator between ISO date and time value, e.g. " " (default) or "T" (for ISO 8601 format). Only used if 'showDelimiter' is true.
timeZoneSeparatorseparator between ISO time value and time zone, e.g. " " (default) or "" (for ISO 8601 format). Only used if 'showDelimiter' is true.
Returns
OFTrue if result variable has been set, OFFalse otherwise

◆ getTime()

const OFTime & OFDateTime::getTime ( ) const

get the current time component

Returns
reference to time object

◆ isValid()

virtual OFBool OFDateTime::isValid ( ) const
virtual

check whether the currently stored date and time value is valid.

See classes OFDate and OFTime for details.

Returns
OFTrue if the current value is valid, OFFalse otherwise

◆ operator!=()

virtual OFBool OFDateTime::operator!= ( const OFDateTime & dateTime) const
virtual

comparison operator (unequal).

Please note that the time values are first transformed to the Coordinated Universal Time (UTC) before they are compared. However, the special case that there is an "overflow" from one day to another is currently not handled.

Parameters
dateTimedate and time value compared with the current value
Returns
OFTrue if given date or time is unequal, OFFalse otherwise

References OFDateTime().

◆ operator<()

virtual OFBool OFDateTime::operator< ( const OFDateTime & dateTime) 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. However, the special case that there is an "overflow" from one day to another is currently not handled.

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

References OFDateTime().

◆ operator<=()

virtual OFBool OFDateTime::operator<= ( const OFDateTime & dateTime) 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. However, the special case that there is an "overflow" from one day to another is currently not handled.

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

References OFDateTime().

◆ operator=()

virtual OFDateTime & OFDateTime::operator= ( const OFDateTime & dateTime)
virtual

assignment operator

Parameters
dateTimedate/time value to be set
Returns
reference to this object (with new value)

References OFDateTime().

◆ operator==()

virtual OFBool OFDateTime::operator== ( const OFDateTime & dateTime) const
virtual

comparison operator (equal).

Please note that the time values are first transformed to the Coordinated Universal Time (UTC) before they are compared. However, the special case that there is an "overflow" from one day to another is currently not handled.

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

References OFDateTime().

◆ operator>()

virtual OFBool OFDateTime::operator> ( const OFDateTime & dateTime) 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. However, the special case that there is an "overflow" from one day to another is currently not handled.

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

References OFDateTime().

◆ operator>=()

virtual OFBool OFDateTime::operator>= ( const OFDateTime & dateTime) 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. However, the special case that there is an "overflow" from one day to another is currently not handled.

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

References OFDateTime().

◆ setCurrentDateTime()

OFBool OFDateTime::setCurrentDateTime ( )

set the date and time value to the current system date and time.

This function uses operating system dependent routines. If the date or time function (or both) are unavailable for some reason, the corresponding value is not modified.

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

◆ setDate()

OFBool OFDateTime::setDate ( const OFDate & dateVal)

set the date component to the specified date.

Before the new value is set, it is checked using the isValid() method.

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

◆ setDateTime() [1/2]

OFBool OFDateTime::setDateTime ( const OFDate & dateVal,
const OFTime & timeVal )

set the date and time component to the specified date/time.

Before the new value is set, it is checked using the isValid() method.

Parameters
dateValnew date value to be set
timeValnew time value to be set
Returns
OFTrue if the new value is valid and has been set, OFFalse otherwise

◆ setDateTime() [2/2]

OFBool OFDateTime::setDateTime ( const unsigned int year,
const unsigned int month,
const unsigned int day,
const unsigned int hour,
const unsigned int minute,
const double second,
const double timeZone = OFTime::unspecifiedTimeZone )

set the date/time value.

Before the new value is set, it is checked using the isValid() method.

Parameters
yearnew year value to be set
monthnew month value to be set
daynew day value to be set
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

References OFTime::unspecifiedTimeZone.

◆ setISOFormattedDateTime()

OFBool OFDateTime::setISOFormattedDateTime ( const OFString & formattedDateTime)

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

The most common ISO date/time formats supported by this function are

  • "YYYY-MM-DD HH:MM[:SS[.FFFFFF]] [&ZZ:ZZ]" (with arbitrary delimiters),
  • "YYYY-MM-DD'T'HH:MM[:SS[.FFFFFF]][&ZZ:ZZ]" (according to ISO 8601) and
  • "YYYYMMDDHHMM[SS[.FFFFFF]][&ZZZZ]" (without delimiters, useful for DICOM datetime type)

where the brackets enclose optional parts, the 'T' stands for the literal symbol "T", and the "&" is a placeholder for the sign symbol ("+" or "-"). The pattern "FFFFFF" contains a fractional part of a second. If specified, it shall contain one to six digits representing a range from 0 to 999999. In the first two formats listed, spaces between date, time and time zone components are accepted. Leading or trailing spaces are never accepted.

Parameters
formattedDateTimeISO formatted date/time value to be set
Returns
OFTrue if input is valid and result variable has been set, OFFalse otherwise

◆ setTime()

OFBool OFDateTime::setTime ( const OFTime & timeVal)

set the time component to the specified time.

Before the new value is set, it is checked using the isValid() method.

Parameters
timeValnew time value to be set
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 for DCMTK Version 3.7.1 by Doxygen 1.18.0