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
e5c6a6fa
Commit
e5c6a6fa
authored
Jan 02, 2003
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
astimezone() internals: if utcoffset() returns a duration, complain if
dst() returns None (instead of treating that as 0).
parent
1d98443b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
14 deletions
+45
-14
Doc/lib/libdatetime.tex
Doc/lib/libdatetime.tex
+19
-13
Lib/test/test_datetime.py
Lib/test/test_datetime.py
+17
-0
Misc/NEWS
Misc/NEWS
+4
-0
Modules/datetimemodule.c
Modules/datetimemodule.c
+5
-1
No files found.
Doc/lib/libdatetime.tex
View file @
e5c6a6fa
...
@@ -893,21 +893,14 @@ implement all of them.
...
@@ -893,21 +893,14 @@ implement all of them.
return CONSTANT # fixed-offset class
return CONSTANT # fixed-offset class
return CONSTANT + self.dst(dt) # daylight-aware class
return CONSTANT + self.dst(dt) # daylight-aware class
\end{verbatim}
\end{verbatim}
\end{methoddesc}
\begin{methoddesc}
{
tzname
}{
self, dt
}
If
\method
{
utcoffset()
}
does not return
\code
{
None
}
,
Return the timezone name corresponding to the
\class
{
datetime
}
represented
\method
{
dst()
}
should not return
\code
{
None
}
either.
by
\var
{
dt
}
, as a string. Nothing about string names is defined by the
\module
{
datetime
}
module, and there's no requirement that it mean anything
in particular. For example, "GMT", "UTC", "-500", "-5:00", "EDT",
"US/Eastern", "America/New York" are all valid replies. Return
\code
{
None
}
if a string name isn't known. Note that this is a method
rather than a fixed string primarily because some
\class
{
tzinfo
}
objects
will wish to return different names depending on the specific value
of
\var
{
dt
}
passed, especially if the
\class
{
tzinfo
}
class is
accounting for daylight time.
\end{methoddesc}
\end{methoddesc}
\begin{methoddesc}
{
dst
}{
self, dt
}
\begin{methoddesc}
{
dst
}{
self, dt
}
Return the daylight savings time (DST) adjustment, in minutes east of
Return the daylight savings time (DST) adjustment, in minutes east of
UTC, or
\code
{
None
}
if DST information isn't known. Return
\code
{
0
}
if
UTC, or
\code
{
None
}
if DST information isn't known. Return
\code
{
0
}
if
...
@@ -937,6 +930,19 @@ implement all of them.
...
@@ -937,6 +930,19 @@ implement all of them.
but cannot detect violations; it's the programmer's responsibility to
but cannot detect violations; it's the programmer's responsibility to
ensure it.
ensure it.
\begin{methoddesc}
{
tzname
}{
self, dt
}
Return the timezone name corresponding to the
\class
{
datetime
}
represented
by
\var
{
dt
}
, as a string. Nothing about string names is defined by the
\module
{
datetime
}
module, and there's no requirement that it mean anything
in particular. For example, "GMT", "UTC", "-500", "-5:00", "EDT",
"US/Eastern", "America/New York" are all valid replies. Return
\code
{
None
}
if a string name isn't known. Note that this is a method
rather than a fixed string primarily because some
\class
{
tzinfo
}
objects
will wish to return different names depending on the specific value
of
\var
{
dt
}
passed, especially if the
\class
{
tzinfo
}
class is
accounting for daylight time.
\end{methoddesc}
\end{methoddesc}
\end{methoddesc}
These methods are called by a
\class
{
datetimetz
}
or
\class
{
timetz
}
object,
These methods are called by a
\class
{
datetimetz
}
or
\class
{
timetz
}
object,
...
@@ -1379,7 +1385,7 @@ Instance methods:
...
@@ -1379,7 +1385,7 @@ Instance methods:
\begin{verbatim}
\begin{verbatim}
>>> from datetime import *
>>> from datetime import *
>>> class TZ(tzinfo):
>>> class TZ(tzinfo):
... def utcoffset(self, dt): return
-399
... def utcoffset(self, dt): return
timedelta(minutes=-399)
...
...
>>> datetimetz(2002, 12, 25, tzinfo=TZ()).isoformat(' ')
>>> datetimetz(2002, 12, 25, tzinfo=TZ()).isoformat(' ')
'2002-12-25 00:00:00-06:39'
'2002-12-25 00:00:00-06:39'
...
...
Lib/test/test_datetime.py
View file @
e5c6a6fa
...
@@ -2591,6 +2591,8 @@ class TestTimezoneConversions(unittest.TestCase):
...
@@ -2591,6 +2591,8 @@ class TestTimezoneConversions(unittest.TestCase):
dston
=
datetimetz
(
2002
,
4
,
7
,
2
)
dston
=
datetimetz
(
2002
,
4
,
7
,
2
)
dstoff
=
datetimetz
(
2002
,
10
,
27
,
2
)
dstoff
=
datetimetz
(
2002
,
10
,
27
,
2
)
theclass
=
datetimetz
# Check a time that's inside DST.
# Check a time that's inside DST.
def
checkinside
(
self
,
dt
,
tz
,
utc
,
dston
,
dstoff
):
def
checkinside
(
self
,
dt
,
tz
,
utc
,
dston
,
dstoff
):
self
.
assertEqual
(
dt
.
dst
(),
HOUR
)
self
.
assertEqual
(
dt
.
dst
(),
HOUR
)
...
@@ -2729,6 +2731,21 @@ class TestTimezoneConversions(unittest.TestCase):
...
@@ -2729,6 +2731,21 @@ class TestTimezoneConversions(unittest.TestCase):
got
=
sixutc
.
astimezone
(
Eastern
).
astimezone
(
None
)
got
=
sixutc
.
astimezone
(
Eastern
).
astimezone
(
None
)
self
.
assertEqual
(
expected
,
got
)
self
.
assertEqual
(
expected
,
got
)
def
test_bogus_dst
(
self
):
class
ok
(
tzinfo
):
def
utcoffset
(
self
,
dt
):
return
HOUR
def
dst
(
self
,
dt
):
return
HOUR
now
=
self
.
theclass
.
now
().
replace
(
tzinfo
=
utc_real
)
# Doesn't blow up.
now
.
astimezone
(
ok
())
# Does blow up.
class
notok
(
ok
):
def
dst
(
self
,
dt
):
return
None
self
.
assertRaises
(
ValueError
,
now
.
astimezone
,
notok
())
def
test_suite
():
def
test_suite
():
allsuites
=
[
unittest
.
makeSuite
(
klass
,
'test'
)
allsuites
=
[
unittest
.
makeSuite
(
klass
,
'test'
)
for
klass
in
(
TestModule
,
for
klass
in
(
TestModule
,
...
...
Misc/NEWS
View file @
e5c6a6fa
...
@@ -22,6 +22,10 @@ Extension modules
...
@@ -22,6 +22,10 @@ Extension modules
today() and now() now round system timestamps to the closest
today() and now() now round system timestamps to the closest
microsecond <http://www.python.org/sf/661086>.
microsecond <http://www.python.org/sf/661086>.
In dt.asdatetime(tz), if tz.utcoffset(dt) returns a duration,
ValueError is raised of tz.dst(dt) returns None (2.3a1 treated it
as 0 instead).
Library
Library
-------
-------
...
...
Modules/datetimemodule.c
View file @
e5c6a6fa
...
@@ -4805,7 +4805,11 @@ datetimetz_astimezone(PyDateTime_DateTimeTZ *self, PyObject *args,
...
@@ -4805,7 +4805,11 @@ datetimetz_astimezone(PyDateTime_DateTimeTZ *self, PyObject *args,
resdst
=
call_dst
(
tzinfo
,
result
,
&
none
);
resdst
=
call_dst
(
tzinfo
,
result
,
&
none
);
if
(
resdst
==
-
1
&&
PyErr_Occurred
())
if
(
resdst
==
-
1
&&
PyErr_Occurred
())
goto
Fail
;
goto
Fail
;
/* None and 0 dst() results are the same to us here. Debatable. */
if
(
none
)
{
PyErr_SetString
(
PyExc_ValueError
,
"astimezone(): utcoffset() "
"returned a duration but dst() returned None"
);
goto
Fail
;
}
total_added_to_result
=
resoff
-
resdst
-
selfoff
;
total_added_to_result
=
resoff
-
resdst
-
selfoff
;
if
(
total_added_to_result
!=
0
)
{
if
(
total_added_to_result
!=
0
)
{
mm
+=
total_added_to_result
;
mm
+=
total_added_to_result
;
...
...
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