Skip to content

Commit

Permalink
Issue duckdb#9869: Strptime Week Start
Browse files Browse the repository at this point in the history
Missing file from commit.
  • Loading branch information
hawkfish committed Dec 4, 2023
1 parent ac9d73a commit 2dcecdc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/function/scalar/strftime_format.cpp
Expand Up @@ -770,6 +770,7 @@ bool StrpTimeFormat::Parse(string_t str, ParseResult &result) const {
uint64_t weekno = 0;
uint64_t weekday = 0;
uint64_t yearday = 0;
bool has_weekday = false;

for (idx_t i = 0;; i++) {
D_ASSERT(i < literals.size());
Expand Down Expand Up @@ -947,6 +948,7 @@ bool StrpTimeFormat::Parse(string_t str, ParseResult &result) const {
error_position = start_pos;
return false;
}
has_weekday = true;
weekday = number;
break;
case StrTimeSpecifier::DAY_OF_YEAR_PADDED:
Expand Down Expand Up @@ -1110,7 +1112,9 @@ bool StrpTimeFormat::Parse(string_t str, ParseResult &result) const {
case StrTimeSpecifier::WEEK_NUMBER_PADDED_SUN_FIRST:
case StrTimeSpecifier::WEEK_NUMBER_PADDED_MON_FIRST: {
// Adjust weekday to be 0-based for the week type
weekday = (weekday + 7 - int(offset_specifier == StrTimeSpecifier::WEEK_NUMBER_PADDED_MON_FIRST)) % 7;
if (has_weekday) {
weekday = (weekday + 7 - int(offset_specifier == StrTimeSpecifier::WEEK_NUMBER_PADDED_MON_FIRST)) % 7;
}
// Get the start of week 1, move back 7 days and then weekno * 7 + weekday gives the date
const auto jan1 = Date::FromDate(result_data[0], 1, 1);
auto yeardate = Date::GetMondayOfCurrentWeek(jan1);
Expand Down

0 comments on commit 2dcecdc

Please sign in to comment.