OmniSciDB  fe05a0c208
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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())
 
std::optional< 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

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 }
tuple d
Definition: test_fsi.py:9

+ Here is the caller graph for this function:

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{GeoIR.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
std::string suffix(SQLTypes type)
Definition: GeoIR.cpp:419

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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:

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", "%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 . %M . %S %p",
83  "%I %p"},
84  {"%z"}}};
85 }

+ Here is the caller graph for this function:

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, and omnisci.dtypes::T.

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 }
std::optional<int64_t> anonymous_namespace{DateTimeParser.cpp}::unixTime ( std::string_view const  str)

Definition at line 119 of file DateTimeParser.cpp.

References run_benchmark_import::result.

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

119  {
120  int64_t time{0};
121  auto const result = std::from_chars(str.data(), str.data() + str.size(), time);
122  // is_valid = str =~ /^-?\d+(\.\d*)$/
123  bool const is_valid = result.ec == std::errc() &&
124  (result.ptr == str.data() + str.size() ||
125  (*result.ptr == '.' &&
126  std::all_of(result.ptr + 1, str.data() + str.size(), isdigit)));
127  return is_valid ? std::make_optional(time) : std::nullopt;
128 }

+ Here is the caller graph for this function:

Variable Documentation

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().

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().

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