arrow-py / arrow-py/arrow

Add support for negative timestamps on Windows (before the epoch)

Open
#675 3 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
9.1k
Forks
784
PR merge metrics
No merged PRs in 30d

Description

Currently, on Windows, you get the following error if you pass a negative timestamp:

```shell
(arrow) C:\Users\Chris>python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import arrow
>>> arrow.get(-15675657)
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\Chris\arrow\lib\site-packages\arrow\api.py", line 21, in get
return _factory.get(*args, **kwargs)
File "C:\Users\Chris\arrow\lib\site-packages\arrow\factory.py", line 155, in get
return self.type.utcfromtimestamp(arg)
File "C:\Users\Chris\arrow\lib\site-packages\arrow\arrow.py", line 166, in utcfromtimestamp
dt = datetime.utcfromtimestamp(timestamp)
OSError: [Errno 22] Invalid argument
```

This occurs on all versions of Arrow on Windows and seems to be due to limitations of the `fromtimestamp` and `utcfromtimestamp` methods in the datetime library on Windows.

This functionality works fine on Linux and MacOS:

```shell
venv ❯ python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 16:52:21)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import arrow
>>> import time
>>> arrow.get(time.time())

>>> arrow.get(time.time() * -1)

```

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the failure on Windows with the negative timestamp shown in the issue, then inspect arrow/arrow.py around utcfromtimestamp and the api.py and factory.py call path from the traceback. Done means arrow.get(-15675657) works on Windows without the reported OSError while existing timestamp behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.