[issue46856] datetime.max conversion

2022-03-01 Thread Joris Geysens


Joris Geysens  added the comment:

I looked at this a bit more in detail.
What happens it the following, starting in the datetime fromtimestamp fragment :

converter = _time.gmtime if utc else _time.localtime
y, m, d, hh, mm, ss, weekday, jday, dst = converter(t)

That will call the system gmtime_r(), which indeed returns Sat Jan  1 00:00:00 
1

I have not looked at the cpp implementation for that method and I am not sure 
if this is something that can be improved.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46856] datetime.max conversion

2022-02-25 Thread Eric V. Smith


Eric V. Smith  added the comment:

Probably so. You could step through the code to make sure that's what's going 
on.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46856] datetime.max conversion

2022-02-25 Thread Joris Geysens


Joris Geysens  added the comment:

I see this in the python source code being tested (datetimetester.py), so I 
guess it is a rounding problem : 

# maximum timestamp: set seconds to zero to avoid rounding issues
max_dt = self.theclass.max.replace(tzinfo=timezone.utc,
   second=0, microsecond=0)
max_ts = max_dt.timestamp()
# date -12-31 23:59:00+00:00: timestamp 253402300740
self.assertEqual(self.theclass.fromtimestamp(max_ts, tz=timezone.utc),
 max_dt)

--
components: +Library (Lib)

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46856] datetime.max conversion

2022-02-25 Thread Joris Geysens


Joris Geysens  added the comment:

a ValueError is raised : 

ValueError: year 1 is out of range 

on 

dt = datetime.fromtimestamp(ts, tz=timezone.utc)

or 

dt = datetime.utcfromtimestamp(ts)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46856] datetime.max conversion

2022-02-25 Thread Eric V. Smith


Eric V. Smith  added the comment:

Please show us how they fail.

--
nosy: +eric.smith

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue46856] datetime.max conversion

2022-02-25 Thread Joris Geysens


New submission from Joris Geysens :

Reading the documentation, I don't understand how this is not possible : 

# get the max utc timestamp
ts = datetime.max.replace(tzinfo=timezone.utc).timestamp()

# similarly 
ts2 = datetime(, 12, 31, 23, 59, 59, 99, 
tzinfo=timezone.utc).timestamp()

# timestamp value 253402300800 seems correct
# converting back to timestamp is impossible, these all fail : 

dt = datetime.fromtimestamp(ts, tz=timezone.utc)
dt = datetime.utcfromtimestamp(ts)

It should be possible to get a datetime back from the initially converted 
timestamp, no?

--
messages: 414013
nosy: joris.geysens
priority: normal
severity: normal
status: open
title: datetime.max conversion
type: behavior
versions: Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com