Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
b8bb4664
Commit
b8bb4664
authored
Jan 08, 2011
by
Alexander Belopolsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #1777412: extended year range of strftime down to 1000.
parent
9253214f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
15 deletions
+15
-15
Lib/datetime.py
Lib/datetime.py
+4
-4
Lib/test/datetimetester.py
Lib/test/datetimetester.py
+3
-3
Modules/_datetimemodule.c
Modules/_datetimemodule.c
+6
-6
Modules/timemodule.c
Modules/timemodule.c
+2
-2
No files found.
Lib/datetime.py
View file @
b8bb4664
...
@@ -173,9 +173,9 @@ def _format_time(hh, mm, ss, us):
...
@@ -173,9 +173,9 @@ def _format_time(hh, mm, ss, us):
# Correctly substitute for %z and %Z escapes in strftime formats.
# Correctly substitute for %z and %Z escapes in strftime formats.
def
_wrap_strftime
(
object
,
format
,
timetuple
):
def
_wrap_strftime
(
object
,
format
,
timetuple
):
year
=
timetuple
[
0
]
year
=
timetuple
[
0
]
if
year
<
1
9
00
:
if
year
<
1
0
00
:
raise
ValueError
(
"year=%d is before 1
9
00; the datetime strftime() "
raise
ValueError
(
"year=%d is before 1
0
00; the datetime strftime() "
"methods require year >= 1
9
00"
%
year
)
"methods require year >= 1
0
00"
%
year
)
# Don't call utcoffset() or tzname() unless actually needed.
# Don't call utcoffset() or tzname() unless actually needed.
freplace
=
None
# the string to use for %f
freplace
=
None
# the string to use for %f
zreplace
=
None
# the string to use for %z
zreplace
=
None
# the string to use for %z
...
@@ -1189,7 +1189,7 @@ class time:
...
@@ -1189,7 +1189,7 @@ class time:
"""Format using strftime(). The date part of the timestamp passed
"""Format using strftime(). The date part of the timestamp passed
to underlying strftime should not be used.
to underlying strftime should not be used.
"""
"""
# The year must be >= 1
9
00 else Python's strftime implementation
# The year must be >= 1
0
00 else Python's strftime implementation
# can raise a bogus exception.
# can raise a bogus exception.
timetuple
=
(
1900
,
1
,
1
,
timetuple
=
(
1900
,
1
,
1
,
self
.
_hour
,
self
.
_minute
,
self
.
_second
,
self
.
_hour
,
self
.
_minute
,
self
.
_second
,
...
...
Lib/test/datetimetester.py
View file @
b8bb4664
...
@@ -1284,10 +1284,10 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase):
...
@@ -1284,10 +1284,10 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase):
self
.
assertTrue
(
self
.
theclass
.
max
)
self
.
assertTrue
(
self
.
theclass
.
max
)
def
test_strftime_out_of_range
(
self
):
def
test_strftime_out_of_range
(
self
):
# For nasty technical reasons, we can't handle years before 1
9
00.
# For nasty technical reasons, we can't handle years before 1
0
00.
cls
=
self
.
theclass
cls
=
self
.
theclass
self
.
assertEqual
(
cls
(
1
900
,
1
,
1
).
strftime
(
"%Y"
),
"19
00"
)
self
.
assertEqual
(
cls
(
1
000
,
1
,
1
).
strftime
(
"%Y"
),
"10
00"
)
for
y
in
1
,
49
,
51
,
99
,
100
,
1000
,
18
99
:
for
y
in
1
,
49
,
51
,
99
,
100
,
9
99
:
self
.
assertRaises
(
ValueError
,
cls
(
y
,
1
,
1
).
strftime
,
"%Y"
)
self
.
assertRaises
(
ValueError
,
cls
(
y
,
1
,
1
).
strftime
,
"%Y"
)
def
test_replace
(
self
):
def
test_replace
(
self
):
...
...
Modules/_datetimemodule.c
View file @
b8bb4664
...
@@ -1166,10 +1166,10 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
...
@@ -1166,10 +1166,10 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
if
(
!
pin
)
if
(
!
pin
)
return
NULL
;
return
NULL
;
/* Give up if the year is before 1
9
00.
/* Give up if the year is before 1
0
00.
* Python strftime() plays games with the year, and different
* Python strftime() plays games with the year, and different
* games depending on whether envar PYTHON2K is set. This makes
* games depending on whether envar PYTHON2K is set. This makes
* years before 1
9
00 a nightmare, even if the platform strftime
* years before 1
0
00 a nightmare, even if the platform strftime
* supports them (and not all do).
* supports them (and not all do).
* We could get a lot farther here by avoiding Python's strftime
* We could get a lot farther here by avoiding Python's strftime
* wrapper and calling the C strftime() directly, but that isn't
* wrapper and calling the C strftime() directly, but that isn't
...
@@ -1182,10 +1182,10 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
...
@@ -1182,10 +1182,10 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
assert
(
PyLong_Check
(
pyyear
));
assert
(
PyLong_Check
(
pyyear
));
year
=
PyLong_AsLong
(
pyyear
);
year
=
PyLong_AsLong
(
pyyear
);
Py_DECREF
(
pyyear
);
Py_DECREF
(
pyyear
);
if
(
year
<
1
9
00
)
{
if
(
year
<
1
0
00
)
{
PyErr_Format
(
PyExc_ValueError
,
"year=%ld is before "
PyErr_Format
(
PyExc_ValueError
,
"year=%ld is before "
"1
9
00; the datetime strftime() "
"1
0
00; the datetime strftime() "
"methods require year >= 1
9
00"
,
"methods require year >= 1
0
00"
,
year
);
year
);
return
NULL
;
return
NULL
;
}
}
...
@@ -3663,7 +3663,7 @@ time_strftime(PyDateTime_Time *self, PyObject *args, PyObject *kw)
...
@@ -3663,7 +3663,7 @@ time_strftime(PyDateTime_Time *self, PyObject *args, PyObject *kw)
/* Python's strftime does insane things with the year part of the
/* Python's strftime does insane things with the year part of the
* timetuple. The year is forced to (the otherwise nonsensical)
* timetuple. The year is forced to (the otherwise nonsensical)
* 1900 to wor
m
around that.
* 1900 to wor
k
around that.
*/
*/
tuple
=
Py_BuildValue
(
"iiiiiiiii"
,
tuple
=
Py_BuildValue
(
"iiiiiiiii"
,
1900
,
1
,
1
,
/* year, month, day */
1900
,
1
,
1
,
/* year, month, day */
...
...
Modules/timemodule.c
View file @
b8bb4664
...
@@ -471,9 +471,9 @@ time_strftime(PyObject *self, PyObject *args)
...
@@ -471,9 +471,9 @@ time_strftime(PyObject *self, PyObject *args)
return
NULL
;
return
NULL
;
/* XXX: Reportedly, some systems have issues formating dates prior to year
/* XXX: Reportedly, some systems have issues formating dates prior to year
* 1
9
00. These systems should be identified and this check should be
* 1
0
00. These systems should be identified and this check should be
* moved to appropriate system specific section below. */
* moved to appropriate system specific section below. */
if
(
buf
.
tm_year
<
0
)
{
if
(
buf
.
tm_year
<
-
90
0
)
{
PyErr_Format
(
PyExc_ValueError
,
"year=%d is before 1900; "
PyErr_Format
(
PyExc_ValueError
,
"year=%d is before 1900; "
"the strftime() method requires year >= 1900"
,
"the strftime() method requires year >= 1900"
,
buf
.
tm_year
+
1900
);
buf
.
tm_year
+
1900
);
...
...
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