arrow icon indicating copy to clipboard operation
arrow copied to clipboard

Day of the week as number 'd' does not format back to day of the week

Open Swizzler121 opened this issue 3 years ago • 2 comments

Issue Description

When formatting from a date as an integer, it does not always translate correctly.

example code:

#!/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

Swizzler121 avatar Dec 04 '21 03:12 Swizzler121

Ran the example code on my windows system just to show it's not one particular environment:

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

System Info

  • 🖥 OS name and version: Windows 10 Version 21H1 (OS Build 19043.1348)
  • 🐍 Python version: Python 3.10.0
  • 🏹 Arrow version: 1.2.1

Swizzler121 avatar Dec 04 '21 15:12 Swizzler121

Hey @Swizzler121 when I try your second example I get the following result.

>>> dt=arrow.get('198911', 'YYYYMD')
>>> dt
<Arrow [1989-01-01T00:00:00+00:00]>
>>> dt.format("d")
'7'
>>> dt.format("dddd")
'Sunday'

I think wkday2 is being overridden at some point.

For the first example I can see the bug, @jadchaar I think we worked on this at one point?

systemcatch avatar Dec 13 '21 18:12 systemcatch