libcommonc++  0.7
DateTimeFormat Class Reference

A formatter for dates and times. More...

#include <DateTimeFormat.h++>

Public Member Functions

 DateTimeFormat (String format="%t %T", String dateFormat="%t", String timeFormat="%T")
 Construct a new DateTimeFormat. More...
 
 ~DateTimeFormat ()
 Destructor. More...
 
void setFormat (const String &format)
 Set the format for dates with times. More...
 
void setDateFormat (const String &dateFormat)
 Set the format for dates. More...
 
void setTimeFormat (const String &timeFormat)
 Set the format for times. More...
 
String format (const Date &value) const
 Format a Date. More...
 
size_t format (const Date &value, char *buf, size_t bufsz) const
 Format a DateTime. More...
 
String format (const Time &value) const
 Format a Time. More...
 
size_t format (const Time &value, char *buf, size_t bufsz) const
 Format a DateTime. More...
 
String format (const DateTime &value) const
 Format a DateTime. More...
 
size_t format (const DateTime &value, char *buf, size_t bufsz) const
 Format a DateTime. More...
 
void parse (Date &value, const String &text) const
 Parse a Date from a string. More...
 
void parse (Time &value, const String &text) const
 Parse a Time from a string. More...
 
void parse (DateTime &value, const String &text) const
 Parse a DateTime from a string. More...
 

Detailed Description

A formatter for dates and times.

Available format directives are enumerated below. Unrecognized directives are ignored, and all other text is treated literally.

DirectiveMeaningRange
%HHour of 24-hour clock0 - 23
%%0HHour of 24-hour clock (padded with leading zeroes)00 - 23
%_HHour of 24-hour clock (padded with leading spaces) 0 - 23
%hHour of 12-hour clock1 - 12
%%0hHour of 12-hour clock (padded with leading zeroes)01 - 12
%_hHour of 12-hour clock (padded with leading spaces) 1 - 12
%MMinutes (unpadded)0 - 59
%%0MMinutes (padded with leading zeroes)00 - 59
%_MMinutes (padded with leading spaces) 0 - 59
%SSeconds (unpadded)0 - 60
%%0SSeconds (padded with leading zeroes)00 - 60
%_SSeconds (padded with leading spaces) 0 - 60
%sMilliseconds (unpadded)0 - 999
%%0sMilliseconds (padded with leading zeroes)000 - 999
%_sMilliseconds (padded with leading spaces)

  0 - 999

%dDay of month1 - 31
%%0dDay of month (padded with leading zeroes)01 - 31
%_dDay of month (padded with leading spaces)

 1 - 31

%DDay of year1 - 366
%%0DDay of year (padded with leading zeroes)001 - 366
%_DDay of year (padded with leading spaces)

  1 - 366

%mMonth number (1 = January)1 - 12
%%0mMonth number (1 = January) (padded with leading zeroes)01 - 12
%_mMonth number (1 = January) (padded with leading spaces) 1 - 12
$mAbbreviated month name
%$$mFull month name
%wWeekday number (0 = Sunday)0 - 6
$wAbbreviated weekday name
%$$w

Full weekday name

%WWeek number (ISO standard)0 - 52
%%0WWeek number (ISO standard) (padded with leading zeroes)00 - 52
%_wWeek number (ISO standard) (padded with leading spaces)

 0 - 52

%y2-digit year 0 - 99
%%0y2-digit year (padded with leading zeroes)00 - 99
%_y2-digit year (padded with leading spaces) 0 - 99
%Y4-digit year 0 - 9999
%%0Y4-digit year (padded with leading zeroes)0000 - 9999
%_Y4-digit year (padded with leading spaces)

   0 - 9999

%PMeridiem (uppercase) (local form of "AM" or "PM")
%pMeridiem (lowercase) (local form of "am" or "pm")
%tDate
%TTime
%ZTime zone name
%%Percent sign
Author
Mark Lindner

Constructor & Destructor Documentation

◆ DateTimeFormat()

DateTimeFormat ( String  format = "%t %T",
String  dateFormat = "%t",
String  timeFormat = "%T" 
)

Construct a new DateTimeFormat.

Parameters
formatThe format for dates with times.
dateFormatThe format for dates.
timeFormatThe format for times.

◆ ~DateTimeFormat()

Destructor.

Member Function Documentation

◆ format() [1/6]

String format ( const Date value) const

Format a Date.

Parameters
valueThe Date to format.
Returns
The formatted string representation of the date.

◆ format() [2/6]

size_t format ( const Date value,
char *  buf,
size_t  bufsz 
) const

Format a DateTime.

Parameters
valueThe Date to format.
bufA raw character buffer to write the formatted value to.
bufszThe size of the character buffer.
Returns
The number of characters written to the buffer.

◆ format() [3/6]

String format ( const Time value) const

Format a Time.

Parameters
valueThe Time to format.
Returns
The formatted string representation of the time.

◆ format() [4/6]

size_t format ( const Time value,
char *  buf,
size_t  bufsz 
) const

Format a DateTime.

Parameters
valueThe Time to format.
bufA raw character buffer to write the formatted value to.
bufszThe size of the character buffer.
Returns
The number of characters written to the buffer.

◆ format() [5/6]

String format ( const DateTime value) const

Format a DateTime.

Parameters
valueThe DateTime to format.
Returns
The formatted string representation of the date & time.

◆ format() [6/6]

size_t format ( const DateTime value,
char *  buf,
size_t  bufsz 
) const

Format a DateTime.

Parameters
valueThe DateTime to format.
bufA raw character buffer to write the formatted value to.
bufszThe size of the character buffer.
Returns
The number of characters written to the buffer.

◆ parse() [1/3]

void parse ( Date value,
const String text 
) const

Parse a Date from a string.

Parameters
valueThe value to parse into.
textThe string to parse.
Exceptions
ParseExceptionIf a parse error occurs.

◆ parse() [2/3]

void parse ( Time value,
const String text 
) const

Parse a Time from a string.

Parameters
valueThe value to parse into.
textThe string to parse.
Exceptions
ParseExceptionIf a parse error occurs.

◆ parse() [3/3]

void parse ( DateTime value,
const String text 
) const

Parse a DateTime from a string.

Parameters
valueThe value to parse into.
textThe string to parse.
Exceptions
ParseExceptionIf a parse error occurs.

◆ setDateFormat()

void setDateFormat ( const String dateFormat)
inline

Set the format for dates.

◆ setFormat()

void setFormat ( const String format)
inline

Set the format for dates with times.

◆ setTimeFormat()

void setTimeFormat ( const String timeFormat)
inline

Set the format for times.


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