Repository: duckdb/duckdb (language: python)

Issue:
`strptime` returns incorrect timestamp when reading year before day of year
### What happens?

When using `strptime` to read timestamps, if the timestamp string (and consequently the format string) has the year before the day of year, the resulting timestamp object will be incorrect and entirely disregard the day of year.

If the year appears after the day of year number, the resulting timestamp is correct.

### To Reproduce

The following two SQL queries in the `duckdb` CLI minimally reproduce the issue:

#### Correct timestamp returned 
```sql
select strptime('100 2024', '%j %Y');
```

#### Incorrect timestamp returned
```sql
select strptime('2024 100', '%Y %j');
```

### OS:

macOS 14.7, aarch64

### DuckDB Version:

v1.1.2

### DuckDB Client:

CLI

### Hardware:

_No response_

### Full Name:

Luke Johnson

### Affiliation:

NASA

### What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a nightly build

### Did you include all relevant data sets for reproducing the issue?

Not applicable - the reproduction does not require a data set

### Did you include all code required to reproduce the issue?

- [X] Yes, I have

### Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

- [X] Yes, I have


Discussion / hints:

Fix patch:
diff --git a/src/function/scalar/strftime_format.cpp b/src/function/scalar/strftime_format.cpp
index 3525519a9dbb..8ab46ace7058 100644
--- a/src/function/scalar/strftime_format.cpp
+++ b/src/function/scalar/strftime_format.cpp
@@ -1185,8 +1185,7 @@ bool StrpTimeFormat::Parse(const char *data, size_t size, ParseResult &result, b
 				case StrTimeSpecifier::YEAR_WITHOUT_CENTURY_PADDED:
 				case StrTimeSpecifier::YEAR_WITHOUT_CENTURY:
 				case StrTimeSpecifier::YEAR_DECIMAL:
-					// Part of the offset
-					break;
+					// Switch to offset parsing
 				case StrTimeSpecifier::WEEKDAY_DECIMAL:
 					// First offset specifier
 					offset_specifier = specifiers[i];


Test patch:
diff --git a/test/sql/function/timestamp/test_strptime.test b/test/sql/function/timestamp/test_strptime.test
index 9be03a0310d9..3d87089fbb87 100644
--- a/test/sql/function/timestamp/test_strptime.test
+++ b/test/sql/function/timestamp/test_strptime.test
@@ -144,6 +144,16 @@ SELECT strptime('30', '%j'), strftime('1900-01-30'::DATE, '%-j')
 ----
 1900-01-30 00:00:00	30
 
+query I
+select strptime('100 2024', '%j %Y');
+----
+2024-04-09 00:00:00
+
+query I
+select strptime('2024 100', '%Y %j');
+----
+2024-04-09 00:00:00
+
 # day of year AND month
 query I
 SELECT strptime('1992-01-30 30', '%Y-%m-%d %j')