16 #ifndef IMPALA_RUNTIME_TIMESTAMP_VALUE_H
17 #define IMPALA_RUNTIME_TIMESTAMP_VALUE_H
22 #include <boost/cstdint.hpp>
23 #include <boost/date_time/posix_time/posix_time.hpp>
24 #include <gflags/gflags.h>
33 DECLARE_bool(use_local_tz_for_unix_timestamp_conversions);
70 const boost::posix_time::time_duration& t)
74 :
time_(t.time_of_day()),
83 template <
typename Number>
90 temp += boost::posix_time::nanoseconds(nanos);
95 const time_t unix_time_whole = unix_time;
97 temp += boost::posix_time::nanoseconds((unix_time - unix_time_whole) /
ONE_BILLIONTH);
106 return TimestampValue(boost::posix_time::microsec_clock::local_time());
128 void ToPtime(boost::posix_time::ptime* ptp)
const {
129 *ptp = boost::posix_time::ptime(
date_,
time_);
138 std::stringstream ss;
140 ss << boost::gregorian::to_iso_extended_string(
date_);
144 ss << boost::posix_time::to_simple_string(
time_);
166 const boost::posix_time::ptime temp(
date_,
time_);
167 tm temp_tm = boost::posix_time::to_tm(temp);
168 if (FLAGS_use_local_tz_for_unix_timestamp_conversions) {
169 return mktime(&temp_tm);
171 return timegm(&temp_tm);
189 const boost::gregorian::date&
date()
const {
return date_; }
190 const boost::posix_time::time_duration&
time()
const {
return time_; }
193 date_ = ptime.date();
194 time_ = ptime.time_of_day();
209 return *
this < other || *
this == other; }
216 return *
this > other || *
this == other;
220 return sizeof(boost::posix_time::time_duration) +
sizeof(boost::gregorian::date);
223 inline uint32_t
Hash(
int seed = 0)
const {
243 boost::posix_time::time_duration
time_;
257 if (FLAGS_use_local_tz_for_unix_timestamp_conversions) {
258 if (
UNLIKELY(localtime_r(&unix_time, &temp_tm) == NULL)) {
259 return boost::posix_time::ptime(boost::posix_time::not_a_date_time);
262 if (
UNLIKELY(gmtime_r(&unix_time, &temp_tm) == NULL)) {
263 return boost::posix_time::ptime(boost::posix_time::not_a_date_time);
267 return boost::posix_time::ptime_from_tm(temp_tm);
268 }
catch (std::exception& e) {
269 return boost::posix_time::ptime(boost::posix_time::not_a_date_time);
279 std::ostream&
operator<<(std::ostream& os,
const TimestampValue& timestamp_value);
int Format(const DateTimeFormatContext &dt_ctx, int len, char *buff)
int64_t time_of_day
Nanoseconds in current day.
TimestampValue(int64_t unix_time, int64_t nanos)
bool operator!=(const TimestampValue &other) const
boost::posix_time::ptime UnixTimeToPtime(time_t unix_time) const
TimestampValue(const boost::posix_time::ptime &t)
const StringSearch UrlParser::hash_search & hash
boost::gregorian::date date_
4 -bytes - stores the date as a day
bool HasDateOrTime() const
const boost::posix_time::time_duration & time() const
int32_t date
Gregorian date. This has the same binary format as boost::gregorian::date.
This object has a compatible storage format with boost::ptime.
std::size_t hash_value(const Decimal4Value &v)
This function must be called 'hash_value' to be picked up by boost.
TimestampValue(const boost::gregorian::date &d, const boost::posix_time::time_duration &t)
void ToTimestampVal(impala_udf::TimestampVal *tv) const
void set_time(const boost::posix_time::time_duration t)
bool operator<(const TimestampValue &other) const
TimestampValue & operator=(const boost::posix_time::ptime &ptime)
static uint32_t Hash(const void *data, int32_t bytes, uint32_t seed)
uint32_t Hash(int seed=0) const
bool operator==(const TimestampValue &other) const
void set_date(const boost::gregorian::date d)
bool operator>(const TimestampValue &other) const
static TimestampValue FromTimestampVal(const impala_udf::TimestampVal &udf_value)
static const char * LLVM_CLASS_NAME
TimestampValue(double unix_time)
static const double ONE_BILLIONTH
double ToSubsecondUnixTime() const
DECLARE_bool(use_local_tz_for_unix_timestamp_conversions)
TimestampValue(const TimestampValue &tv)
bool operator>=(const TimestampValue &other) const
void ToPtime(boost::posix_time::ptime *ptp) const
ostream & operator<<(ostream &os, const map< TNetworkAddress, llama::TAllocatedResource > &resources)
TimestampValue(Number unix_time)
const boost::gregorian::date & date() const
bool HasDateAndTime() const
boost::posix_time::time_duration time_
8 bytes - stores the nanoseconds within the current day
bool operator<=(const TimestampValue &other) const
time_t ToUnixTime() const
static TimestampValue LocalTime()
std::string DebugString() const