OmniSciDB  2e3a973ef4
DateTimeParser.h File Reference
#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>
int64_t dateTimeParse (std::string_view, unsigned const dim)
 
template<>
int64_t dateTimeParse< kDATE > (std::string_view, unsigned const dim)
 
template<>
int64_t dateTimeParse< kTIME > (std::string_view, unsigned const dim)
 
template<>
int64_t dateTimeParse< kTIMESTAMP > (std::string_view, unsigned const dim)
 

Function Documentation

◆ dateTimeParse()

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

◆ dateTimeParse< kDATE >()

template<>
int64_t dateTimeParse< kDATE > ( std::string_view  ,
unsigned const  dim 
)

Definition at line 187 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 StringToDatum().

187  {
189  // Parse date
191  std::optional<int64_t> date = parser.parse(str, dim);
192  if (!date) {
193  return unixTime(str);
194  }
195  // Parse optional timezone
196  std::string_view timezone = parser.unparsed();
198  std::optional<int64_t> tz = parser.parse(timezone, dim);
199  return *date + tz.value_or(0);
200 }
int64_t unixTime(std::string_view const &str)
std::optional< int64_t > parse(std::string_view const &, unsigned dim)
std::string_view unparsed() const
void setFormatType(FormatType)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dateTimeParse< kTIME >()

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

Definition at line 134 of file DateTimeParser.cpp.

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

Referenced by StringToDatum().

134  {
135  if (!str.empty() && str.front() == 'T') {
136  str.remove_prefix(1);
137  }
140  std::optional<int64_t> time = parser.parse(str, dim);
141  if (!time) {
142  throw std::runtime_error(cat("Invalid TIME string (", str, ')'));
143  }
144  // Parse optional timezone
145  std::string_view timezone = parser.unparsed();
147  std::optional<int64_t> tz = parser.parse(timezone, dim);
148  if (!parser.unparsed().empty()) {
149  throw std::runtime_error(cat("Invalid TIME string (", str, ')'));
150  }
151  return *time + tz.value_or(0);
152 }
std::optional< int64_t > parse(std::string_view const &, unsigned dim)
std::string cat(Ts &&... args)
std::string_view unparsed() const
void setFormatType(FormatType)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dateTimeParse< kTIMESTAMP >()

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

Definition at line 157 of file DateTimeParser.cpp.

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

Referenced by foreign_storage::get_next_refresh_time(), Catalog_Namespace::Catalog::getForeignServersForUser(), StringToDatum(), and foreign_storage::ForeignTable::validate().

157  {
158  if (!str.empty() && str.front() == 'T') {
159  str.remove_prefix(1);
160  }
162  // Parse date
164  std::optional<int64_t> date = parser.parse(str, dim);
165  if (!date) {
166  return unixTime(str);
167  }
168  // Parse optional time-of-day
169  std::string_view time_of_day = parser.unparsed();
170  if (time_of_day.empty()) {
171  throw std::runtime_error(cat("TIMESTAMP requires a time-of-day (", str, ')'));
172  } else if (time_of_day.front() == 'T' || time_of_day.front() == ':') {
173  time_of_day.remove_prefix(1);
174  }
176  std::optional<int64_t> time = parser.parse(time_of_day, dim);
177  // Parse optional timezone
178  std::string_view timezone = parser.unparsed();
180  std::optional<int64_t> tz = parser.parse(timezone, dim);
181  return *date + time.value_or(0) + tz.value_or(0);
182 }
int64_t unixTime(std::string_view const &str)
std::optional< int64_t > parse(std::string_view const &, unsigned dim)
std::string cat(Ts &&... args)
std::string_view unparsed() const
void setFormatType(FormatType)
+ Here is the call graph for this function:
+ Here is the caller graph for this function: