OpenMS
Loading...
Searching...
No Matches
DateTime Class Reference

DateTime Class. More...

#include <OpenMS/DATASTRUCTURES/DateTime.h>

Collaboration diagram for DateTime:
[legend]

Classes

struct  Fields
 

Public Member Functions

 DateTime ()
 Default constructor.
 
 DateTime (const DateTime &date)=default
 Copy constructor.
 
 DateTime (DateTime &&) noexcept=default
 Move constructor.
 
DateTimeoperator= (const DateTime &source)=default
 Assignment operator.
 
DateTimeoperator= (DateTime &&) &noexcept=default
 Move assignment operator.
 
 ~DateTime ()=default
 Destructor.
 
bool operator== (const DateTime &rhs) const
 equal operator
 
bool operator!= (const DateTime &rhs) const
 not-equal operator
 
bool operator< (const DateTime &rhs) const
 less operator
 
void setDate (const String &date)
 sets date from a string
 
void setTime (const String &date)
 sets time from a string
 
void setDate (UInt month, UInt day, UInt year)
 sets data from three integers
 
void setTime (UInt hour, UInt minute, UInt second)
 sets time from three integers
 
void set (UInt month, UInt day, UInt year, UInt hour, UInt minute, UInt second)
 sets data from six integers
 
void get (UInt &month, UInt &day, UInt &year, UInt &hour, UInt &minute, UInt &second) const
 Fills the arguments with the date and the time.
 
void getDate (UInt &month, UInt &day, UInt &year) const
 Fills the arguments with the date.
 
String getDate () const
 Returns the date as string.
 
void getTime (UInt &hour, UInt &minute, UInt &second) const
 Fills the arguments with the time.
 
DateTimeaddSecs (int s)
 
String getTime () const
 Returns the time as string.
 
bool isValid () const
 Returns true if the date time is valid.
 
bool isNull () const
 return true if the date and time is null
 
void clear ()
 Sets the undefined date: 00/00/0000 00:00:00.
 
String toString (const std::string &format="yyyy-MM-ddThh:mm:ss") const
 
String get () const
 Returns a string representation of the date and time.
 
void set (const String &date)
 Sets date and time.
 

Static Public Member Functions

static DateTime now ()
 Returns the current date and time.
 
static DateTime nowUTC ()
 Returns the current date and time in UTC.
 
static DateTime fromString (const std::string &date, const std::string &format="yyyy-MM-ddThh:mm:ss")
 

Private Attributes

struct OpenMS::DateTime::Fields fields_
 

Detailed Description

DateTime Class.

This class implements date handling. Import and export to/from both string and integers is possible.


Class Documentation

◆ OpenMS::DateTime::Fields

struct OpenMS::DateTime::Fields
Collaboration diagram for DateTime::Fields:
[legend]
Class Members
int day = 0
int hour = 0
int millisecond = 0
int minute = 0
int month = 0
int second = 0
bool valid = false
int year = 0

Constructor & Destructor Documentation

◆ DateTime() [1/3]

DateTime ( )

Default constructor.

Fills the object with an undefined date: 00/00/0000

◆ DateTime() [2/3]

DateTime ( const DateTime date)
default

Copy constructor.

◆ DateTime() [3/3]

DateTime ( DateTime &&  )
defaultnoexcept

Move constructor.

◆ ~DateTime()

~DateTime ( )
default

Destructor.

Member Function Documentation

◆ addSecs()

DateTime & addSecs ( int  s)

◆ clear()

void clear ( )

Sets the undefined date: 00/00/0000 00:00:00.

◆ fromString()

static DateTime fromString ( const std::string &  date,
const std::string &  format = "yyyy-MM-ddThh:mm:ss" 
)
static

◆ get() [1/2]

String get ( ) const

Returns a string representation of the date and time.

The format of the string will be yyyy-MM-dd hh:mm:ss

◆ get() [2/2]

void get ( UInt month,
UInt day,
UInt year,
UInt hour,
UInt minute,
UInt second 
) const

Fills the arguments with the date and the time.

Give the numbers in the following order: month, day and year, hour minute, second.

◆ getDate() [1/2]

String getDate ( ) const

Returns the date as string.

The format of the string is yyyy-MM-dd

◆ getDate() [2/2]

void getDate ( UInt month,
UInt day,
UInt year 
) const

Fills the arguments with the date.

Give the numbers in the following order: month, day and year.

◆ getTime() [1/2]

String getTime ( ) const

Returns the time as string.

The format of the string is hh:mm:ss

◆ getTime() [2/2]

void getTime ( UInt hour,
UInt minute,
UInt second 
) const

Fills the arguments with the time.

The arguments are all UInts and the order is hour minute second

◆ isNull()

bool isNull ( ) const

return true if the date and time is null

◆ isValid()

bool isValid ( ) const

Returns true if the date time is valid.

◆ now()

static DateTime now ( )
static

Returns the current date and time.

◆ nowUTC()

static DateTime nowUTC ( )
static

Returns the current date and time in UTC.

◆ operator!=()

bool operator!= ( const DateTime rhs) const

not-equal operator

◆ operator<()

bool operator< ( const DateTime rhs) const

less operator

◆ operator=() [1/2]

DateTime & operator= ( const DateTime source)
default

Assignment operator.

◆ operator=() [2/2]

DateTime & operator= ( DateTime &&  ) &
defaultnoexcept

Move assignment operator.

◆ operator==()

bool operator== ( const DateTime rhs) const

equal operator

◆ set() [1/2]

void set ( const String date)

Sets date and time.

The following formats are supported:

  • MM/dd/yyyy hh:mm:ss
  • dd.MM.yyyy hh:mm:ss
  • yyyy-MM-dd hh:mm:ss
  • yyyy-MM-ddThh:mm:ss (ISO 8601 format)
  • yyyy-MM-ddZ (ISO 8601 format)
  • yyyy-MM-dd+hh:mm (ISO 8601 format)
Exceptions
Exception::ParseError

◆ set() [2/2]

void set ( UInt  month,
UInt  day,
UInt  year,
UInt  hour,
UInt  minute,
UInt  second 
)

sets data from six integers

Give the numbers in the following order: month, day, year, hour, minute, second.

Exceptions
Exception::ParseError

Referenced by XMLHandler::asDateTime_(), and XMassFile::importExperimentalSettings().

◆ setDate() [1/2]

void setDate ( const String date)

sets date from a string

Reads both English, German and iso/ansi date formats: 'MM/dd/yyyy', 'dd.MM.yyyy' or 'yyyy-MM-dd'

Exceptions
Exception::ParseError

◆ setDate() [2/2]

void setDate ( UInt  month,
UInt  day,
UInt  year 
)

sets data from three integers

Give the numbers in the following order: month, day and year.

Exceptions
Exception::ParseError

◆ setTime() [1/2]

void setTime ( const String date)

sets time from a string

Reads time format: 'hh:mm:ss'

Exceptions
Exception::ParseError

◆ setTime() [2/2]

void setTime ( UInt  hour,
UInt  minute,
UInt  second 
)

sets time from three integers

Give the numbers in the following order: hour, minute and second.

Exceptions
Exception::ParseError

◆ toString()

String toString ( const std::string &  format = "yyyy-MM-ddThh:mm:ss") const

Member Data Documentation

◆ fields_

struct OpenMS::DateTime::Fields fields_
private