Giter VIP home page Giter VIP logo

Comments (4)

yiransii avatar yiransii commented on September 18, 2024

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.

funicia avatar funicia commented on September 18, 2024

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.

sanskark avatar sanskark commented on September 18, 2024

@funicia Have you solved this bug? If so can you share how you done it

from arrow.

tonyk232 avatar tonyk232 commented on September 18, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.