Formats an interval to a buffer, the buffer should be >=70 characters years: 17 characters (max value: "-2147483647 years") months: 9 (max value: "12 months") days: 16 characters (max value: "-2147483647 days") time: 24 characters (max value: -2562047788:00:00.123456) spaces between all characters (+3 characters) Total: 70 characters Returns the length of the interval
20059 {
20060 idx_t length = 0;
20061 if (interval.months != 0) {
20062 int32_t years = interval.months / 12;
20063 int32_t months = interval.months - years * 12;
20064
20065 FormatIntervalValue(years, buffer, length, " year", 5);
20066 FormatIntervalValue(months, buffer, length, " month", 6);
20067 }
20068 if (interval.days != 0) {
20069
20070 FormatIntervalValue(interval.days, buffer, length, " day", 4);
20071 }
20072 if (interval.micros != 0) {
20073 if (length != 0) {
20074
20075 buffer[length++] = ' ';
20076 }
20077 int64_t micros = interval.micros;
20078 if (micros < 0) {
20079
20080 buffer[length++] = '-';
20081 } else {
20082 micros = -micros;
20083 }
20084 int64_t hour = -(micros / Interval::MICROS_PER_HOUR);
20085 micros += hour * Interval::MICROS_PER_HOUR;
20086 int64_t min = -(micros / Interval::MICROS_PER_MINUTE);
20087 micros +=
min * Interval::MICROS_PER_MINUTE;
20088 int64_t sec = -(micros / Interval::MICROS_PER_SEC);
20089 micros += sec * Interval::MICROS_PER_SEC;
20090 micros = -micros;
20091
20092 if (hour < 10) {
20093 buffer[length++] = '0';
20094 }
20095 FormatSignedNumber(hour, buffer, length);
20096 buffer[length++] = ':';
20097 FormatTwoDigits(
min, buffer, length);
20098 buffer[length++] = ':';
20099 FormatTwoDigits(sec, buffer, length);
20100 if (micros != 0) {
20101 buffer[length++] = '.';
20103 length += NumericCast<idx_t>(6 - trailing_zeros);
20104 }
20105 } else if (length == 0) {
20106
20107 memcpy(buffer, "00:00:00", 8);
20108 return 8;
20109 }
20110 return length;
20111 }
static int32_t FormatMicros(int32_t microseconds, char micro_buffer[])
Format microseconds to a buffer of length 6. Returns the number of trailing zeros.
Definition duckdb.cpp:19945