Comments (4)
I am unsure what the intended behavior would be here as 9999 is an odd input year. I can take on this - but could someone verify the intended behavior here?
from arrow.
some system stored the timestamp of 9999 to mark the data will never be expired, and the passed date like 2022 means has expired γAnd the BI System need to show as datetime like of 9999γso i need find a way to resolve it.
On linux, the datetime.fromtimestamp can do this correctly, but , this function will raise error on windows when the datetime over 2038. So I am finding a way to hanle this problem both run well on Linux and Window. At least, the arrow can transform 9999 to timestamp correctly.
By the way, the arrow can only tranform timestamp of 2999-12-31 to the correct datetime, timestamp of 3001 will be 1971 either.
from arrow.
@funicia Have you solved this bug? If so can you share how you done it
from arrow.
@yiransii Just in case you would still want to work on this one, the root cause for this is not year 9999 being invalid, but there's a rather obscure bug.
When you construct an Arrow object from a timestamp, it calls normalize_timestamp from util.py. The first few lines:
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
MAX_TIMESTAMP is from constants.py:
try:
# Get max timestamp. Works on POSIX-based systems like Linux and macOS,
# but will trigger an OverflowError, ValueError, or OSError on Windows
_MAX_TIMESTAMP = datetime.max.timestamp()
except (OverflowError, ValueError, OSError): # pragma: no cover
# Fallback for Windows and 32-bit systems if initial max timestamp call fails
What happens is that despite the comment, datetime.max.timestamp() only works on Linux if the local timezone is UTC or UTC-xx:
$ TZ=UTC python3
>>> from datetime import datetime
>>> datetime.max.timestamp()
253402300800.0
$ TZ=Europe/Berlin python3
>>> from datetime import datetime
>>> datetime.max.timestamp()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: year 10000 is out of range
Going back to normalize_timestamp, this means 253402214400 gets divided by 1000, which then matches the original bug report:
>>> arrow.get(253402214.4)
<Arrow [1978-01-11T21:30:14.400000+00:00]>
from arrow.
Related Issues (20)
- passing a parameter to Arrow.shift function (to check for imaginary times or not)
- Fuzzing arrow on OSS-Fuzz HOT 1
- Arrow.humanize() thinks past date is in the future HOT 3
- The dehumanize method doesn't recognize singular nouns HOT 5
- Cannot append nullable string columns to table
- Timezone in multiples of 4. HOT 1
- incorrect tzinfo when arrow.get() HOT 4
- 'arrow' has no attribute 'utcnow' HOT 1
- .humanize() should have a numeric option for 1 instead of a/an HOT 3
- arrow 1.2.3 doesn't run under Python 3.11 HOT 3
- Missing hour during DST long day when shifting or calculating ranges HOT 3
- No docs on values in format string for Arrow.format() HOT 2
- Use `typing.Self` to support subclassing
- Don't force requirement on types-python-dateutil HOT 4
- incorrect behavior WRT daylight savings for shift/adding timedelta
- 1.3.0: pytest fails in multiple units HOT 2
- RFE: use `zoneinfo` instead of `pytz` HOT 1
- datetime.utcnow is deprecated HOT 1
- span_range returns unexpected result (missing days) when using frame month
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from arrow.