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
0af3ade6
Kaydet (Commit)
0af3ade6
authored
Ock 13, 2005
tarafından
Skip Montanaro
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add strptime() constructor to datetime class. Thanks to Josh Spoerri for
the changes.
üst
2f8c6589
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
0 deletions
+66
-0
libdatetime.tex
Doc/lib/libdatetime.tex
+9
-0
test_datetime.py
Lib/test/test_datetime.py
+9
-0
ACKS
Misc/ACKS
+1
-0
NEWS
Misc/NEWS
+2
-0
datetimemodule.c
Modules/datetimemodule.c
+45
-0
No files found.
Doc/lib/libdatetime.tex
Dosyayı görüntüle @
0af3ade6
...
...
@@ -624,6 +624,15 @@ Other constructors, all class methods:
ignored.
\end{methoddesc}
\begin{methoddesc}
{
strptime
}{
date
_
string, format
}
Return a
\class
{
datetime
}
corresponding to
\var
{
date
_
string
}
, parsed
according to
\var
{
format
}
. This is equivalent to
\code
{
datetime(*(time.strptime(date
_
string,
format)[0:6]))
}
.
\exception
{
ValueError
}
is raised if the date
_
string and
format can't be parsed by
\function
{
time.strptime()
}
or if it returns a
value which isn't a time tuple.
\end{methoddesc}
Class attributes:
\begin{memberdesc}
{
min
}
...
...
Lib/test/test_datetime.py
Dosyayı görüntüle @
0af3ade6
...
...
@@ -1421,6 +1421,15 @@ class TestDateTime(TestDate):
# Else try again a few times.
self
.
failUnless
(
abs
(
from_timestamp
-
from_now
)
<=
tolerance
)
def
test_strptime
(
self
):
import
time
string
=
'2004-12-01 13:02:47'
format
=
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
expected
=
self
.
theclass
(
*
(
time
.
strptime
(
string
,
format
)[
0
:
6
]))
got
=
self
.
theclass
.
strptime
(
string
,
format
)
self
.
assertEqual
(
expected
,
got
)
def
test_more_timetuple
(
self
):
# This tests fields beyond those tested by the TestDate.test_timetuple.
t
=
self
.
theclass
(
2004
,
12
,
31
,
6
,
22
,
33
)
...
...
Misc/ACKS
Dosyayı görüntüle @
0af3ade6
...
...
@@ -548,6 +548,7 @@ Dirk Soede
Paul Sokolovsky
Clay Spence
Per Spilling
Joshua Spoerri
Noah Spurrier
Oliver Steele
Greg Stein
...
...
Misc/NEWS
Dosyayı görüntüle @
0af3ade6
...
...
@@ -31,6 +31,8 @@ Extension Modules
This allows islice() to work more readily with slices:
islice(s.start, s.stop, s.step)
- datetime.datetime() now has a strptime class method which can be used to
create datetime object using a string and format.
Library
-------
...
...
Modules/datetimemodule.c
Dosyayı görüntüle @
0af3ade6
...
...
@@ -3798,6 +3798,46 @@ datetime_utcfromtimestamp(PyObject *cls, PyObject *args)
return
result
;
}
/* Return new datetime from time.strptime(). */
static
PyObject
*
datetime_strptime
(
PyObject
*
cls
,
PyObject
*
args
)
{
PyObject
*
result
=
NULL
,
*
obj
,
*
module
;
const
char
*
string
,
*
format
;
if
(
!
PyArg_ParseTuple
(
args
,
"ss:strptime"
,
&
string
,
&
format
))
return
NULL
;
if
((
module
=
PyImport_ImportModule
(
"time"
))
==
NULL
)
return
NULL
;
obj
=
PyObject_CallMethod
(
module
,
"strptime"
,
"ss"
,
string
,
format
);
Py_DECREF
(
module
);
if
(
obj
!=
NULL
)
{
int
i
,
good_timetuple
=
1
;
long
int
ia
[
6
];
if
(
PySequence_Check
(
obj
)
&&
PySequence_Size
(
obj
)
>=
6
)
for
(
i
=
0
;
i
<
6
;
i
++
)
{
PyObject
*
p
=
PySequence_GetItem
(
obj
,
i
);
if
(
PyInt_Check
(
p
))
ia
[
i
]
=
PyInt_AsLong
(
p
);
else
good_timetuple
=
0
;
Py_DECREF
(
p
);
}
else
good_timetuple
=
0
;
if
(
good_timetuple
)
result
=
PyObject_CallFunction
(
cls
,
"iiiiii"
,
ia
[
0
],
ia
[
1
],
ia
[
2
],
ia
[
3
],
ia
[
4
],
ia
[
5
]);
else
PyErr_SetString
(
PyExc_ValueError
,
"unexpected value from time.strptime"
);
Py_DECREF
(
obj
);
}
return
result
;
}
/* Return new datetime from date/datetime and time arguments. */
static
PyObject
*
datetime_combine
(
PyObject
*
cls
,
PyObject
*
args
,
PyObject
*
kw
)
...
...
@@ -4419,6 +4459,11 @@ static PyMethodDef datetime_methods[] = {
PyDoc_STR
(
"timestamp -> UTC datetime from a POSIX timestamp "
"(like time.time())."
)},
{
"strptime"
,
(
PyCFunction
)
datetime_strptime
,
METH_VARARGS
|
METH_CLASS
,
PyDoc_STR
(
"string, format -> new datetime parsed from a string "
"(like time.strptime())."
)},
{
"combine"
,
(
PyCFunction
)
datetime_combine
,
METH_VARARGS
|
METH_KEYWORDS
|
METH_CLASS
,
PyDoc_STR
(
"date, time -> datetime with same date and time fields"
)},
...
...
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