Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
sese::text::DateTimeFormatter Class Reference

Date time formatter class. More...

#include <DateTimeFormatter.h>

Static Public Member Functions

static std::string format (const DateTime &date_time, const std::string &pattern=TIME_DEFAULT_PATTERN)
 
static std::string format (const std::unique_ptr< DateTime > &date_time, const std::string &pattern=TIME_DEFAULT_PATTERN)
 
static uint64_t parseFromGreenwich (const std::string &text)
 
static uint64_t parseFromISO8601 (const std::string &text)
 

Static Protected Member Functions

static int mon2number (const std::string &text)
 

Static Protected Attributes

static const std::map< std::string, uint8_t > MON_MAP
 
static const std::array< std::string, 12 > MON_ARRAY
 
static const std::map< std::string, uint8_t > MONTH_MAP
 
static const std::array< std::string, 12 > MONTH_ARRAY
 
static const std::array< std::string, 7 > WK_DAY
 
static const std::array< std::string, 7 > WEEK_DAY
 

Detailed Description

Date time formatter class.

Time format specifiers
d    Day of the month (1-31)
dd   Day of the month (01-31)
ddd  Abbreviated day of the week (Mon)
dddd Full name of the day of the week (Monday)
m    Minute (0-59)
mm   Minute (00-59)
M    Month (1-12)
MM   Month (01-12)
MMM  Abbreviated month (Jun)
MMMM Full name of the month (June)
y    Year (0-99)
yy   Year (00-99)
yyy  Year (000-999)
yyyy Year (0000-9999)
z    Offset from UTC
h    12-hour format (0-11)
hh   12-hour format (00-11)
H    24-hour format (0-23)
HH   24-hour format (00-23)
t    AM / PM - can be used with the 12-hour format
s    Second (0-59)
ss   Second (00-59)
f    Millisecond (0-999)
ff   Millisecond (000-999)
fff  Microsecond (0-999)
ffff Microsecond (000-999)
%    Escape character

Member Function Documentation

◆ format() [1/2]

◆ format() [2/2]

static std::string sese::text::DateTimeFormatter::format ( const std::unique_ptr< DateTime > & date_time,
const std::string & pattern = TIME_DEFAULT_PATTERN )
static

◆ mon2number()

int sese::text::DateTimeFormatter::mon2number ( const std::string & text)
staticprotected

◆ parseFromGreenwich()

uint64_t sese::text::DateTimeFormatter::parseFromGreenwich ( const std::string & text)
static

Convert Greenwich Mean Time to timestamp

Parameters
textGreenwich Mean Time text
"Tue, 17 Oct 2023 15:41:22 GMT"
"Thu, 31-Dec-37 23:55:55 GMT"
Returns
Timestamp

References timegm.

◆ parseFromISO8601()

uint64_t sese::text::DateTimeFormatter::parseFromISO8601 ( const std::string & text)
static

Convert ISO 8601 time to timestamp

Parameters
textISO 8601 time text
"2023-06-20"
"2023-06-20 16:46:55"
"2023-06-20T16:46:55Z"
"2023-06-20 16:46:55 +8"
"2023-06-20T16:46:55+00:00"
Returns
Timestamp

References sese::text::AbstractStringBuffer::split(), and timegm.

Member Data Documentation

◆ MON_ARRAY

const std::array< std::string, 12 > sese::text::DateTimeFormatter::MON_ARRAY
staticprotected
Initial value:
{
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
}

Referenced by format().

◆ MON_MAP

const std::map< std::string, uint8_t > sese::text::DateTimeFormatter::MON_MAP
staticprotected
Initial value:
{
{"Jan", 1},
{"Feb", 2},
{"Mar", 3},
{"Apr", 4},
{"May", 5},
{"Jun", 6},
{"Jul", 7},
{"Aug", 8},
{"Sep", 9},
{"Oct", 10},
{"Nov", 11},
{"Dec", 12}
}

◆ MONTH_ARRAY

const std::array< std::string, 12 > sese::text::DateTimeFormatter::MONTH_ARRAY
staticprotected
Initial value:
{
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
}

Referenced by format().

◆ MONTH_MAP

const std::map< std::string, uint8_t > sese::text::DateTimeFormatter::MONTH_MAP
staticprotected
Initial value:
{
{"January", 1},
{"February", 2},
{"March", 3},
{"April", 4},
{"May", 5},
{"June", 6},
{"July", 7},
{"August", 8},
{"September", 9},
{"October", 10},
{"November", 11},
{"December", 12}
}

◆ WEEK_DAY

const std::array< std::string, 7 > sese::text::DateTimeFormatter::WEEK_DAY
staticprotected
Initial value:
{
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
}

Referenced by format().

◆ WK_DAY

const std::array< std::string, 7 > sese::text::DateTimeFormatter::WK_DAY
staticprotected
Initial value:
{
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat"
}

Referenced by format().


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