Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
7000e9e0
Kaydet (Commit)
7000e9e0
authored
May 09, 2010
tarafından
Mark Dickinson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #8644: Improve accuracy of timedelta.total_seconds method.
(Backport of r80979 to py3k.) Thanks Alexander Belopolsky.
üst
860852fd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
6 deletions
+35
-6
datetime.rst
Doc/library/datetime.rst
+6
-2
test_datetime.py
Lib/test/test_datetime.py
+8
-1
NEWS
Misc/NEWS
+2
-0
datetimemodule.c
Modules/datetimemodule.c
+19
-3
No files found.
Doc/library/datetime.rst
Dosyayı görüntüle @
7000e9e0
...
...
@@ -270,8 +270,12 @@ Instance methods:
.. method:: timedelta.total_seconds()
Return the total number of seconds contained in the duration. Equivalent to
``td.microseconds / 1000000 + td.seconds + td.days * 24 * 3600``.
Return the total number of seconds contained in the duration.
Equivalent to ``(td.microseconds + (td.seconds + td.days * 24 *
3600) * 10**6) / 10**6`` computed with true division enabled.
Note that for very large time intervals (greater than 270 years on
most platforms) this method will lose microsecond accuracy.
.. versionadded:: 2.7
...
...
Lib/test/test_datetime.py
Dosyayı görüntüle @
7000e9e0
...
...
@@ -2,7 +2,7 @@
See http://www.zope.org/Members/fdrake/DateTimeWiki/TestCases
"""
from
__future__
import
division
import
os
import
pickle
import
cPickle
...
...
@@ -269,6 +269,13 @@ class TestTimeDelta(HarmlessMixedComparison, unittest.TestCase):
for
total_seconds
in
[
123456.789012
,
-
123456.789012
,
0.123456
,
0
,
1e6
]:
td
=
timedelta
(
seconds
=
total_seconds
)
self
.
assertEqual
(
td
.
total_seconds
(),
total_seconds
)
# Issue8644: Test that td.total_seconds() has the same
# accuracy as td / timedelta(seconds=1).
for
ms
in
[
-
1
,
-
2
,
-
123
]:
td
=
timedelta
(
microseconds
=
ms
)
self
.
assertEqual
(
td
.
total_seconds
(),
((
24
*
3600
*
td
.
days
+
td
.
seconds
)
*
10
**
6
+
td
.
microseconds
)
/
10
**
6
)
def
test_carries
(
self
):
t1
=
timedelta
(
days
=
100
,
...
...
Misc/NEWS
Dosyayı görüntüle @
7000e9e0
...
...
@@ -200,6 +200,8 @@ Library
Extension Modules
-----------------
- Issue #8644: Improved accuracy of timedelta.total_seconds().
- Use Clang 2.7's static analyzer to find places to clean up some code.
- Build the ossaudio extension on GNU/kFreeBSD.
...
...
Modules/datetimemodule.c
Dosyayı görüntüle @
7000e9e0
...
...
@@ -2096,9 +2096,25 @@ delta_getstate(PyDateTime_Delta *self)
static
PyObject
*
delta_total_seconds
(
PyObject
*
self
)
{
return
PyFloat_FromDouble
(
GET_TD_MICROSECONDS
(
self
)
/
1000000
.
0
+
GET_TD_SECONDS
(
self
)
+
GET_TD_DAYS
(
self
)
*
24
.
0
*
3600
.
0
);
PyObject
*
total_seconds
;
PyObject
*
total_microseconds
;
PyObject
*
one_million
;
total_microseconds
=
delta_to_microseconds
((
PyDateTime_Delta
*
)
self
);
if
(
total_microseconds
==
NULL
)
return
NULL
;
one_million
=
PyLong_FromLong
(
1000000L
);
if
(
one_million
==
NULL
)
{
Py_DECREF
(
total_microseconds
);
return
NULL
;
}
total_seconds
=
PyNumber_TrueDivide
(
total_microseconds
,
one_million
);
Py_DECREF
(
total_microseconds
);
Py_DECREF
(
one_million
);
return
total_seconds
;
}
static
PyObject
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment