Class DateTimeParser

class DateTimeParser

Set format_type_ and parse date/time/timestamp strings into (s,ms,us,ns) since the epoch based on given dim in (0,3,6,9) respectively. Basic idea is to parse given string by matching to formats (“%Y-%m-%d”, “%m/%d/%Y”, …) until a valid parse is found. Save parsed values into a DateTime dt_ struct from which the final epoch-based int64_t value is calculated.

Public Types

enum FormatType

Values:

Date
Time
Timezone

Public Functions

std::optional<int64_t> parse(std::string_view const, unsigned dim)
void setFormatType(FormatType format_type)
std::string_view unparsed() const

Private Functions

bool parseWithFormat(std::string_view format, std::string_view &str)
void resetDateTime()
bool updateDateTimeAndStr(char const field, std::string_view &str)

Private Members

DateTime dt_
FormatType format_type_
std::string_view unparsed_
struct DateTime

Public Functions

int64_t getTime(unsigned const dim) const

Public Members

int64_t Y = {1970}
unsigned m = {1}
unsigned d = {1}
unsigned H = {0}
unsigned M = {0}
unsigned S = {0}
unsigned n = {0}
int z = {0}
std::optional<bool> p

Friends

std::ostream &operator<<(std::ostream &out, DateTime const &dt)