HuyaneMatsu / hata

Async Discord API wrapper.
https://www.astil.dev/project/hata/
Other
181 stars 20 forks source link

[Bug] Timestamp? #66

Closed LrnzDC3696 closed 2 years ago

LrnzDC3696 commented 2 years ago

Description

Traceback (most recent call last):
  File "/storage/emulated/0/Codes/yametechs/dbot/main.py", line 1, in <module>                                             import hata
  File "/data/data/com.termux/files/home/.local/share/virtualenvs/dbot-OSOAGk4U/lib/python3.10/site-packages/hata/__init__.py", line 110, in <module>                                                                                             from .discord import *                                                                                               File "/data/data/com.termux/files/home/.local/share/virtualenvs/dbot-OSOAGk4U/lib/python3.10/site-packages/hata/discord/__init__.py", line 1, in <module>                                                                                       from .activity import *                                                                                             File "/data/data/com.termux/files/home/.local/share/virtualenvs/dbot-OSOAGk4U/lib/python3.10/site-packages/hata/discord/activity/__init__.py", line 3, in <module>                                                                              from .activity_base import *                                                                                         File "/data/data/com.termux/files/home/.local/share/virtualenvs/dbot-OSOAGk4U/lib/python3.10/site-packages/hata/discord/activity/activity_base.py", line 8, in <module>                                                                         from ..utils import DATETIME_FORMAT_CODE, DISCORD_EPOCH_START, datetime_to_unix_time, unix_time_to_datetime          File "/data/data/com.termux/files/home/.local/share/virtualenvs/dbot-OSOAGk4U/lib/python3.10/site-packages/hata/discord/utils.py", line 331, in <module>                                                                                        UNIX_TIME_MAX = datetime_to_unix_time(DATETIME_MAX)                                                                  File "/data/data/com.termux/files/home/.local/share/virtualenvs/dbot-OSOAGk4U/lib/python3.10/site-packages/hata/discord/utils.py", line 299, in datetime_to_unix_time                                                                           return floor(date_time.timestamp() * 1000.0)                                                                       OverflowError: timestamp out of range for platform time_t```

### Reproduction Steps

pipenv install hata
python
>> import hata

### Reproduction Code

```python
import hata

Expected behaviour

imports hata

Actual behaviour

errors

System information

Can't run... it errors

HuyaneMatsu commented 2 years ago

Since it is a platform specific python issue and not hata one, I need your system information.

LrnzDC3696 commented 2 years ago

What system information exactly?

HuyaneMatsu commented 2 years ago

Operation system CPU Python version Python implementation Hata version

And whatever else you might find useful

WizzyGeek commented 2 years ago

Seems like the platform they are on (probably android+arm) uses 32 bit time_t whose max value is somewhere around 2038 from epoch.

Here is a relevant stackoverflow thread which is related

https://stackoverflow.com/a/50860754

Apparently getting the platform independent timestamp has been described as "difficult" with no clear solution.

And a not-so-related but interesting article https://en.m.wikipedia.org/wiki/Year_2038_problem

HuyaneMatsu commented 2 years ago

I was expecting that they use 32 bit int for time. Tho as expected python is still not enforcing 64 bit int still.

I met datetime issues before, since I might receive high unix time, timestamp and snowflake values and their conversion to datetime fails. Linux and Windows also has different limits.

Pretty stupid python behavior, not gonna lie.

WizzyGeek commented 2 years ago

Tho as expected python is still not enforcing 64 bit int still.

Nothing they can do about time_t being 32 bit on a platform.

The only sane workaround I see right now is to switch to 32 bit max on overflow seems like a reasonable solution that would work till 2038

Or, you can implement binary search to find the max timestamp

HuyaneMatsu commented 2 years ago

Nothing they can do about time_t being 32 bit on a platform.

They can convert it to 64 bit.

LrnzDC3696 commented 2 years ago

Sorry for late reply but here...

It's weird because on a device (Android) it works fine but on another one it doesn't...

Operation system: Android 10 armv7l CPU: Unisoc SC9832e (4) @ 1.400GHz Python version: 3.10.1 Python implementation: CPython Hata version: Latest

LrnzDC3696 commented 2 years ago

The "Other" devices:

Operation system: Android 8.1.0 aarch CPU: MT6765 (8) @ 2.301 Python version: 3.10.0 Python implementation: CPython Hata version: Latest

HuyaneMatsu commented 2 years ago

Will be fixed next update.

LrnzDC3696 commented 2 years ago

Ok! oh and just please notify me here when the next update has been released because I'm not in the discord. Yeetn't when?

HuyaneMatsu commented 2 years ago

The next update is here.