29 size_t formatDate(
char* buf,
size_t const max, int64_t
const unixtime) {
32 unsigned const doe =
static_cast<unsigned>(div_era.
rem);
33 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
34 unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
35 unsigned const moy = (5 * doy + 2) / 153;
36 static_assert(8 <=
sizeof(
long long));
37 long long const y = 2000 + div_era.
quot * 400 + yoe + (9 < moy);
38 unsigned const m = moy + (9 < moy ? -9 : 3);
39 unsigned const d = doy - (153 * moy + 2) / 5 + 1;
40 int const len = snprintf(buf, max,
"%04lld-%02u-%02u", y, m, d);
41 if (0 <= len && static_cast<size_t>(len) < max) {
42 return static_cast<size_t>(len);
49 int64_t
const timestamp,
51 bool use_iso_format) {
52 constexpr
int pow10[10]{
53 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
57 unsigned const doe =
static_cast<unsigned>(div_era.
rem);
58 unsigned const yoe = (doe - doe / 1460 + doe / 36524 - (doe == 146096)) / 365;
59 unsigned const doy = doe - (365 * yoe + yoe / 4 - yoe / 100);
60 unsigned const moy = (5 * doy + 2) / 153;
61 static_assert(8 <=
sizeof(
long long));
62 long long const y = 2000 + div_era.
quot * 400 + yoe + (9 < moy);
63 unsigned const m = moy + (9 < moy ? -9 : 3);
64 unsigned const d = doy - (153 * moy + 2) / 5 + 1;
65 unsigned const minutes =
static_cast<unsigned>(div_day.
rem) / 60;
66 unsigned const ss = div_day.
rem % 60;
67 unsigned const hh = minutes / 60;
68 unsigned const mm = minutes % 60;
69 const char* date_time_format;
72 date_time_format =
"%04lld-%02u-%02uT%02u:%02u:%02u";
74 date_time_format =
"%04lld-%02u-%02uT%02u:%02u:%02uZ";
77 date_time_format =
"%04lld-%02u-%02u %02u:%02u:%02u";
79 int const len = snprintf(buf, max, date_time_format, y, m, d, hh, mm, ss);
80 if (0 <= len && static_cast<size_t>(len) < max) {
82 auto precision_format = use_iso_format ?
".%0*dZ" :
".%0*d";
83 int const len_frac = snprintf(buf + len,
87 static_cast<int>(div_hip.
rem));
88 if (0 <= len_frac && static_cast<size_t>(len + len_frac) < max) {
89 return static_cast<size_t>(len + len_frac);
92 return static_cast<size_t>(len);
98 size_t formatHMS(
char* buf,
size_t const max, int64_t
const unixtime) {
99 unsigned const seconds =
static_cast<unsigned>(
unsignedMod(unixtime, 24 * 60 * 60));
100 unsigned const minutes = seconds / 60;
101 unsigned const ss = seconds % 60;
102 unsigned const hh = minutes / 60;
103 unsigned const mm = minutes % 60;
104 int const len = snprintf(buf, max,
"%02u:%02u:%02u", hh, mm, ss);
105 if (0 <= len && static_cast<size_t>(len) < max) {
106 return static_cast<size_t>(len);
117 const auto len =
shared::formatHMS(iso_str.data(), iso_str.length() + 1, unix_time);
125 CHECK_GT(len, static_cast<size_t>(0));
132 iso_str.resize(18 + 1 + 8 +
bool(precision) + precision + 1);
134 iso_str.data(), iso_str.length() + 1, unix_time, precision,
true);
135 CHECK_GT(len, static_cast<size_t>(0));
144 static_assert(
sizeof(item_1) +
sizeof(item_2) <=
sizeof(
size_t));
145 return (static_cast<size_t>(item_1) << (8 *
sizeof(item_2))) |
146 (
static_cast<size_t>(item_2));
155 if (!file.is_open()) {
156 os <<
"\"Unable to open " <<
filename <<
'"';
160 std::ios orig_os_state(
nullptr);
161 orig_os_state.copyfmt(os);
163 while (file.get(ch)) {
166 }
else if (ch ==
'\\') {
168 }
else if (std::isprint(ch) || ch ==
' ') {
173 case '\b': os <<
"\\b";
break;
174 case '\f': os <<
"\\f";
break;
175 case '\n': os <<
"\\n";
break;
176 case '\r': os <<
"\\r";
break;
177 case '\t': os <<
"\\t";
break;
180 os <<
"\\u" << std::hex << std::setw(4) << std::setfill(
'0')
181 <<
static_cast<unsigned>(
static_cast<unsigned char>(ch));
187 os.copyfmt(orig_os_state);
std::ostream & operator<<(std::ostream &os, const StringDictKey &dict_key)
std::string convert_temporal_to_iso_format(const SQLTypeInfo &type_info, int64_t unix_time)
Constants for Builtin SQL Types supported by HEAVY.AI.
HOST DEVICE SQLTypes get_type() const
size_t formatHMS(char *buf, size_t const max, int64_t const unixtime)
char const *const filename
std::string toString() const
int get_precision() const
size_t formatDate(char *buf, size_t const max, int64_t const unixtime)
uint64_t unsignedMod(int64_t num, int64_t den)
size_t formatDateTime(char *buf, size_t const max, int64_t const timestamp, int const dimension, bool use_iso_format)
size_t compute_hash(int32_t item_1, int32_t item_2)
void quoteAndPrint(std::ostream &) const
DivUMod divUMod(int64_t num, int64_t den)