OmniSciDB  2e3a973ef4
DateTimeParser.cpp File Reference
#include "DateTimeParser.h"
#include "StringTransform.h"
#include <boost/algorithm/string/predicate.hpp>
#include <algorithm>
#include <array>
#include <cctype>
#include <charconv>
#include <limits>
#include <sstream>
#include <vector>
+ Include dependency graph for DateTimeParser.cpp:

Go to the source code of this file.

Namespaces

 anonymous_namespace{DateTimeParser.cpp}
 

Functions

int64_t anonymous_namespace{DateTimeParser.cpp}::daysFromCivil (int64_t y, unsigned const m, unsigned const d)
 
std::vector< std::vector< std::string_view > > anonymous_namespace{DateTimeParser.cpp}::formatViews ()
 
void anonymous_namespace{DateTimeParser.cpp}::eatMonth (unsigned const month, std::string_view &str)
 
void anonymous_namespace{DateTimeParser.cpp}::eatSpace (std::string_view &str)
 
template<typename T >
std::optional< T > anonymous_namespace{DateTimeParser.cpp}::fromChars (std::string_view &str, size_t maxlen=std::numeric_limits< size_t >::max())
 
int64_t anonymous_namespace{DateTimeParser.cpp}::unixTime (std::string_view const &str)
 
template<>
int64_t dateTimeParse< kTIME > (std::string_view str, unsigned const dim)
 
template<>
int64_t dateTimeParse< kTIMESTAMP > (std::string_view str, unsigned const dim)
 
template<>
int64_t dateTimeParse< kDATE > (std::string_view str, unsigned const dim)
 
std::ostream & operator<< (std::ostream &out, DateTimeParser::DateTime const &dt)
 

Variables

constexpr std::array< int, 12 > anonymous_namespace{DateTimeParser.cpp}::month_prefixes
 
constexpr std::array< std::string_view, 13 > anonymous_namespace{DateTimeParser.cpp}::month_suffixes
 
constexpr unsigned anonymous_namespace{DateTimeParser.cpp}::pow_10 [10] {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000}
 

Function Documentation

◆ dateTimeParse< kDATE >()

template<>
int64_t dateTimeParse< kDATE > ( std::string_view  str,
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  str,
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  str,
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:

◆ operator<<()

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

Definition at line 387 of file DateTimeParser.cpp.

References DateTimeParser::DateTime::d, DateTimeParser::DateTime::H, DateTimeParser::DateTime::m, DateTimeParser::DateTime::M, DateTimeParser::DateTime::n, DateTimeParser::DateTime::p, DateTimeParser::DateTime::S, DateTimeParser::DateTime::Y, and DateTimeParser::DateTime::z.

387  {
388  return out << dt.Y << '-' << dt.m << '-' << dt.d << ' ' << dt.H << ':' << dt.M << ':'
389  << dt.S << '.' << dt.n << " p("
390  << (dt.p ? *dt.p ? "true" : "false" : "unset") << ") z(" << dt.z << ')';
391 }
const int8_t const int64_t const uint64_t const int32_t const int64_t int64_t ** out