robotframework: DateTime suffers from "Year 2038" problem with epoch conversion on 32 bit systems

Problem

The datetime library is not able to convert timestamp in far future (Dec 31 14:10:36 2040 GMT) to epoch timestamp (integer) on 32 bit systems (like raspberry pi).

Example:

Convert Date    Dec 31 14:10:36 2040 GMT    date_format=%b %d %H:%M:%S %Y %Z    result_format=epoch

Raises

OverflowError: mktime argument out of range

This is caused by https://github.com/robotframework/robotframework/blob/208b8988254af37867d487682604f6e1229a3cf0/src/robot/libraries/DateTime.py#L576

not handling timestamp over 32 bit integers well.

environment

  • 32 bit raspberry pi 3
  • python 3.7.3
  • 3.2.1

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 26 (19 by maintainers)

Commits related to this issue

Most upvoted comments

I can.

I guess you are referring to commit id ebbcd9580d1a1a34a048e6dbb2fdd14e274b23e9 (the link was broken).

I have installed the version by creating a new python virtual env and installing the robotframework with:

python3 -m venv .venv
source .venv/bin/activate
pip3 install git+https://github.com/robotframework/robotframework.git@ebbcd9580d1a1a34a048e6dbb2fdd14e274b23e9

And run a test case with:

*** Settings ***
Library    DateTime

***Variables***
${date1}=    Dec 31 14:10:36 2040 GMT

***Test Cases***
2040
    Log To Console    \n${date1}
    ${epoch}=    Convert Date    ${date1}    date_format=%b %d %H:%M:%S %Y %Z    result_format=epoch
    Should Be Equal As Integers    ${epoch}    2240575836    Was not what https://www.epochconverter.com/ says. It should be 2240575836

And got:

==============================================================================
Testcase                                                                      
==============================================================================
2040                                                                  
Dec 31 14:10:36 2040 GMT
2040                                                                  | FAIL |
OverflowError: timestamp out of range for platform time_t
------------------------------------------------------------------------------
Testcase                                                              | FAIL |
1 test, 0 passed, 1 failed
==============================================================================
Output:  /tmp/test/output.xml
Log:     /tmp/test/log.html
Report:  /tmp/test/report.html

I tried to convert a datetime to integer with year>2040:

>>> import datetime
>>> d=datetime.datetime(2040, 12, 20, 8, 19, 3, 224927)
>>> d.timestamp()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: timestamp out of range for platform time_t

I think this is relevant bug in python datetime library: https://github.com/python/cpython/issues/101069


Version info:

$ python3 --version
Python 3.9.2
$ uname -a
Linux <redacted> 5.15.61-v7+ #1578 SMP Wed Aug 24 11:46:41 BST 2022 armv7l GNU/Linux
$ cat /etc/os-release 
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

Was run with raspberry pi 3B

Already tested that DST causes problems. This is a better workaround:

try:
    return time.mktime(dt.timetuple()) + dt.microsecond / 1e6 
except OverflowError:
    ok = dt.replace(year=2037)
    return time.mktime(ok.timetuple()) + ok.microsecond / 1e6 + (dt - ok).total_seconds()