Day of the week as number 'd' does not format back to day of the week
- Dominant language
- Python
- Stars
- 9.1k
- Forks
- 784
- PR merge metrics
- No merged PRs in 30d
Description
## Issue Description
When formatting from a date as an integer, it does not always translate correctly.
example code:
```py
#!/usr/bin/env python3
import arrow
d = '3'
d2 = '198911'
wkday = arrow.get(d, 'd')
wkday2 = arrow.get(d2, 'YYYYMD')
print(f'sample 1 Fetched date short, (date should be a Wednesday): {wkday}')
print(f'sample 2 Fetched date long (date should be a Sunday): {wkday2}')
wkday = wkday.format('dddd')
wkday2 = wkday2.format('d')
print(f'sample 1 Formatted long (should be the word Wednesday): {wkday}')
print(f'sample 2 Formatted short (should be 7 for Sunday): {wkday2}')
wkday2 = wkday2.format('dddd')
print(f'sample 2 Formatted long (should be the word Sunday): {wkday2}')
```
example output:
```
sample 1 Fetched date short, (date should be a Wednesday): 0001-01-01T00:00:00+00:00
sample 2 Fetched date long (date should be a Sunday): 1989-01-01T00:00:00+00:00
sample 1 Formatted long (should be the word Wednesday): Monday
sample 2 Formatted short (should be 7 for Sunday): 7
sample 2 Formatted long (should be the word Sunday): 7
```
**Sample 1: Single digit input**
As you can see, when using arrow.get to fetch day of the week as an integer, no matter what number you give it, it instead grabs the date of 0001-01-01 which is a Sunday, but then more confusingly, it formats 0001-01-01 as a Monday, so I assume it's just seeing 1, even though it was originally fed a 3.
**Sample 2: Valid date input**
While you can convert a valid date to day of the week then again down to a number 1-7 Mon-Sun, you cannot then convert back from a number to a day of the week again.
## System Info
- 🖥 **OS name and version**: Manjaro, Kernel: 5.14.18-1-MANJARO
- 🐍 **Python version**: Python 3.9.7
- 🏹 **Arrow version**: 1.2.1
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the two examples using arrow.get() and format(), comparing the expected weekday values with the reported output. Trace the date parsing and weekday formatting entry points, then add regression coverage showing that numeric weekday values round-trip correctly and that the examples produce the stated Wednesday and Sunday results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100