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::StrfTimeFormat Struct Reference
Inheritance diagram for duckdb::StrfTimeFormat:
Collaboration diagram for duckdb::StrfTimeFormat:

Public Member Functions

DUCKDB_API idx_t GetLength (date_t date, dtime_t time, int32_t utc_offset, const char *tz_name)
DUCKDB_API void FormatStringNS (date_t date, int32_t data[8], const char *tz_name, char *target) const
DUCKDB_API void FormatString (date_t date, int32_t data[8], const char *tz_name, char *target)
void FormatString (date_t date, dtime_t time, char *target)
DUCKDB_API void ConvertDateVector (Vector &input, Vector &result, idx_t count)
DUCKDB_API void ConvertTimestampVector (Vector &input, Vector &result, idx_t count)
DUCKDB_API void ConvertTimestampNSVector (Vector &input, Vector &result, idx_t count)
Public Member Functions inherited from duckdb::StrTimeFormat
bool HasFormatSpecifier (StrTimeSpecifier s) const
DUCKDB_API bool Empty () const
 If the string format is empty.

Static Public Member Functions

static DUCKDB_API string Format (timestamp_t timestamp, const string &format)
Static Public Member Functions inherited from duckdb::StrTimeFormat
static DUCKDB_API string ParseFormatSpecifier (const string &format_string, StrTimeFormat &format)

Protected Member Functions

DUCKDB_API void AddFormatSpecifier (string preceding_literal, StrTimeSpecifier specifier) override
idx_t GetLength (date_t date, int32_t data[8], const char *tz_name) const
 Returns the total length of the date formatted by this format specifier.
string_t ConvertTimestampValue (const timestamp_t &input, Vector &result) const
string_t ConvertTimestampValue (const timestamp_ns_t &input, Vector &result) const
char * WriteString (char *target, const string_t &str) const
char * Write2 (char *target, uint8_t value) const
char * WritePadded2 (char *target, uint32_t value) const
char * WritePadded3 (char *target, uint32_t value) const
char * WritePadded (char *target, uint32_t value, size_t padding) const
bool IsDateSpecifier (StrTimeSpecifier specifier)
char * WriteDateSpecifier (StrTimeSpecifier specifier, date_t date, char *target) const
char * WriteStandardSpecifier (StrTimeSpecifier specifier, int32_t data[], const char *tz_name, size_t tz_len, char *target) const
Protected Member Functions inherited from duckdb::StrTimeFormat
void AddLiteral (string literal)

Static Protected Member Functions

static idx_t GetSpecifierLength (StrTimeSpecifier specifier, date_t date, int32_t data[8], const char *tz_name)

Protected Attributes

vector< StrTimeSpecifier > var_length_specifiers
 The variable-length specifiers. To determine total string size, these need to be checked.
vector< bool > is_date_specifier
 Whether or not the current specifier is a special "date" specifier (i.e. one that requires a date_t object to generate).
Protected Attributes inherited from duckdb::StrTimeFormat
vector< StrTimeSpecifier > specifiers
 The format specifiers.
vector< string > literals
 The literals that appear in between the format specifiers The following must hold: literals.size() = specifiers.size() + 1 Format is literals[0], specifiers[0], literals[1], ..., specifiers[n - 1], literals[n].
idx_t constant_size = 0
 The constant size that appears in the format string.
vector< int > numeric_width
 The max numeric width of the specifier (if it is parsed as a number), or -1 if it is not a number.

Additional Inherited Members

Public Attributes inherited from duckdb::StrTimeFormat
string format_specifier
 The full format specifier, for error messages.

Member Function Documentation

◆ GetLength() [1/2]

idx_t duckdb::StrfTimeFormat::GetLength ( date_t date,
dtime_t time,
int32_t utc_offset,
const char * tz_name )
230354 {
230355 if (!var_length_specifiers.empty()) {
230356 int32_t data[8];
230357 Date::Convert(date, data[0], data[1], data[2]);
230358 Time::Convert(time, data[3], data[4], data[5], data[6]);
230359 data[6] *= Interval::NANOS_PER_MICRO;
230360 data[7] = utc_offset;
230361 return GetLength(date, data, tz_name);
230362 }
230363 return constant_size;
230364}
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 DUCKDB_API void Convert(dtime_t time, int32_t &out_hour, int32_t &out_min, int32_t &out_sec, int32_t &out_micros)
Extract the time from a given timestamp object.
Definition duckdb.cpp:129382
::int32_t int32_t
idx_t constant_size
The constant size that appears in the format string.
Definition duckdb.hpp:46108
vector< StrTimeSpecifier > var_length_specifiers
The variable-length specifiers. To determine total string size, these need to be checked.
Definition duckdb.hpp:46132

◆ FormatStringNS()

void duckdb::StrfTimeFormat::FormatStringNS ( date_t date,
int32_t data[8],
const char * tz_name,
char * target ) const
230621 {
230622 D_ASSERT(specifiers.size() + 1 == literals.size());
230623 idx_t i;
230624 for (i = 0; i < specifiers.size(); i++) {
230625 // first copy the current literal
230626 memcpy(target, literals[i].c_str(), literals[i].size());
230627 target += literals[i].size();
230628 // now copy the specifier
230629 if (is_date_specifier[i]) {
230630 target = WriteDateSpecifier(specifiers[i], date, target);
230631 } else {
230632 auto tz_len = tz_name ? strlen(tz_name) : 0;
230633 target = WriteStandardSpecifier(specifiers[i], data, tz_name, tz_len, target);
230634 }
230635 }
230636 // copy the final literal into the target
230637 memcpy(target, literals[i].c_str(), literals[i].size());
230638}
GOpaque< Size > size(const GMat &src)
uint64_t idx_t
a saner size_t for loop indices etc
Definition duckdb.hpp:237
vector< StrTimeSpecifier > specifiers
The format specifiers.
Definition duckdb.hpp:46102
vector< string > literals
The literals that appear in between the format specifiers The following must hold: literals....
Definition duckdb.hpp:46106
vector< bool > is_date_specifier
Whether or not the current specifier is a special "date" specifier (i.e. one that requires a date_t o...
Definition duckdb.hpp:46135

◆ FormatString() [1/2]

void duckdb::StrfTimeFormat::FormatString ( date_t date,
int32_t data[8],
const char * tz_name,
char * target )
230640 {
230641 data[6] *= Interval::NANOS_PER_MICRO;
230642 FormatStringNS(date, data, tz_name, target);
230643 data[6] /= Interval::NANOS_PER_MICRO;
230644}

◆ FormatString() [2/2]

void duckdb::StrfTimeFormat::FormatString ( date_t date,
dtime_t time,
char * target )
230646 {
230647 int32_t data[8]; // year, month, day, hour, min, sec, µs, offset
230648 Date::Convert(date, data[0], data[1], data[2]);
230649 Time::Convert(time, data[3], data[4], data[5], data[6]);
230650 data[7] = 0;
230651
230652 FormatString(date, data, nullptr, target);
230653}

◆ Format()

string duckdb::StrfTimeFormat::Format ( timestamp_t timestamp,
const string & format )
static
230655 {
230656 StrfTimeFormat format;
230657 format.ParseFormatSpecifier(format_str, format);
230658
230659 auto date = Timestamp::GetDate(timestamp);
230660 auto time = Timestamp::GetTime(timestamp);
230661
230662 auto len = format.GetLength(date, time, 0, nullptr);
230663 auto result = make_unsafe_uniq_array_uninitialized<char>(len);
230664 format.FormatString(date, time, result.get());
230665 return string(result.get(), len);
230666}
std::basic_string< Char > format(const S &format_str, Args &&... args)
Definition duckdb.cpp:16295

◆ ConvertDateVector()

void duckdb::StrfTimeFormat::ConvertDateVector ( Vector & input,
Vector & result,
idx_t count )
230855 {
230856 D_ASSERT(input.GetType().id() == LogicalTypeId::DATE);
230857 D_ASSERT(result.GetType().id() == LogicalTypeId::VARCHAR);
230858 UnaryExecutor::ExecuteWithNulls<date_t, string_t>(
230859 input, result, count, [&](date_t input, ValidityMask &mask, idx_t idx) {
230860 if (Date::IsFinite(input)) {
230861 dtime_t time(0);
230862 idx_t len = GetLength(input, time, 0, nullptr);
230863 string_t target = StringVector::EmptyString(result, len);
230864 FormatString(input, time, target.GetDataWriteable());
230865 target.Finalize();
230866 return target;
230867 } else {
230868 return StringVector::AddString(result, Date::ToString(input));
230869 }
230870 });
230871}
static bool IsFinite(date_t date)
Returns true if the specified date is finite.
Definition duckdb.hpp:5078
static DUCKDB_API string ToString(date_t date)
Convert a date object to a string in the format "YYYY-MM-DD".
Definition duckdb.cpp:117525
static DUCKDB_API string_t AddString(Vector &vector, const char *data, idx_t len)
Add a string to the string heap of the vector (auxiliary data).
Definition duckdb.cpp:137889
static DUCKDB_API string_t EmptyString(Vector &vector, idx_t len)
Definition duckdb.cpp:137942

◆ ConvertTimestampVector()

void duckdb::StrfTimeFormat::ConvertTimestampVector ( Vector & input,
Vector & result,
idx_t count )
230921 {
230922 D_ASSERT(input.GetType().id() == LogicalTypeId::TIMESTAMP || input.GetType().id() == LogicalTypeId::TIMESTAMP_TZ);
230923 D_ASSERT(result.GetType().id() == LogicalTypeId::VARCHAR);
230924 UnaryExecutor::ExecuteWithNulls<timestamp_t, string_t>(
230925 input, result, count,
230926 [&](timestamp_t input, ValidityMask &mask, idx_t idx) { return ConvertTimestampValue(input, result); });
230927}

◆ ConvertTimestampNSVector()

void duckdb::StrfTimeFormat::ConvertTimestampNSVector ( Vector & input,
Vector & result,
idx_t count )
230929 {
230930 D_ASSERT(input.GetType().id() == LogicalTypeId::TIMESTAMP_NS);
230931 D_ASSERT(result.GetType().id() == LogicalTypeId::VARCHAR);
230932 UnaryExecutor::ExecuteWithNulls<timestamp_ns_t, string_t>(
230933 input, result, count,
230934 [&](timestamp_ns_t input, ValidityMask &mask, idx_t idx) { return ConvertTimestampValue(input, result); });
230935}
@ TIMESTAMP_NS
us
Definition duckdb.hpp:2886

◆ AddFormatSpecifier()

void duckdb::StrfTimeFormat::AddFormatSpecifier ( string preceding_literal,
StrTimeSpecifier specifier )
overrideprotectedvirtual

Reimplemented from duckdb::StrTimeFormat.

230254 {
230255 is_date_specifier.push_back(IsDateSpecifier(specifier));
230256 idx_t specifier_size = StrfTimepecifierSize(specifier);
230257 if (specifier_size == 0) {
230258 // variable length specifier
230259 var_length_specifiers.push_back(specifier);
230260 } else {
230261 // constant size specifier
230262 constant_size += specifier_size;
230263 }
230264 StrTimeFormat::AddFormatSpecifier(std::move(preceding_literal), specifier);
230265}

◆ GetSpecifierLength()

idx_t duckdb::StrfTimeFormat::GetSpecifierLength ( StrTimeSpecifier specifier,
date_t date,
int32_t data[8],
const char * tz_name )
staticprotected
230268 {
230269 switch (specifier) {
230270 case StrTimeSpecifier::FULL_WEEKDAY_NAME:
230271 return Date::DAY_NAMES[Date::ExtractISODayOfTheWeek(date) % 7].GetSize();
230272 case StrTimeSpecifier::FULL_MONTH_NAME:
230273 return Date::MONTH_NAMES[data[1] - 1].GetSize();
230274 case StrTimeSpecifier::YEAR_DECIMAL: {
230275 auto year = data[0];
230276 // Be consistent with WriteStandardSpecifier
230277 if (0 <= year && year <= 9999) {
230278 return 4;
230279 } else {
230280 return UnsafeNumericCast<idx_t>(NumericHelper::SignedLength<int32_t, uint32_t>(year));
230281 }
230282 }
230283 case StrTimeSpecifier::MONTH_DECIMAL: {
230284 idx_t len = 1;
230285 auto month = data[1];
230286 len += month >= 10;
230287 return len;
230288 }
230289 case StrTimeSpecifier::UTC_OFFSET: {
230290 // ±HH or ±HH:MM or ±HH:MM:SS
230291 int hh, mm, ss;
230292 StrfTimeSplitOffset(data[7], hh, mm, ss);
230293 return ss ? 9 : (mm ? 6 : 3);
230294 }
230295 case StrTimeSpecifier::TZ_NAME:
230296 if (tz_name) {
230297 return strlen(tz_name);
230298 }
230299 // empty for now
230300 return 0;
230301 case StrTimeSpecifier::HOUR_24_DECIMAL:
230302 case StrTimeSpecifier::HOUR_12_DECIMAL:
230303 case StrTimeSpecifier::MINUTE_DECIMAL:
230304 case StrTimeSpecifier::SECOND_DECIMAL: {
230305 // time specifiers
230306 idx_t len = 1;
230307 int32_t hour = data[3], min = data[4], sec = data[5];
230308 switch (specifier) {
230309 case StrTimeSpecifier::HOUR_24_DECIMAL:
230310 len += hour >= 10;
230311 break;
230312 case StrTimeSpecifier::HOUR_12_DECIMAL:
230313 hour = hour % 12;
230314 if (hour == 0) {
230315 hour = 12;
230316 }
230317 len += hour >= 10;
230318 break;
230319 case StrTimeSpecifier::MINUTE_DECIMAL:
230320 len += min >= 10;
230321 break;
230322 case StrTimeSpecifier::SECOND_DECIMAL:
230323 len += sec >= 10;
230324 break;
230325 default:
230326 throw InternalException("Time specifier mismatch");
230327 }
230328 return len;
230329 }
230330 case StrTimeSpecifier::DAY_OF_MONTH:
230331 return UnsafeNumericCast<idx_t>(NumericHelper::UnsignedLength<uint32_t>(UnsafeNumericCast<uint32_t>(data[2])));
230332 case StrTimeSpecifier::DAY_OF_YEAR_DECIMAL:
230333 return UnsafeNumericCast<idx_t>(
230334 NumericHelper::UnsignedLength<uint32_t>(UnsafeNumericCast<uint32_t>(Date::ExtractDayOfTheYear(date))));
230335 case StrTimeSpecifier::YEAR_WITHOUT_CENTURY:
230336 return UnsafeNumericCast<idx_t>(
230337 NumericHelper::UnsignedLength<uint32_t>(UnsafeNumericCast<uint32_t>(AbsValue(data[0]) % 100)));
230338 default:
230339 throw InternalException("Unimplemented specifier for GetSpecifierLength");
230340 }
230341}
static DUCKDB_API int32_t ExtractDayOfTheYear(date_t date)
Extract the day of the year.
Definition duckdb.cpp:117645
static DUCKDB_API int32_t ExtractISODayOfTheWeek(date_t date)
Extract the day of the week (1-7).
Definition duckdb.cpp:117657
static softfloat min()

◆ GetLength() [2/2]

idx_t duckdb::StrfTimeFormat::GetLength ( date_t date,
int32_t data[8],
const char * tz_name ) const
protected

Returns the total length of the date formatted by this format specifier.

230344 {
230346 if (!var_length_specifiers.empty()) {
230347 for (auto &specifier : var_length_specifiers) {
230348 size += GetSpecifierLength(specifier, date, data, tz_name);
230349 }
230350 }
230351 return size;
230352}

◆ ConvertTimestampValue() [1/2]

string_t duckdb::StrfTimeFormat::ConvertTimestampValue ( const timestamp_t & input,
Vector & result ) const
protected
230873 {
230874 if (Timestamp::IsFinite(input)) {
230875 date_t date;
230876 dtime_t time;
230877 Timestamp::Convert(input, date, time);
230878
230879 int32_t data[8]; // year, month, day, hour, min, sec, ns, offset
230880 Date::Convert(date, data[0], data[1], data[2]);
230881 Time::Convert(time, data[3], data[4], data[5], data[6]);
230882 data[6] *= Interval::NANOS_PER_MICRO;
230883 data[7] = 0;
230884 const char *tz_name = nullptr;
230885
230886 idx_t len = GetLength(date, data, tz_name);
230887 string_t target = StringVector::EmptyString(result, len);
230888 FormatStringNS(date, data, tz_name, target.GetDataWriteable());
230889 target.Finalize();
230890 return target;
230891 } else {
230892 return StringVector::AddString(result, Timestamp::ToString(input));
230893 }
230894}
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
static DUCKDB_API string ToString(timestamp_t timestamp)
Convert a date object to a string in the format "YYYY-MM-DD hh:mm:ss".
Definition duckdb.cpp:129737
static bool IsFinite(timestamp_t timestamp)
True, if the timestamp is finite, else false.
Definition duckdb.hpp:4287

◆ ConvertTimestampValue() [2/2]

string_t duckdb::StrfTimeFormat::ConvertTimestampValue ( const timestamp_ns_t & input,
Vector & result ) const
protected
230896 {
230897 if (Timestamp::IsFinite(input)) {
230898 date_t date;
230899 dtime_t time;
230900 int32_t nanos;
230901 Timestamp::Convert(input, date, time, nanos);
230902
230903 int32_t data[8]; // year, month, day, hour, min, sec, ns, offset
230904 Date::Convert(date, data[0], data[1], data[2]);
230905 Time::Convert(time, data[3], data[4], data[5], data[6]);
230906 data[6] *= Interval::NANOS_PER_MICRO;
230907 data[6] += nanos;
230908 data[7] = 0;
230909 const char *tz_name = nullptr;
230910
230911 idx_t len = GetLength(date, data, tz_name);
230912 string_t target = StringVector::EmptyString(result, len);
230913 FormatStringNS(date, data, tz_name, target.GetDataWriteable());
230914 target.Finalize();
230915 return target;
230916 } else {
230917 return StringVector::AddString(result, Timestamp::ToString(input));
230918 }
230919}

◆ WriteString()

char * duckdb::StrfTimeFormat::WriteString ( char * target,
const string_t & str ) const
protected
230366 {
230367 idx_t size = str.GetSize();
230368 memcpy(target, str.GetData(), size);
230369 return target + size;
230370}

◆ Write2()

char * duckdb::StrfTimeFormat::Write2 ( char * target,
uint8_t value ) const
protected
230373 {
230374 D_ASSERT(value < 100);
230375 if (value >= 10) {
230376 return WritePadded2(target, value);
230377 } else {
230378 *target = char(uint8_t('0') + value);
230379 return target + 1;
230380 }
230381}
::uint8_t uint8_t

◆ WritePadded2()

char * duckdb::StrfTimeFormat::WritePadded2 ( char * target,
uint32_t value ) const
protected
230384 {
230385 D_ASSERT(value < 100);
230386 auto index = static_cast<unsigned>(value * 2);
230387 *target++ = duckdb_fmt::internal::data::digits[index];
230388 *target++ = duckdb_fmt::internal::data::digits[index + 1];
230389 return target;
230390}
index

◆ WritePadded3()

char * duckdb::StrfTimeFormat::WritePadded3 ( char * target,
uint32_t value ) const
protected
230393 {
230394 D_ASSERT(value < 1000);
230395 if (value >= 100) {
230396 WritePadded2(target + 1, value % 100);
230397 *target = char(uint8_t('0') + value / 100);
230398 return target + 3;
230399 } else {
230400 *target = '0';
230401 target++;
230402 return WritePadded2(target, value);
230403 }
230404}

◆ WritePadded()

char * duckdb::StrfTimeFormat::WritePadded ( char * target,
uint32_t value,
size_t padding ) const
protected
230407 {
230408 D_ASSERT(padding > 1);
230409 if (padding % 2) {
230410 uint32_t decimals = value % 1000u;
230411 WritePadded3(target + padding - 3, decimals);
230412 value /= 1000;
230413 padding -= 3;
230414 }
230415 for (size_t i = 0; i < padding / 2; i++) {
230416 uint32_t decimals = value % 100u;
230417 WritePadded2(target + padding - 2 * (i + 1), decimals);
230418 value /= 100;
230419 }
230420 return target + padding;
230421}
::uint32_t uint32_t

◆ IsDateSpecifier()

bool duckdb::StrfTimeFormat::IsDateSpecifier ( StrTimeSpecifier specifier)
protected
230423 {
230424 switch (specifier) {
230425 case StrTimeSpecifier::ABBREVIATED_WEEKDAY_NAME:
230426 case StrTimeSpecifier::FULL_WEEKDAY_NAME:
230427 case StrTimeSpecifier::DAY_OF_YEAR_PADDED:
230428 case StrTimeSpecifier::DAY_OF_YEAR_DECIMAL:
230429 case StrTimeSpecifier::WEEK_NUMBER_PADDED_MON_FIRST:
230430 case StrTimeSpecifier::WEEK_NUMBER_PADDED_SUN_FIRST:
230431 case StrTimeSpecifier::WEEK_NUMBER_ISO:
230432 case StrTimeSpecifier::WEEKDAY_DECIMAL:
230433 case StrTimeSpecifier::WEEKDAY_ISO:
230434 case StrTimeSpecifier::YEAR_ISO:
230435 return true;
230436 default:
230437 return false;
230438 }
230439}

◆ WriteDateSpecifier()

char * duckdb::StrfTimeFormat::WriteDateSpecifier ( StrTimeSpecifier specifier,
date_t date,
char * target ) const
protected
230441 {
230442 switch (specifier) {
230443 case StrTimeSpecifier::ABBREVIATED_WEEKDAY_NAME: {
230444 auto dow = Date::ExtractISODayOfTheWeek(date);
230445 target = WriteString(target, Date::DAY_NAMES_ABBREVIATED[dow % 7]);
230446 break;
230447 }
230448 case StrTimeSpecifier::FULL_WEEKDAY_NAME: {
230449 auto dow = Date::ExtractISODayOfTheWeek(date);
230450 target = WriteString(target, Date::DAY_NAMES[dow % 7]);
230451 break;
230452 }
230453 case StrTimeSpecifier::WEEKDAY_DECIMAL: {
230454 auto dow = Date::ExtractISODayOfTheWeek(date);
230455 *target = char('0' + uint8_t(dow % 7));
230456 target++;
230457 break;
230458 }
230459 case StrTimeSpecifier::DAY_OF_YEAR_PADDED: {
230461 target = WritePadded3(target, UnsafeNumericCast<uint32_t>(doy));
230462 break;
230463 }
230464 case StrTimeSpecifier::WEEK_NUMBER_PADDED_MON_FIRST:
230465 target = WritePadded2(target, UnsafeNumericCast<uint32_t>(Date::ExtractWeekNumberRegular(date, true)));
230466 break;
230467 case StrTimeSpecifier::WEEK_NUMBER_PADDED_SUN_FIRST:
230468 target = WritePadded2(target, UnsafeNumericCast<uint32_t>(Date::ExtractWeekNumberRegular(date, false)));
230469 break;
230470 case StrTimeSpecifier::WEEK_NUMBER_ISO:
230471 target = WritePadded2(target, UnsafeNumericCast<uint32_t>(Date::ExtractISOWeekNumber(date)));
230472 break;
230473 case StrTimeSpecifier::DAY_OF_YEAR_DECIMAL: {
230474 auto doy = UnsafeNumericCast<uint32_t>(Date::ExtractDayOfTheYear(date));
230475 target += NumericHelper::UnsignedLength<uint32_t>(doy);
230476 NumericHelper::FormatUnsigned(doy, target);
230477 break;
230478 }
230479 case StrTimeSpecifier::YEAR_ISO:
230480 target = WritePadded(target, UnsafeNumericCast<uint32_t>(Date::ExtractISOYearNumber(date)), 4);
230481 break;
230482 case StrTimeSpecifier::WEEKDAY_ISO:
230483 *target = char('0' + uint8_t(Date::ExtractISODayOfTheWeek(date)));
230484 target++;
230485 break;
230486 default:
230487 throw InternalException("Unimplemented date specifier for strftime");
230488 }
230489 return target;
230490}
static DUCKDB_API int32_t ExtractWeekNumberRegular(date_t date, bool monday_first=true)
Definition duckdb.cpp:117742

◆ WriteStandardSpecifier()

char * duckdb::StrfTimeFormat::WriteStandardSpecifier ( StrTimeSpecifier specifier,
int32_t data[],
const char * tz_name,
size_t tz_len,
char * target ) const
protected
230493 {
230494 // data contains [0] year, [1] month, [2] day, [3] hour, [4] minute, [5] second, [6] ns, [7] utc (secs)
230495 switch (specifier) {
230496 case StrTimeSpecifier::DAY_OF_MONTH_PADDED:
230497 target = WritePadded2(target, UnsafeNumericCast<uint32_t>(data[2]));
230498 break;
230499 case StrTimeSpecifier::ABBREVIATED_MONTH_NAME: {
230500 auto &month_name = Date::MONTH_NAMES_ABBREVIATED[data[1] - 1];
230501 return WriteString(target, month_name);
230502 }
230503 case StrTimeSpecifier::FULL_MONTH_NAME: {
230504 auto &month_name = Date::MONTH_NAMES[data[1] - 1];
230505 return WriteString(target, month_name);
230506 }
230507 case StrTimeSpecifier::MONTH_DECIMAL_PADDED:
230508 target = WritePadded2(target, UnsafeNumericCast<uint32_t>(data[1]));
230509 break;
230510 case StrTimeSpecifier::YEAR_WITHOUT_CENTURY_PADDED:
230511 target = WritePadded2(target, UnsafeNumericCast<uint32_t>(AbsValue(data[0]) % 100));
230512 break;
230513 case StrTimeSpecifier::YEAR_DECIMAL:
230514 if (data[0] >= 0 && data[0] <= 9999) {
230515 target = WritePadded(target, UnsafeNumericCast<uint32_t>(data[0]), 4);
230516 } else {
230517 int32_t year = data[0];
230518 if (data[0] < 0) {
230519 *target = '-';
230520 year = -year;
230521 target++;
230522 }
230523 auto len = NumericHelper::UnsignedLength<uint32_t>(UnsafeNumericCast<uint32_t>(year));
230524 NumericHelper::FormatUnsigned(year, target + len);
230525 target += len;
230526 }
230527 break;
230528 case StrTimeSpecifier::HOUR_24_PADDED: {
230529 target = WritePadded2(target, UnsafeNumericCast<uint32_t>(data[3]));
230530 break;
230531 }
230532 case StrTimeSpecifier::HOUR_12_PADDED: {
230533 int hour = data[3] % 12;
230534 if (hour == 0) {
230535 hour = 12;
230536 }
230537 target = WritePadded2(target, UnsafeNumericCast<uint32_t>(hour));
230538 break;
230539 }
230540 case StrTimeSpecifier::AM_PM:
230541 *target++ = data[3] >= 12 ? 'P' : 'A';
230542 *target++ = 'M';
230543 break;
230544 case StrTimeSpecifier::MINUTE_PADDED: {
230545 target = WritePadded2(target, UnsafeNumericCast<uint32_t>(data[4]));
230546 break;
230547 }
230548 case StrTimeSpecifier::SECOND_PADDED:
230549 target = WritePadded2(target, UnsafeNumericCast<uint32_t>(data[5]));
230550 break;
230551 case StrTimeSpecifier::NANOSECOND_PADDED:
230552 target = WritePadded(target, UnsafeNumericCast<uint32_t>(data[6]), 9);
230553 break;
230554 case StrTimeSpecifier::MICROSECOND_PADDED:
230555 target = WritePadded(target, UnsafeNumericCast<uint32_t>(data[6] / Interval::NANOS_PER_MICRO), 6);
230556 break;
230557 case StrTimeSpecifier::MILLISECOND_PADDED:
230558 target = WritePadded3(target, UnsafeNumericCast<uint32_t>(data[6] / Interval::NANOS_PER_MSEC));
230559 break;
230560 case StrTimeSpecifier::UTC_OFFSET: {
230561 *target++ = (data[7] < 0) ? '-' : '+';
230562
230563 auto offset = abs(data[7]);
230564 int hh, mm, ss;
230565 StrfTimeSplitOffset(offset, hh, mm, ss);
230566 target = WritePadded2(target, UnsafeNumericCast<uint32_t>(hh));
230567 if (mm || ss) {
230568 *target++ = ':';
230569 target = WritePadded2(target, UnsafeNumericCast<uint32_t>(mm));
230570 }
230571 if (ss) {
230572 *target++ = ':';
230573 target = WritePadded2(target, UnsafeNumericCast<uint32_t>(ss));
230574 }
230575 break;
230576 }
230577 case StrTimeSpecifier::TZ_NAME:
230578 if (tz_name) {
230579 memcpy(target, tz_name, tz_len);
230580 target += strlen(tz_name);
230581 }
230582 break;
230583 case StrTimeSpecifier::DAY_OF_MONTH: {
230584 target = Write2(target, UnsafeNumericCast<uint8_t>(data[2] % 100));
230585 break;
230586 }
230587 case StrTimeSpecifier::MONTH_DECIMAL: {
230588 target = Write2(target, UnsafeNumericCast<uint8_t>(data[1]));
230589 break;
230590 }
230591 case StrTimeSpecifier::YEAR_WITHOUT_CENTURY: {
230592 target = Write2(target, UnsafeNumericCast<uint8_t>(AbsValue(data[0]) % 100));
230593 break;
230594 }
230595 case StrTimeSpecifier::HOUR_24_DECIMAL: {
230596 target = Write2(target, UnsafeNumericCast<uint8_t>(data[3]));
230597 break;
230598 }
230599 case StrTimeSpecifier::HOUR_12_DECIMAL: {
230600 int hour = data[3] % 12;
230601 if (hour == 0) {
230602 hour = 12;
230603 }
230604 target = Write2(target, UnsafeNumericCast<uint8_t>(hour));
230605 break;
230606 }
230607 case StrTimeSpecifier::MINUTE_DECIMAL: {
230608 target = Write2(target, UnsafeNumericCast<uint8_t>(data[4]));
230609 break;
230610 }
230611 case StrTimeSpecifier::SECOND_DECIMAL: {
230612 target = Write2(target, UnsafeNumericCast<uint8_t>(data[5]));
230613 break;
230614 }
230615 default:
230616 throw InternalException("Unimplemented specifier for WriteStandardSpecifier in strftime");
230617 }
230618 return target;
230619}
__device__ __forceinline__ uchar1 abs(const uchar1 &a)

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