Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::Interval Class Reference

#include <duckdb.hpp>

Static Public Member Functions

static bool FromString (const string &str, interval_t &result)
 Convert a string to an interval object.
static bool FromCString (const char *str, idx_t len, interval_t &result, string *error_message, bool strict)
 Convert a string to an interval object.
static string ToString (const interval_t &val)
 Convert an interval object to a string.
static DUCKDB_API interval_t FromMicro (int64_t micros)
 Convert milliseconds to a normalised interval.
static int64_t GetMilli (const interval_t &val)
 Get Interval in milliseconds.
static bool TryGetMicro (const interval_t &val, int64_t &micros)
 Get Interval in microseconds.
static int64_t GetMicro (const interval_t &val)
static int64_t GetNanoseconds (const interval_t &val)
 Get Interval in Nanoseconds.
static interval_t GetAge (timestamp_t timestamp_1, timestamp_t timestamp_2)
 Returns the age between two timestamps (including months).
static interval_t GetAge (TimestampComponents ts1, TimestampComponents ts2, bool is_negative)
 Returns the age between two timestamp components.
static interval_t GetDifference (timestamp_t timestamp_1, timestamp_t timestamp_2)
 Returns the exact difference between two timestamps (days and seconds).
static interval_t Invert (interval_t interval)
 Returns the inverted interval.
static date_t Add (date_t left, interval_t right)
 Add an interval to a date.
static timestamp_t Add (timestamp_t left, interval_t right)
 Add an interval to a timestamp.
static dtime_t Add (dtime_t left, interval_t right, date_t &date)
static dtime_tz_t Add (dtime_tz_t left, interval_t right, date_t &date)
static bool Equals (const interval_t &left, const interval_t &right)
 Comparison operators.
static bool GreaterThan (const interval_t &left, const interval_t &right)

Static Public Attributes

static constexpr const int32_t MONTHS_PER_MILLENIUM = 12000
static constexpr const int32_t MONTHS_PER_CENTURY = 1200
static constexpr const int32_t MONTHS_PER_DECADE = 120
static constexpr const int32_t MONTHS_PER_YEAR = 12
static constexpr const int32_t MONTHS_PER_QUARTER = 3
static constexpr const int32_t DAYS_PER_WEEK = 7
static constexpr const int64_t DAYS_PER_MONTH = 30
 only used for interval comparison/ordering purposes, in which case a month counts as 30 days
static constexpr const int64_t DAYS_PER_YEAR = 365
static constexpr const int64_t MSECS_PER_SEC = 1000
static constexpr const int32_t SECS_PER_MINUTE = 60
static constexpr const int32_t MINS_PER_HOUR = 60
static constexpr const int32_t HOURS_PER_DAY = 24
static constexpr const int32_t SECS_PER_HOUR = SECS_PER_MINUTE * MINS_PER_HOUR
static constexpr const int32_t SECS_PER_DAY = SECS_PER_HOUR * HOURS_PER_DAY
static constexpr const int32_t SECS_PER_WEEK = SECS_PER_DAY * DAYS_PER_WEEK
static constexpr const int64_t MICROS_PER_MSEC = 1000
static constexpr const int64_t MICROS_PER_SEC = MICROS_PER_MSEC * MSECS_PER_SEC
static constexpr const int64_t MICROS_PER_MINUTE = MICROS_PER_SEC * SECS_PER_MINUTE
static constexpr const int64_t MICROS_PER_HOUR = MICROS_PER_MINUTE * MINS_PER_HOUR
static constexpr const int64_t MICROS_PER_DAY = MICROS_PER_HOUR * HOURS_PER_DAY
static constexpr const int64_t MICROS_PER_WEEK = MICROS_PER_DAY * DAYS_PER_WEEK
static constexpr const int64_t MICROS_PER_MONTH = MICROS_PER_DAY * DAYS_PER_MONTH
static constexpr const int64_t NANOS_PER_MICRO = 1000
static constexpr const int64_t NANOS_PER_MSEC = NANOS_PER_MICRO * MICROS_PER_MSEC
static constexpr const int64_t NANOS_PER_SEC = NANOS_PER_MSEC * MSECS_PER_SEC
static constexpr const int64_t NANOS_PER_MINUTE = NANOS_PER_SEC * SECS_PER_MINUTE
static constexpr const int64_t NANOS_PER_HOUR = NANOS_PER_MINUTE * MINS_PER_HOUR
static constexpr const int64_t NANOS_PER_DAY = NANOS_PER_HOUR * HOURS_PER_DAY
static constexpr const int64_t NANOS_PER_WEEK = NANOS_PER_DAY * DAYS_PER_WEEK

Detailed Description

The Interval class is a static class that holds helper functions for the Interval type.

Member Function Documentation

◆ FromString()

bool duckdb::Interval::FromString ( const string & str,
interval_t & result )
static

Convert a string to an interval object.

123112 {
123113 string error_message;
123114 return Interval::FromCString(str.c_str(), str.size(), result, &error_message, false);
123115}
static bool FromCString(const char *str, idx_t len, interval_t &result, string *error_message, bool strict)
Convert a string to an interval object.
Definition duckdb.cpp:123138
Here is the call graph for this function:

◆ FromCString()

bool duckdb::Interval::FromCString ( const char * str,
idx_t len,
interval_t & result,
string * error_message,
bool strict )
static

Convert a string to an interval object.

123138 {
123139 idx_t pos = 0;
123140 idx_t start_pos;
123141 bool negative;
123142 bool found_any = false;
123143 int64_t number;
123144 int64_t fraction;
123145 DatePartSpecifier specifier;
123146 string specifier_str;
123147
123148 result.days = 0;
123149 result.micros = 0;
123150 result.months = 0;
123151
123152 if (len == 0) {
123153 return false;
123154 }
123155
123156 switch (str[pos]) {
123157 case '@':
123158 pos++;
123159 goto standard_interval;
123160 case 'P':
123161 case 'p':
123162 pos++;
123163 goto posix_interval;
123164 default:
123165 goto standard_interval;
123166 }
123167standard_interval:
123168 // start parsing a standard interval (e.g. 2 years 3 months...)
123169 for (; pos < len; pos++) {
123170 char c = str[pos];
123171 if (c == ' ' || c == '\t' || c == '\n') {
123172 // skip spaces
123173 continue;
123174 } else if (c >= '0' && c <= '9') {
123175 // start parsing a positive number
123176 negative = false;
123177 goto interval_parse_number;
123178 } else if (c == '-') {
123179 // negative number
123180 negative = true;
123181 pos++;
123182 goto interval_parse_number;
123183 } else if (c == 'a' || c == 'A') {
123184 // parse the word "ago" as the final specifier
123185 goto interval_parse_ago;
123186 } else {
123187 // unrecognized character, expected a number or end of string
123188 return false;
123189 }
123190 }
123191 goto end_of_string;
123192interval_parse_number:
123193 start_pos = pos;
123194 for (; pos < len; pos++) {
123195 char c = str[pos];
123196 if (c >= '0' && c <= '9') {
123197 // the number continues
123198 continue;
123199 } else if (c == ':') {
123200 // colon: we are parsing a time
123201 goto interval_parse_time;
123202 } else {
123203 if (pos == start_pos) {
123204 return false;
123205 }
123206 // finished the number, parse it from the string
123207 string_t nr_string(str + start_pos, UnsafeNumericCast<uint32_t>(pos - start_pos));
123208 number = Cast::Operation<string_t, int64_t>(nr_string);
123209 fraction = 0;
123210 if (c == '.') {
123211 // we expect some microseconds
123212 int32_t mult = 100000;
123213 for (++pos; pos < len && StringUtil::CharacterIsDigit(str[pos]); ++pos, mult /= 10) {
123214 if (mult > 0) {
123215 fraction += int64_t(str[pos] - '0') * mult;
123216 }
123217 }
123218 }
123219 if (negative) {
123220 number = -number;
123221 fraction = -fraction;
123222 }
123223 goto interval_parse_identifier;
123224 }
123225 }
123226 goto end_of_string;
123227interval_parse_time : {
123228 // parse the remainder of the time as a Time type
123229 dtime_t time;
123230 idx_t pos;
123231 if (!Time::TryConvertInterval(str + start_pos, len - start_pos, pos, time)) {
123232 return false;
123233 }
123234 result.micros += time.micros;
123235 found_any = true;
123236 if (negative) {
123237 result.micros = -result.micros;
123238 }
123239 goto end_of_string;
123240}
123241interval_parse_identifier:
123242 for (; pos < len; pos++) {
123243 char c = str[pos];
123244 if (c == ' ' || c == '\t' || c == '\n') {
123245 // skip spaces at the start
123246 continue;
123247 } else {
123248 break;
123249 }
123250 }
123251 // now parse the identifier
123252 start_pos = pos;
123253 for (; pos < len; pos++) {
123254 char c = str[pos];
123255 if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
123256 // keep parsing the string
123257 continue;
123258 } else {
123259 break;
123260 }
123261 }
123262 specifier_str = string(str + start_pos, pos - start_pos);
123263
123264 // Special case SS[.FFFFFF] - implied SECONDS/MICROSECONDS
123265 if (specifier_str.empty() && !found_any) {
123266 IntervalTryAddition<int64_t>(result.micros, number, MICROS_PER_SEC);
123267 IntervalTryAddition<int64_t>(result.micros, fraction, 1);
123268 found_any = true;
123269 // parse any trailing whitespace
123270 for (; pos < len; pos++) {
123271 char c = str[pos];
123272 if (c == ' ' || c == '\t' || c == '\n') {
123273 continue;
123274 } else {
123275 return false;
123276 }
123277 }
123278 goto end_of_string;
123279 }
123280
123281 if (!TryGetDatePartSpecifier(specifier_str, specifier)) {
123282 HandleCastError::AssignError(StringUtil::Format("extract specifier \"%s\" not recognized", specifier_str),
123283 error_message);
123284 return false;
123285 }
123286 // add the specifier to the interval
123287 switch (specifier) {
123288 case DatePartSpecifier::MILLENNIUM:
123289 IntervalTryAddition<int32_t>(result.months, number, MONTHS_PER_MILLENIUM, fraction);
123290 break;
123291 case DatePartSpecifier::CENTURY:
123292 IntervalTryAddition<int32_t>(result.months, number, MONTHS_PER_CENTURY, fraction);
123293 break;
123294 case DatePartSpecifier::DECADE:
123295 IntervalTryAddition<int32_t>(result.months, number, MONTHS_PER_DECADE, fraction);
123296 break;
123297 case DatePartSpecifier::YEAR:
123298 IntervalTryAddition<int32_t>(result.months, number, MONTHS_PER_YEAR, fraction);
123299 break;
123300 case DatePartSpecifier::QUARTER:
123301 IntervalTryAddition<int32_t>(result.months, number, MONTHS_PER_QUARTER, fraction);
123302 // Reduce to fraction of a month
123303 fraction *= MONTHS_PER_QUARTER;
123304 fraction %= MICROS_PER_SEC;
123305 IntervalTryAddition<int32_t>(result.days, 0, DAYS_PER_MONTH, fraction);
123306 break;
123307 case DatePartSpecifier::MONTH:
123308 IntervalTryAddition<int32_t>(result.months, number, 1);
123309 IntervalTryAddition<int32_t>(result.days, 0, DAYS_PER_MONTH, fraction);
123310 break;
123311 case DatePartSpecifier::DAY:
123312 IntervalTryAddition<int32_t>(result.days, number, 1);
123313 IntervalTryAddition<int64_t>(result.micros, 0, MICROS_PER_DAY, fraction);
123314 break;
123315 case DatePartSpecifier::WEEK:
123316 IntervalTryAddition<int32_t>(result.days, number, DAYS_PER_WEEK, fraction);
123317 // Reduce to fraction of a day
123318 fraction *= DAYS_PER_WEEK;
123319 fraction %= MICROS_PER_SEC;
123320 IntervalTryAddition<int64_t>(result.micros, 0, MICROS_PER_DAY, fraction);
123321 break;
123322 case DatePartSpecifier::MICROSECONDS:
123323 // Round the fraction
123324 number += (fraction * 2) / MICROS_PER_SEC;
123325 IntervalTryAddition<int64_t>(result.micros, number, 1);
123326 break;
123327 case DatePartSpecifier::MILLISECONDS:
123328 IntervalTryAddition<int64_t>(result.micros, number, MICROS_PER_MSEC, fraction);
123329 break;
123330 case DatePartSpecifier::SECOND:
123331 IntervalTryAddition<int64_t>(result.micros, number, MICROS_PER_SEC, fraction);
123332 break;
123333 case DatePartSpecifier::MINUTE:
123334 IntervalTryAddition<int64_t>(result.micros, number, MICROS_PER_MINUTE, fraction);
123335 break;
123336 case DatePartSpecifier::HOUR:
123337 IntervalTryAddition<int64_t>(result.micros, number, MICROS_PER_HOUR, fraction);
123338 break;
123339 default:
123340 HandleCastError::AssignError(
123341 StringUtil::Format("extract specifier \"%s\" not supported for interval", specifier_str), error_message);
123342 return false;
123343 }
123344 found_any = true;
123345 goto standard_interval;
123346interval_parse_ago:
123347 D_ASSERT(str[pos] == 'a' || str[pos] == 'A');
123348 // parse the "ago" string at the end of the interval
123349 if (len - pos < 3) {
123350 return false;
123351 }
123352 pos++;
123353 if (!(str[pos] == 'g' || str[pos] == 'G')) {
123354 return false;
123355 }
123356 pos++;
123357 if (!(str[pos] == 'o' || str[pos] == 'O')) {
123358 return false;
123359 }
123360 pos++;
123361 // parse any trailing whitespace
123362 for (; pos < len; pos++) {
123363 char c = str[pos];
123364 if (c == ' ' || c == '\t' || c == '\n') {
123365 continue;
123366 } else {
123367 return false;
123368 }
123369 }
123370 // invert all the values
123371 if (result.months == NumericLimits<int32_t>::Minimum() || result.days == NumericLimits<int32_t>::Minimum()) {
123372 throw OutOfRangeException("AGO interval value is out of range");
123373 }
123374
123375 result.months = -result.months;
123376 result.days = -result.days;
123377 result.micros = -result.micros;
123378 goto end_of_string;
123379end_of_string:
123380 if (!found_any) {
123381 // end of string and no identifiers were found: cannot convert empty interval
123382 return false;
123383 }
123384 return true;
123385posix_interval:
123386 return false;
123387}
static constexpr const int64_t DAYS_PER_MONTH
only used for interval comparison/ordering purposes, in which case a month counts as 30 days
Definition duckdb.hpp:5258
static string Format(const string fmt_str, ARGS... params)
Format a string using printf semantics.
Definition duckdb.hpp:4002
::int64_t int64_t
::int32_t int32_t
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ToString()

string duckdb::Interval::ToString ( const interval_t & val)
static

Convert an interval object to a string.

123389 {
123390 char buffer[70];
123391 idx_t length = IntervalToStringCast::Format(interval, buffer);
123392 return string(buffer, length);
123393}
static idx_t Format(interval_t interval, char buffer[])
Definition duckdb.cpp:20059
Here is the call graph for this function:

◆ FromMicro()

interval_t duckdb::Interval::FromMicro ( int64_t micros)
static

Convert milliseconds to a normalised interval.

123555 {
123556 interval_t result;
123557 result.months = 0;
123558 result.days = UnsafeNumericCast<int32_t>(delta_us / Interval::MICROS_PER_DAY);
123559 result.micros = delta_us % Interval::MICROS_PER_DAY;
123560
123561 return result;
123562}
Here is the caller graph for this function:

◆ GetMilli()

int64_t duckdb::Interval::GetMilli ( const interval_t & val)
static

Get Interval in milliseconds.

123395 {
123396 int64_t milli_month, milli_day, milli;
123397 if (!TryMultiplyOperator::Operation((int64_t)val.months, Interval::MICROS_PER_MONTH / 1000, milli_month)) {
123398 throw ConversionException("Could not convert Interval to Milliseconds");
123399 }
123400 if (!TryMultiplyOperator::Operation((int64_t)val.days, Interval::MICROS_PER_DAY / 1000, milli_day)) {
123401 throw ConversionException("Could not convert Interval to Milliseconds");
123402 }
123403 milli = val.micros / 1000;
123404 if (!TryAddOperator::Operation<int64_t, int64_t, int64_t>(milli, milli_month, milli)) {
123405 throw ConversionException("Could not convert Interval to Milliseconds");
123406 }
123407 if (!TryAddOperator::Operation<int64_t, int64_t, int64_t>(milli, milli_day, milli)) {
123408 throw ConversionException("Could not convert Interval to Milliseconds");
123409 }
123410 return milli;
123411}

◆ TryGetMicro()

bool duckdb::Interval::TryGetMicro ( const interval_t & val,
int64_t & micros )
static

Get Interval in microseconds.

123413 {
123414 int64_t micro_month, micro_day;
123415 micro_total = val.micros;
123416 if (!TryMultiplyOperator::Operation((int64_t)val.months, Interval::MICROS_PER_MONTH, micro_month)) {
123417 return false;
123418 }
123419 if (!TryMultiplyOperator::Operation((int64_t)val.days, Interval::MICROS_PER_DAY, micro_day)) {
123420 return false;
123421 }
123422 if (!TryAddOperator::Operation<int64_t, int64_t, int64_t>(micro_total, micro_month, micro_total)) {
123423 return false;
123424 }
123425 if (!TryAddOperator::Operation<int64_t, int64_t, int64_t>(micro_total, micro_day, micro_total)) {
123426 return false;
123427 }
123428
123429 return true;
123430}

◆ GetMicro()

int64_t duckdb::Interval::GetMicro ( const interval_t & val)
static
123432 {
123433 int64_t micro_month, micro_day, micro_total;
123434 micro_total = val.micros;
123435 if (!TryMultiplyOperator::Operation((int64_t)val.months, MICROS_PER_MONTH, micro_month)) {
123436 throw ConversionException("Could not convert Month to Microseconds");
123437 }
123438 if (!TryMultiplyOperator::Operation((int64_t)val.days, MICROS_PER_DAY, micro_day)) {
123439 throw ConversionException("Could not convert Day to Microseconds");
123440 }
123441 if (!TryAddOperator::Operation<int64_t, int64_t, int64_t>(micro_total, micro_month, micro_total)) {
123442 throw ConversionException("Could not convert Interval to Microseconds");
123443 }
123444 if (!TryAddOperator::Operation<int64_t, int64_t, int64_t>(micro_total, micro_day, micro_total)) {
123445 throw ConversionException("Could not convert Interval to Microseconds");
123446 }
123447
123448 return micro_total;
123449}

◆ GetNanoseconds()

int64_t duckdb::Interval::GetNanoseconds ( const interval_t & val)
static

Get Interval in Nanoseconds.

123451 {
123452 int64_t nano;
123453 const auto micro_total = GetMicro(val);
123454 if (!TryMultiplyOperator::Operation(micro_total, NANOS_PER_MICRO, nano)) {
123455 throw ConversionException("Could not convert Interval to Nanoseconds");
123456 }
123457
123458 return nano;
123459}

◆ GetAge() [1/2]

interval_t duckdb::Interval::GetAge ( timestamp_t timestamp_1,
timestamp_t timestamp_2 )
static

Returns the age between two timestamps (including months).

123533 {
123534 D_ASSERT(Timestamp::IsFinite(timestamp_1) && Timestamp::IsFinite(timestamp_2));
123535
123536 auto ts_component1 = Timestamp::GetComponents(timestamp_1);
123537 auto ts_component2 = Timestamp::GetComponents(timestamp_2);
123538
123539 return Interval::GetAge(ts_component1, ts_component2, timestamp_1 < timestamp_2);
123540}
static interval_t GetAge(timestamp_t timestamp_1, timestamp_t timestamp_2)
Returns the age between two timestamps (including months).
Definition duckdb.cpp:123533
static DUCKDB_API TimestampComponents GetComponents(timestamp_t timestamp)
Decompose a timestamp into its components.
Definition duckdb.cpp:129957
static bool IsFinite(timestamp_t timestamp)
True, if the timestamp is finite, else false.
Definition duckdb.hpp:4287
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAge() [2/2]

interval_t duckdb::Interval::GetAge ( TimestampComponents ts1,
TimestampComponents ts2,
bool is_negative )
static

Returns the age between two timestamp components.

123461 {
123462 // perform the differences
123463 auto year_diff = ts1.year - ts2.year;
123464 auto month_diff = ts1.month - ts2.month;
123465 auto day_diff = ts1.day - ts2.day;
123466
123467 auto hour_diff = ts1.hour - ts2.hour;
123468 auto min_diff = ts1.minute - ts2.minute;
123469 auto sec_diff = ts1.second - ts2.second;
123470 auto micros_diff = ts1.microsecond - ts2.microsecond;
123471
123472 // flip sign if necessary
123473 bool sign_flipped = false;
123474 if (is_negative) {
123475 year_diff = -year_diff;
123476 month_diff = -month_diff;
123477 day_diff = -day_diff;
123478 hour_diff = -hour_diff;
123479 min_diff = -min_diff;
123480 sec_diff = -sec_diff;
123481 micros_diff = -micros_diff;
123482 sign_flipped = true;
123483 }
123484 // now propagate any negative field into the next higher field
123485 while (micros_diff < 0) {
123486 micros_diff += MICROS_PER_SEC;
123487 sec_diff--;
123488 }
123489 while (sec_diff < 0) {
123490 sec_diff += SECS_PER_MINUTE;
123491 min_diff--;
123492 }
123493 while (min_diff < 0) {
123494 min_diff += MINS_PER_HOUR;
123495 hour_diff--;
123496 }
123497 while (hour_diff < 0) {
123498 hour_diff += HOURS_PER_DAY;
123499 day_diff--;
123500 }
123501 while (day_diff < 0) {
123502 if (is_negative) {
123503 day_diff += Date::IsLeapYear(ts1.year) ? Date::LEAP_DAYS[ts1.month] : Date::NORMAL_DAYS[ts1.month];
123504 month_diff--;
123505 } else {
123506 day_diff += Date::IsLeapYear(ts2.year) ? Date::LEAP_DAYS[ts2.month] : Date::NORMAL_DAYS[ts2.month];
123507 month_diff--;
123508 }
123509 }
123510 while (month_diff < 0) {
123511 month_diff += MONTHS_PER_YEAR;
123512 year_diff--;
123513 }
123514
123515 // recover sign if necessary
123516 if (sign_flipped) {
123517 year_diff = -year_diff;
123518 month_diff = -month_diff;
123519 day_diff = -day_diff;
123520 hour_diff = -hour_diff;
123521 min_diff = -min_diff;
123522 sec_diff = -sec_diff;
123523 micros_diff = -micros_diff;
123524 }
123525 interval_t interval;
123526 interval.months = year_diff * MONTHS_PER_YEAR + month_diff;
123527 interval.days = day_diff;
123528 interval.micros = Time::FromTime(hour_diff, min_diff, sec_diff, micros_diff).micros;
123529
123530 return interval;
123531}
static DUCKDB_API bool IsLeapYear(int32_t year)
Returns true if (year) is a leap year, and false otherwise.
Definition duckdb.cpp:117548
Here is the call graph for this function:

◆ GetDifference()

interval_t duckdb::Interval::GetDifference ( timestamp_t timestamp_1,
timestamp_t timestamp_2 )
static

Returns the exact difference between two timestamps (days and seconds).

123542 {
123543 if (!Timestamp::IsFinite(timestamp_1) || !Timestamp::IsFinite(timestamp_2)) {
123544 throw InvalidInputException("Cannot subtract infinite timestamps");
123545 }
123546 const auto us_1 = Timestamp::GetEpochMicroSeconds(timestamp_1);
123547 const auto us_2 = Timestamp::GetEpochMicroSeconds(timestamp_2);
123548 int64_t delta_us;
123549 if (!TrySubtractOperator::Operation(us_1, us_2, delta_us)) {
123550 throw ConversionException("Timestamp difference is out of bounds");
123551 }
123552 return FromMicro(delta_us);
123553}
static DUCKDB_API interval_t FromMicro(int64_t micros)
Convert milliseconds to a normalised interval.
Definition duckdb.cpp:123555
static DUCKDB_API int64_t GetEpochMicroSeconds(timestamp_t timestamp)
Convert a timestamp to epoch (in microseconds).
Definition duckdb.cpp:129909
Here is the call graph for this function:

◆ Invert()

interval_t duckdb::Interval::Invert ( interval_t interval)
static

Returns the inverted interval.

123564 {
123565 interval.days = -interval.days;
123566 interval.micros = -interval.micros;
123567 interval.months = -interval.months;
123568 return interval;
123569}

◆ Add() [1/4]

date_t duckdb::Interval::Add ( date_t left,
interval_t right )
static

Add an interval to a date.

123571 {
123572 if (!Date::IsFinite(left)) {
123573 return left;
123574 }
123575 date_t result;
123576 if (right.months != 0) {
123577 int32_t year, month, day;
123578 Date::Convert(left, year, month, day);
123579 int32_t year_diff = right.months / Interval::MONTHS_PER_YEAR;
123580 year += year_diff;
123581 month += right.months - year_diff * Interval::MONTHS_PER_YEAR;
123582 if (month > Interval::MONTHS_PER_YEAR) {
123583 year++;
123584 month -= Interval::MONTHS_PER_YEAR;
123585 } else if (month <= 0) {
123586 year--;
123587 month += Interval::MONTHS_PER_YEAR;
123588 }
123589 day = MinValue<int32_t>(day, Date::MonthDays(year, month));
123590 result = Date::FromDate(year, month, day);
123591 } else {
123592 result = left;
123593 }
123594 if (right.days != 0) {
123595 if (!TryAddOperator::Operation(result.days, right.days, result.days)) {
123596 throw OutOfRangeException("Date out of range");
123597 }
123598 }
123599 if (right.micros != 0) {
123600 if (!TryAddOperator::Operation(result.days, int32_t(right.micros / Interval::MICROS_PER_DAY), result.days)) {
123601 throw OutOfRangeException("Date out of range");
123602 }
123603 }
123604 if (!Date::IsFinite(result)) {
123605 throw OutOfRangeException("Date out of range");
123606 }
123607 return result;
123608}
static DUCKDB_API date_t FromDate(int32_t year, int32_t month, int32_t day)
Create a Date object from a specified (year, month, day) combination.
Definition duckdb.cpp:117328
static DUCKDB_API void Convert(date_t date, int32_t &out_year, int32_t &out_month, int32_t &out_day)
Extract the year, month and day from a given date object.
Definition duckdb.cpp:117272
static bool IsFinite(date_t date)
Returns true if the specified date is finite.
Definition duckdb.hpp:5078
static DUCKDB_API int32_t MonthDays(int32_t year, int32_t month)
The max number of days in a month of a given year.
Definition duckdb.cpp:117580
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Add() [2/4]

timestamp_t duckdb::Interval::Add ( timestamp_t left,
interval_t right )
static

Add an interval to a timestamp.

123627 {
123628 if (!Timestamp::IsFinite(left)) {
123629 return left;
123630 }
123631 date_t date;
123632 dtime_t time;
123633 Timestamp::Convert(left, date, time);
123634 auto new_date = Interval::Add(date, right);
123635 auto new_time = Interval::Add(time, right, new_date);
123636 return Timestamp::FromDatetime(new_date, new_time);
123637}
static date_t Add(date_t left, interval_t right)
Add an interval to a date.
Definition duckdb.cpp:123571
static DUCKDB_API timestamp_t FromDatetime(date_t date, dtime_t time)
Create a Timestamp object from a specified (date, time) combination.
Definition duckdb.cpp:129804
static DUCKDB_API void Convert(timestamp_t date, date_t &out_date, dtime_t &out_time)
Extract the date and time from a given timestamp object.
Definition duckdb.cpp:129812
Here is the call graph for this function:

◆ Add() [3/4]

dtime_t duckdb::Interval::Add ( dtime_t left,
interval_t right,
date_t & date )
static

Add an interval to a time. In case the time overflows or underflows, modify the date by the overflow. For example if we go from 23:00 to 02:00, we add a day to the date

123610 {
123611 int64_t diff = right.micros - ((right.micros / Interval::MICROS_PER_DAY) * Interval::MICROS_PER_DAY);
123612 left += diff;
123613 if (left.micros >= Interval::MICROS_PER_DAY) {
123614 left.micros -= Interval::MICROS_PER_DAY;
123615 date.days++;
123616 } else if (left.micros < 0) {
123617 left.micros += Interval::MICROS_PER_DAY;
123618 date.days--;
123619 }
123620 return left;
123621}

◆ Add() [4/4]

dtime_tz_t duckdb::Interval::Add ( dtime_tz_t left,
interval_t right,
date_t & date )
static
123623 {
123624 return dtime_tz_t(Interval::Add(left.time(), right, date), left.offset());
123625}

◆ Equals()

bool duckdb::Interval::Equals ( const interval_t & left,
const interval_t & right )
inlinestatic

Comparison operators.

5326 {
5327 return left == right;
5328 }

◆ GreaterThan()

bool duckdb::Interval::GreaterThan ( const interval_t & left,
const interval_t & right )
inlinestatic
5329 {
5330 return left > right;
5331 }

The documentation for this class was generated from the following files: