OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DateTimeParser.h File Reference
#include "Shared/StringTransform.h"
#include "sqltypes.h"
#include <optional>
#include <ostream>
#include <string_view>
+ Include dependency graph for DateTimeParser.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  DateTimeParser
 
struct  DateTimeParser::DateTime
 

Functions

template<SQLTypes SQL_TYPE>
std::optional< int64_t > dateTimeParseOptional (std::string_view, unsigned const dim)
 
template<>
std::optional< int64_t > dateTimeParseOptional< kDATE > (std::string_view, unsigned const dim)
 
template<>
std::optional< int64_t > dateTimeParseOptional< kTIME > (std::string_view, unsigned const dim)
 
template<>
std::optional< int64_t > dateTimeParseOptional< kTIMESTAMP > (std::string_view, unsigned const dim)
 
template<SQLTypes SQL_TYPE>
int64_t dateTimeParse (std::string_view const s, unsigned const dim)
 

Function Documentation

template<SQLTypes SQL_TYPE>
int64_t dateTimeParse ( std::string_view const  s,
unsigned const  dim 
)

Definition at line 40 of file DateTimeParser.h.

References cat(), and toString().

40  {
41  if (auto const time = dateTimeParseOptional<SQL_TYPE>(s, dim)) {
42  return *time;
43  } else {
44  throw std::runtime_error(cat("Invalid ", toString(SQL_TYPE), " string (", s, ')'));
45  }
46 }
std::string cat(Ts &&...args)
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1703

+ Here is the call graph for this function:

template<SQLTypes SQL_TYPE>
std::optional<int64_t> dateTimeParseOptional ( std::string_view  ,
unsigned const  dim 
)
template<>
std::optional<int64_t> dateTimeParseOptional< kDATE > ( std::string_view  ,
unsigned const  dim 
)

Definition at line 190 of file DateTimeParser.cpp.

References DateTimeParser::Date, DateTimeParser::parse(), run_benchmark_import::parser, DateTimeParser::setFormatType(), DateTimeParser::Timezone, anonymous_namespace{DateTimeParser.cpp}::unixTime(), and DateTimeParser::unparsed().

Referenced by import_export::Detector::detect_sqltype().

191  {
193  // Parse date
195  std::optional<int64_t> date = parser.parse(str, dim);
196  if (!date) {
197  return unixTime(str);
198  }
199  // Parse optional timezone
200  std::string_view timezone = parser.unparsed();
202  std::optional<int64_t> tz = parser.parse(timezone, dim);
203  return *date + tz.value_or(0);
204 }
std::optional< int64_t > parse(std::string_view const, unsigned dim)
std::optional< int64_t > unixTime(std::string_view const str)
void setFormatType(FormatType)
std::string_view unparsed() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<>
std::optional<int64_t> dateTimeParseOptional< kTIME > ( std::string_view  ,
unsigned const  dim 
)

Definition at line 135 of file DateTimeParser.cpp.

References DateTimeParser::parse(), run_benchmark_import::parser, DateTimeParser::setFormatType(), DateTimeParser::Time, DateTimeParser::Timezone, and DateTimeParser::unparsed().

Referenced by import_export::Detector::detect_sqltype().

136  {
137  if (!str.empty() && str.front() == 'T') {
138  str.remove_prefix(1);
139  }
142  std::optional<int64_t> time = parser.parse(str, dim);
143  if (!time) {
144  return std::nullopt;
145  }
146  // Parse optional timezone
147  std::string_view timezone = parser.unparsed();
149  std::optional<int64_t> tz = parser.parse(timezone, dim);
150  if (!parser.unparsed().empty()) {
151  return std::nullopt;
152  }
153  return *time + tz.value_or(0);
154 }
std::optional< int64_t > parse(std::string_view const, unsigned dim)
void setFormatType(FormatType)
std::string_view unparsed() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<>
std::optional<int64_t> dateTimeParseOptional< kTIMESTAMP > ( std::string_view  ,
unsigned const  dim 
)

Definition at line 159 of file DateTimeParser.cpp.

References DateTimeParser::Date, DateTimeParser::parse(), run_benchmark_import::parser, DateTimeParser::setFormatType(), DateTimeParser::Time, DateTimeParser::Timezone, anonymous_namespace{DateTimeParser.cpp}::unixTime(), and DateTimeParser::unparsed().

Referenced by import_export::Detector::detect_sqltype().

160  {
161  if (!str.empty() && str.front() == 'T') {
162  str.remove_prefix(1);
163  }
165  // Parse date
167  std::optional<int64_t> date = parser.parse(str, dim);
168  if (!date) {
169  return unixTime(str);
170  }
171  // Parse time-of-day
172  std::string_view time_of_day = parser.unparsed();
173  if (time_of_day.empty()) {
174  return std::nullopt;
175  } else if (time_of_day.front() == 'T' || time_of_day.front() == ':') {
176  time_of_day.remove_prefix(1);
177  }
179  std::optional<int64_t> time = parser.parse(time_of_day, dim);
180  // Parse optional timezone
181  std::string_view timezone = parser.unparsed();
183  std::optional<int64_t> tz = parser.parse(timezone, dim);
184  return *date + time.value_or(0) + tz.value_or(0);
185 }
std::optional< int64_t > parse(std::string_view const, unsigned dim)
std::optional< int64_t > unixTime(std::string_view const str)
void setFormatType(FormatType)
std::string_view unparsed() const

+ Here is the call graph for this function:

+ Here is the caller graph for this function: