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
4a19b20f
Commit
4a19b20f
authored
Jun 14, 2010
by
Alexander Belopolsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue 6280: Tests and simpler implementation for calendar.timegm
parent
ea1228ef
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
10 deletions
+13
-10
Lib/calendar.py
Lib/calendar.py
+3
-8
Lib/test/test_calendar.py
Lib/test/test_calendar.py
+10
-2
No files found.
Lib/calendar.py
View file @
4a19b20f
...
@@ -587,17 +587,12 @@ def formatstring(cols, colwidth=_colwidth, spacing=_spacing):
...
@@ -587,17 +587,12 @@ def formatstring(cols, colwidth=_colwidth, spacing=_spacing):
EPOCH
=
1970
EPOCH
=
1970
_EPOCH_
ORD
=
datetime
.
date
(
EPOCH
,
1
,
1
).
toordinal
(
)
_EPOCH_
DATETIME
=
datetime
.
datetime
(
EPOCH
,
1
,
1
)
_SECOND
=
datetime
.
timedelta
(
seconds
=
1
)
def
timegm
(
tuple
):
def
timegm
(
tuple
):
"""Unrelated but handy function to calculate Unix timestamp from GMT."""
"""Unrelated but handy function to calculate Unix timestamp from GMT."""
year
,
month
,
day
,
hour
,
minute
,
second
=
tuple
[:
6
]
return
(
datetime
.
datetime
(
*
tuple
[:
6
])
-
_EPOCH_DATETIME
)
//
_SECOND
days
=
datetime
.
date
(
year
,
month
,
1
).
toordinal
()
-
_EPOCH_ORD
+
day
-
1
hours
=
days
*
24
+
hour
minutes
=
hours
*
60
+
minute
seconds
=
minutes
*
60
+
second
return
seconds
def
main
(
args
):
def
main
(
args
):
...
...
Lib/test/test_calendar.py
View file @
4a19b20f
...
@@ -2,7 +2,7 @@ import calendar
...
@@ -2,7 +2,7 @@ import calendar
import
unittest
import
unittest
from
test
import
support
from
test
import
support
import
time
result_2004_text
=
"""
result_2004_text
=
"""
2004
2004
...
@@ -381,13 +381,21 @@ class SundayTestCase(MonthCalendarTestCase):
...
@@ -381,13 +381,21 @@ class SundayTestCase(MonthCalendarTestCase):
# A 31-day december starting on friday (2+7+7+7+7+1 days)
# A 31-day december starting on friday (2+7+7+7+7+1 days)
self
.
check_weeks
(
1995
,
12
,
(
2
,
7
,
7
,
7
,
7
,
1
))
self
.
check_weeks
(
1995
,
12
,
(
2
,
7
,
7
,
7
,
7
,
1
))
class
TimegmTestCase
(
unittest
.
TestCase
):
TIMESTAMPS
=
[
0
,
10
,
100
,
1000
,
10000
,
100000
,
1000000
,
1234567890
,
1262304000
,
1275785153
,]
def
test_timegm
(
self
):
for
secs
in
self
.
TIMESTAMPS
:
tuple
=
time
.
gmtime
(
secs
)
self
.
assertEqual
(
secs
,
calendar
.
timegm
(
tuple
))
def
test_main
():
def
test_main
():
support
.
run_unittest
(
support
.
run_unittest
(
OutputTestCase
,
OutputTestCase
,
CalendarTestCase
,
CalendarTestCase
,
MondayTestCase
,
MondayTestCase
,
SundayTestCase
SundayTestCase
,
TimegmTestCase
,
)
)
...
...
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