Provide a means to override the default timezone in `arrow.get()`
- Dominant language
- Python
- Stars
- 9.1k
- Forks
- 784
- PR merge metrics
- No merged PRs in 30d
Description
## Feature Request
When providing a date as a string, it's often useful to be able to have it default to the local timezone but also have the ability to override it with a specific timezone. For example, writing `2025-01-01 12:34` for 12:34 PM in the local time, or `2025-01-01 12:34-0800` for 12:34 PM in the `US/Pacific` timezone.
Currently, if you parse a time with an explicit timezone but also provide a `tzinfo` parameter, the timezone will override the parsed time, for example:
```
>>> arrow.get('2025-01-01 00:00-0800',tzinfo='US/Eastern')
```
One possible workaround is to use `arrow.get` and then look at the resulting object's tzinfo, but this will fail if the time is being explicitly set to UTC:
```
>>> arrow.get('2025-01-01 00:00:00').tzinfo
datetime.timezone.utc
>>> arrow.get('2025-01-01 00:00:00+0000').tzinfo
datetime.timezone.utc
```
and I do not see any way to determine whether the timezone was specified in the string provided to `.get()`, and this information doesn't even seem to be preserved anywhere:
```
>>> arrow.get('2025-01-01 00:00:00+0000').__dict__
{'_datetime': datetime.datetime(2025, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)}
>>> arrow.get('2025-01-01 00:00:00').__dict__
{'_datetime': datetime.datetime(2025, 1, 1, 0, 0, tzinfo=datetime.timezone.utc)}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading the implementation and tests for arrow.get() parsing, especially how an explicit timezone in the input interacts with the tzinfo parameter. Reproduce the examples in the issue and determine how completion should distinguish an omitted timezone from an explicitly supplied UTC or offset timezone.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100