MAX_TIMESTAMP calculation error
- Dominant language
- Python
- Stars
- 9.1k
- Forks
- 784
- PR merge metrics
- No merged PRs in 30d
Description
## Issue Description
There are some issues related to the way max values are handled (partially because of how python's datetime works) :
The way how Arrow calculates the max timestamp constant value also fails on Linux in **constants.py** :
`_MAX_TIMESTAMP = datetime.max.timestamp()`
Which will raise a ValueError in non-utc timezones (timestamp() ) will try to return a timestamp in the local timezone):
`ValueError: year 10000 is out of range`
Therefore I suggest making this more robust and replacing this with :
`datetime.max.replace(tzinfo=timezone.utc).timestamp()`
Which is more in line with python documentation : https://docs.python.org/3/library/datetime.html#datetime.datetime.timestamp
Using `Arrow.max` has its own issues , as
`Arrow.utcfromtimestamp(Arrow.max.float_timestamp)`
does not behave as expected and returns a date in 1978, due to `normalize_timestamp` (util) division by 1000 :
```python
def normalize_timestamp(timestamp: float) -> float:
"""Normalize millisecond and microsecond timestamps into normal timestamps."""
if timestamp > MAX_TIMESTAMP:
if timestamp < MAX_TIMESTAMP_MS:
timestamp /= 1000
elif timestamp < MAX_TIMESTAMP_US:
timestamp /= 1_000_000
else:
raise ValueError(f"The specified timestamp {timestamp!r} is too large.")
return timestamp
```
## System Info
- 🖥 **OS name and version**: Debian 11
- 🐍 **Python version**: 3.9.2
- 🏹 **Arrow version**: 1.2.2
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in constants.py with the _MAX_TIMESTAMP calculation, then inspect normalize_timestamp in util and the Arrow.max.float_timestamp path. Reproduce the failure in a non-UTC timezone and check Arrow.utcfromtimestamp(Arrow.max.float_timestamp). Done means the maximum timestamp is handled consistently without the timezone error or unexpected 1978 result.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100