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
8827d0c3
Commit
8827d0c3
authored
Jan 03, 2003
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replaced the flawed "local time" example tzinfo class with the guts
of Guido's later Local.py (from the datetime sandbox).
parent
6f2bb236
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
13 deletions
+39
-13
Doc/lib/tzinfo-examples.py
Doc/lib/tzinfo-examples.py
+39
-13
No files found.
Doc/lib/tzinfo-examples.py
View file @
8827d0c3
...
...
@@ -2,6 +2,8 @@ from datetime import tzinfo, timedelta
ZERO
=
timedelta
(
0
)
# A UTC class.
class
UTC
(
tzinfo
):
"""UTC"""
...
...
@@ -14,11 +16,17 @@ class UTC(tzinfo):
def
dst
(
self
,
dt
):
return
ZERO
utc
=
UTC
()
# A class building tzinfo objects for fixed-offset time zones.
# Note that FixedOffset(0, "UTC") is a different way to build a
# UTC tzinfo object.
class
FixedOffset
(
tzinfo
):
"""Fixed offset in minutes east from UTC."""
def
__init__
(
self
,
offset
,
name
):
self
.
__offset
=
offset
self
.
__offset
=
timdelta
(
minutes
=
offset
)
self
.
__name
=
name
def
utcoffset
(
self
,
dt
):
...
...
@@ -30,23 +38,41 @@ class FixedOffset(tzinfo):
def
dst
(
self
,
dt
):
return
ZERO
import
time
# A class capturing the platform's idea of local time.
class
LocalTime
(
tzinfo
):
"""Local time as defined by the operating system."""
import
time
as
_time
def
_isdst
(
self
,
dt
):
t
=
(
dt
.
year
,
dt
.
month
,
dt
.
day
,
dt
.
hour
,
dt
.
minute
,
dt
.
second
,
-
1
,
-
1
,
-
1
)
# XXX This may fail for years < 1970 or >= 2038
t
=
time
.
localtime
(
time
.
mktime
(
t
))
return
t
.
tm_isdst
>
0
STDOFFSET
=
timedelta
(
seconds
=
-
_time
.
timezone
)
if
_time
.
daylight
:
DSTOFFSET
=
timedelta
(
seconds
=
-
_time
.
altzone
)
else
:
DSTOFFSET
=
STDOFFSET
DSTDIFF
=
DSTOFFSET
-
STDOFFSET
class
LocalTimezone
(
tzinfo
):
def
utcoffset
(
self
,
dt
):
if
self
.
_isdst
(
dt
):
return
timedelta
(
seconds
=-
time
.
timezone
)
return
DSTOFFSET
else
:
return
timedelta
(
seconds
=-
time
.
altzone
)
return
STDOFFSET
def
dst
(
self
,
dt
):
if
self
.
_isdst
(
dt
):
return
DSTDIFF
else
:
return
ZERO
def
tzname
(
self
,
dt
):
return
time
.
tzname
[
self
.
_isdst
(
dt
)]
return
_time
.
tzname
[
self
.
_isdst
(
dt
)]
def
_isdst
(
self
,
dt
):
tt
=
(
dt
.
year
,
dt
.
month
,
dt
.
day
,
dt
.
hour
,
dt
.
minute
,
dt
.
second
,
dt
.
weekday
(),
0
,
-
1
)
stamp
=
_time
.
mktime
(
tt
)
tt
=
_time
.
localtime
(
stamp
)
return
tt
.
tm_isdst
>
0
Local
=
LocalTimezone
()
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