DateTimeParser Class Reference

#include <lib_datetimeparser.h>

Detailed Description

Class to parse and create date time strings.

Note
Has to be created with Alloc() and destroyed with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.

Example:

dtp->SetFormatString("YYYY-MM-DD", DATETIMEPARSERMODE::DATE);
dtp->SetFormatString("HH:MM:SS", DATETIMEPARSERMODE::TIME);
String sDateFormat = dtp->GetFormatString(DATETIMEPARSERMODE::DATE);
String sTimeFormat = dtp->GetFormatString(DATETIMEPARSERMODE::TIME);
GePrint(sDateFormat + " " + sTimeFormat);
dtp->ParseString("110325", dt, DATETIMEPARSERMODE::DATE);
dtp->ParseString("54321", dt, DATETIMEPARSERMODE::TIME);
String sDate = dtp->MakeString(dt, DATETIMEPARSERMODE::DATE);
String sTime = dtp->MakeString(dt, DATETIMEPARSERMODE::TIME);
GePrint(sDate + " " + sTime);
void GePrint(const maxon::String &str)
Definition: ge_autoptr.h:37
Definition: c4d_string.h:39
Represents a date and time.
Definition: customgui_datetime.h:39

Private Member Functions

 DateTimeParser ()
 
 ~DateTimeParser ()
 

Alloc/Free

static DateTimeParserAlloc ()
 
static void Free (DateTimeParser *&dtp)
 

Parse/Make String

Bool ParseString (const String &str, DateTime &result, DATETIMEPARSERMODE mode)
 
String MakeString (const DateTime &dt, DATETIMEPARSERMODE mode)
 

Format String

void SetFormatString (const String &sFormat, DATETIMEPARSERMODE mode)
 
String GetFormatString (DATETIMEPARSERMODE mode)
 

Constructor & Destructor Documentation

◆ DateTimeParser()

DateTimeParser ( )
private

◆ ~DateTimeParser()

~DateTimeParser ( )
private

Member Function Documentation

◆ Alloc()

static DateTimeParser* Alloc ( )
static

Allocates a date time parser. Destroy the allocated date time parser with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.

Returns
The allocated date time parser, or nullptr if the allocation failed.

◆ Free()

static void Free ( DateTimeParser *&  dtp)
static

Destructs date time parsers allocated with Alloc(). Use AutoAlloc to automate the allocation and destruction based on scope.

Parameters
[in,out]dtpThe date time parser to destruct. If the pointer is nullptr nothing happens. The pointer is assigned nullptr afterwards.

◆ ParseString()

Bool ParseString ( const String str,
DateTime result,
DATETIMEPARSERMODE  mode 
)

Parses a date time string.

Parameters
[in]strThe string to parse.
[in]resultAssigned the parsed result.
[in]modeThe date time mode: DATETIMEPARSERMODE
Returns
true if successful, otherwise false.

◆ MakeString()

String MakeString ( const DateTime dt,
DATETIMEPARSERMODE  mode 
)

Creates a date time string, e.g. "12:24:05" or "2011-08-23".

Parameters
[in]dtThe date time to create the string from.
[in]modeThe date time mode: DATETIMEPARSERMODE
Returns
The date time string.

◆ SetFormatString()

void SetFormatString ( const String sFormat,
DATETIMEPARSERMODE  mode 
)

Sets the formating of the time string.

Parameters
[in]sFormatThe formating string, e.g. "HH:MM:SS" for time and "YYYY-MM-DD" for the date.
[in]modeThe date time mode: DATETIMEPARSERMODE

◆ GetFormatString()

String GetFormatString ( DATETIMEPARSERMODE  mode)

Retrieves the current date time formating string.

Parameters
[in]modeThe date time mode: DATETIMEPARSERMODE
Returns
The formating string, e.g. "HH:MM:SS" for time and "YYYY-MM-DD" for the date.