OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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())
 
std::optional< int64_t > anonymous_namespace{DateTimeParser.cpp}::unixTime (std::string_view const str)
 
template<>
std::optional< int64_t > dateTimeParseOptional< kTIME > (std::string_view str, unsigned const dim)
 
template<>
std::optional< int64_t > dateTimeParseOptional< kTIMESTAMP > (std::string_view str, unsigned const dim)
 
template<>
std::optional< int64_t > dateTimeParseOptional< 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

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

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

Definition at line 398 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.

398  {
399  return out << dt.Y << '-' << dt.m << '-' << dt.d << ' ' << dt.H << ':' << dt.M << ':'
400  << dt.S << '.' << dt.n << " p("
401  << (dt.p ? *dt.p ? "true" : "false" : "unset") << ") z(" << dt.z << ')';
402 }