77
88#include <time.h>
99
10- #include "_time.h"
11-
1210/* Differentiate between building the core module and building extension
1311 * modules.
1412 */
@@ -2441,15 +2439,15 @@ date_new(PyTypeObject *type, PyObject *args, PyObject *kw)
24412439
24422440/* Return new date from localtime(t). */
24432441static PyObject *
2444- date_local_from_time_t (PyObject * cls , double ts )
2442+ date_local_from_object (PyObject * cls , PyObject * obj )
24452443{
24462444 struct tm * tm ;
24472445 time_t t ;
24482446 PyObject * result = NULL ;
24492447
2450- t = _PyTime_DoubleToTimet (ts );
2451- if (t == (time_t )- 1 && PyErr_Occurred ())
2448+ if (_PyTime_ObjectToTime_t (obj , & t ) == -1 )
24522449 return NULL ;
2450+
24532451 tm = localtime (& t );
24542452 if (tm )
24552453 result = PyObject_CallFunction (cls , "iii" ,
@@ -2494,11 +2492,11 @@ date_today(PyObject *cls, PyObject *dummy)
24942492static PyObject *
24952493date_fromtimestamp (PyObject * cls , PyObject * args )
24962494{
2497- double timestamp ;
2495+ PyObject * timestamp ;
24982496 PyObject * result = NULL ;
24992497
2500- if (PyArg_ParseTuple (args , "d :fromtimestamp" , & timestamp ))
2501- result = date_local_from_time_t (cls , timestamp );
2498+ if (PyArg_ParseTuple (args , "O :fromtimestamp" , & timestamp ))
2499+ result = date_local_from_object (cls , timestamp );
25022500 return result ;
25032501}
25042502
@@ -4096,31 +4094,14 @@ datetime_from_timet_and_us(PyObject *cls, TM_FUNC f, time_t timet, int us,
40964094 * to get that much precision (e.g., C time() isn't good enough).
40974095 */
40984096static PyObject *
4099- datetime_from_timestamp (PyObject * cls , TM_FUNC f , double timestamp ,
4097+ datetime_from_timestamp (PyObject * cls , TM_FUNC f , PyObject * timestamp ,
41004098 PyObject * tzinfo )
41014099{
41024100 time_t timet ;
4103- double fraction ;
4104- int us ;
4101+ long us ;
41054102
4106- timet = _PyTime_DoubleToTimet (timestamp );
4107- if (timet == (time_t )- 1 && PyErr_Occurred ())
4103+ if (_PyTime_ObjectToTimeval (timestamp , & timet , & us ) == -1 )
41084104 return NULL ;
4109- fraction = timestamp - (double )timet ;
4110- us = (int )round_to_long (fraction * 1e6 );
4111- if (us < 0 ) {
4112- /* Truncation towards zero is not what we wanted
4113- for negative numbers (Python's mod semantics) */
4114- timet -= 1 ;
4115- us += 1000000 ;
4116- }
4117- /* If timestamp is less than one microsecond smaller than a
4118- * full second, round up. Otherwise, ValueErrors are raised
4119- * for some floats. */
4120- if (us == 1000000 ) {
4121- timet += 1 ;
4122- us = 0 ;
4123- }
41244105 return datetime_from_timet_and_us (cls , f , timet , us , tzinfo );
41254106}
41264107
@@ -4181,11 +4162,11 @@ static PyObject *
41814162datetime_fromtimestamp (PyObject * cls , PyObject * args , PyObject * kw )
41824163{
41834164 PyObject * self ;
4184- double timestamp ;
4165+ PyObject * timestamp ;
41854166 PyObject * tzinfo = Py_None ;
41864167 static char * keywords [] = {"timestamp" , "tz" , NULL };
41874168
4188- if (! PyArg_ParseTupleAndKeywords (args , kw , "d |O:fromtimestamp" ,
4169+ if (! PyArg_ParseTupleAndKeywords (args , kw , "O |O:fromtimestamp" ,
41894170 keywords , & timestamp , & tzinfo ))
41904171 return NULL ;
41914172 if (check_tzinfo_subclass (tzinfo ) < 0 )
@@ -4210,10 +4191,10 @@ datetime_fromtimestamp(PyObject *cls, PyObject *args, PyObject *kw)
42104191static PyObject *
42114192datetime_utcfromtimestamp (PyObject * cls , PyObject * args )
42124193{
4213- double timestamp ;
4194+ PyObject * timestamp ;
42144195 PyObject * result = NULL ;
42154196
4216- if (PyArg_ParseTuple (args , "d :utcfromtimestamp" , & timestamp ))
4197+ if (PyArg_ParseTuple (args , "O :utcfromtimestamp" , & timestamp ))
42174198 result = datetime_from_timestamp (cls , gmtime , timestamp ,
42184199 Py_None );
42194200 return result ;
0 commit comments