OmniSciDB  2e3a973ef4
anonymous_namespace{DateTimeParser.cpp} Namespace Reference

Functions

int64_t daysFromCivil (int64_t y, unsigned const m, unsigned const d)
 
std::vector< std::vector< std::string_view > > formatViews ()
 
void eatMonth (unsigned const month, std::string_view &str)
 
void eatSpace (std::string_view &str)
 
template<typename T >
std::optional< T > fromChars (std::string_view &str, size_t maxlen=std::numeric_limits< size_t >::max())
 
int64_t unixTime (std::string_view const &str)
 

Variables

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

Function Documentation

◆ daysFromCivil()

int64_t anonymous_namespace{DateTimeParser.cpp}::daysFromCivil ( int64_t  y,
unsigned const  m,
unsigned const  d 
)

Definition at line 65 of file DateTimeParser.cpp.

Referenced by DateTimeParser::DateTime::getTime().

65  {
66  y -= m <= 2;
67  int64_t const era = (y < 0 ? y - 399 : y) / 400;
68  unsigned const yoe = static_cast<unsigned>(y - era * 400); // [0, 399]
69  unsigned const doy = (153 * (m + (m <= 2 ? 9 : -3)) + 2) / 5 + d - 1; // [0, 365]
70  unsigned const doe = yoe * 365 + yoe / 4 - yoe / 100 + doy; // [0, 146096]
71  return era * 146097 + static_cast<int64_t>(doe) - 719468;
72 }
+ Here is the caller graph for this function:

◆ eatMonth()

void anonymous_namespace{DateTimeParser.cpp}::eatMonth ( unsigned const  month,
std::string_view &  str 
)

Definition at line 88 of file DateTimeParser.cpp.

References month_suffixes, and anonymous_namespace{RelAlgTranslatorGeo.cpp}::suffix().

Referenced by DateTimeParser::updateDateTimeAndStr().

88  {
89  str.remove_prefix(3);
90  std::string_view const& suffix = month_suffixes[month];
91  if (boost::algorithm::istarts_with(str, suffix)) {
92  str.remove_prefix(suffix.size());
93  }
94 }
constexpr std::array< std::string_view, 13 > month_suffixes
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ eatSpace()

void anonymous_namespace{DateTimeParser.cpp}::eatSpace ( std::string_view &  str)

Definition at line 96 of file DateTimeParser.cpp.

Referenced by DateTimeParser::parseWithFormat().

96  {
97  while (!str.empty() && isspace(str.front())) {
98  str.remove_prefix(1);
99  }
100 }
+ Here is the caller graph for this function:

◆ formatViews()

std::vector<std::vector<std::string_view> > anonymous_namespace{DateTimeParser.cpp}::formatViews ( )

Definition at line 75 of file DateTimeParser.cpp.

Referenced by DateTimeParser::parse().

75  {
76  return {{{"%Y-%m-%d", "%m/%d/%Y", "%Y/%m/%d", "%d-%b-%y", "%d/%b/%Y"},
77  {"%I:%M:%S %p",
78  "%H:%M:%S",
79  "%I:%M %p",
80  "%H:%M",
81  "%H%M%S",
82  "%I %p",
83  "%I . %M . %S %p"},
84  {"%z"}}};
85 }
+ Here is the caller graph for this function:

◆ fromChars()

template<typename T >
std::optional<T> anonymous_namespace{DateTimeParser.cpp}::fromChars ( std::string_view &  str,
size_t  maxlen = std::numeric_limits<size_t>::max() 
)

Definition at line 106 of file DateTimeParser.cpp.

References run_benchmark_import::result.

107  {
108  T retval;
109  maxlen = std::min(maxlen, str.size());
110  auto const result = std::from_chars(str.data(), str.data() + maxlen, retval);
111  if (result.ec == std::errc()) {
112  str.remove_prefix(result.ptr - str.data());
113  return retval;
114  } else {
115  return std::nullopt;
116  }
117 }

◆ unixTime()

int64_t anonymous_namespace{DateTimeParser.cpp}::unixTime ( std::string_view const &  str)

Definition at line 120 of file DateTimeParser.cpp.

References cat(), and run_benchmark_import::result.

Referenced by dateTimeParse< kDATE >(), and dateTimeParse< kTIMESTAMP >().

120  {
121  int64_t time{0};
122  auto const result = std::from_chars(str.data(), str.data() + str.size(), time);
123  if (result.ec == std::errc()) {
124  return time;
125  } else {
126  throw std::runtime_error(cat("Invalid DATE/TIMESTAMP string (", str, ')'));
127  }
128 }
std::string cat(Ts &&... args)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ month_prefixes

constexpr std::array<int, 12> anonymous_namespace{DateTimeParser.cpp}::month_prefixes
Initial value:
{{int('j') << 16 | int('a') << 8 | int('n'),
int('f') << 16 | int('e') << 8 | int('b'),
int('m') << 16 | int('a') << 8 | int('r'),
int('a') << 16 | int('p') << 8 | int('r'),
int('m') << 16 | int('a') << 8 | int('y'),
int('j') << 16 | int('u') << 8 | int('n'),
int('j') << 16 | int('u') << 8 | int('l'),
int('a') << 16 | int('u') << 8 | int('g'),
int('s') << 16 | int('e') << 8 | int('p'),
int('o') << 16 | int('c') << 8 | int('t'),
int('n') << 16 | int('o') << 8 | int('v'),
int('d') << 16 | int('e') << 8 | int('c')}}

Definition at line 32 of file DateTimeParser.cpp.

Referenced by DateTimeParser::updateDateTimeAndStr().

◆ month_suffixes

constexpr std::array<std::string_view, 13> anonymous_namespace{DateTimeParser.cpp}::month_suffixes
Initial value:
{
{""
"uary",
"ruary",
"ch",
"il",
"",
"e",
"y",
"ust",
"tember",
"ober",
"ember",
"ember"}}

Definition at line 45 of file DateTimeParser.cpp.

Referenced by eatMonth().

◆ pow_10

constexpr unsigned anonymous_namespace{DateTimeParser.cpp}::pow_10[10] {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000}