Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
3197d275
Commit
3197d275
authored
Oct 15, 2002
by
Lennart Regebro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for collector issue #411. DateTime.rfc822() is not rfc2822 compliant.
parent
42ea9a15
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
26 deletions
+39
-26
lib/python/DateTime/DateTime.py
lib/python/DateTime/DateTime.py
+13
-4
lib/python/DateTime/tests/testDateTime.py
lib/python/DateTime/tests/testDateTime.py
+26
-22
No files found.
lib/python/DateTime/DateTime.py
View file @
3197d275
...
...
@@ -12,13 +12,12 @@
##############################################################################
"""Encapsulation of date/time values"""
__version__
=
'$Revision: 1.
79
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.
80
$'
[
11
:
-
2
]
import
re
,
sys
,
os
,
math
,
DateTimeZone
from
time
import
time
,
gmtime
,
localtime
,
asctime
from
time
import
timezone
,
strftime
from
time
import
daylight
,
timezone
,
altzone
from
time
import
daylight
,
timezone
,
altzone
,
strftime
from
types
import
InstanceType
,
IntType
,
FloatType
,
StringType
,
UnicodeType
try
:
from
time
import
tzname
except
:
tzname
=
(
'UNKNOWN'
,
'UNKNOWN'
)
...
...
@@ -400,6 +399,9 @@ def safelocaltime(t):
rval
=
localtime
(
t_int
)
return
rval
def
_tzoffset2rfc822zone
(
seconds
):
return
"%+03d%02d"
%
divmod
(
(
-
seconds
/
60
),
60
)
class
DateTime
:
"""DateTime objects represent instants in time and provide
...
...
@@ -1435,9 +1437,16 @@ class DateTime:
def rfc822(self):
"""Return the date in RFC 822 format"""
if self._tz == self._localzone0: #Use local standard time
tzoffset = _tzoffset2rfc822zone(localzone)
elif self._tz == self._localzone1: # Use local daylight saving time
tzoffset = _tzoffset2rfc822zone(altzone)
else:
tzoffset = '
-
0000
' # unknown time zone offset
return '
%
s
,
%
2.2
d
%
s
%
d
%
2.2
d
:
%
2.2
d
:
%
2.2
d
%
s
' % (
self._aday,self._day,self._amon,self._year,
self._hour,self._minute,self._nearsec,
self._tz
)
self._hour,self._minute,self._nearsec,
tzoffset
)
# New formats
...
...
lib/python/DateTime/tests/testDateTime.py
View file @
3197d275
# To run these tests, use:
# python unittest.py DateTime.tests.suite
...
...
@@ -5,9 +6,7 @@ import unittest
from
DateTime
import
DateTime
import
string
import
math
import
os
__basedir__
=
os
.
getcwd
()
import
time
class
DateTimeTests
(
unittest
.
TestCase
):
...
...
@@ -94,7 +93,7 @@ class DateTimeTests (unittest.TestCase):
# Compare representations as it's the
# only way to compare the dates to the same accuracy
self
.
assertEqual
(
repr
(
dt
),
repr
(
dt1
))
def
testDayOfWeek
(
self
):
'''strftime() used to always be passed a day of week of 0.'''
dt
=
DateTime
(
'2000/6/16'
)
...
...
@@ -218,27 +217,32 @@ class DateTimeTests (unittest.TestCase):
isoDt
=
DateTime
(
'2002-05-02T08:00:00Z-04:00'
)
self
.
assertEqual
(
ref1
,
isoDt
)
def
testJulianWeek
(
self
):
""" check JulianDayWeek function """
try
:
import
gzip
except
ImportError
:
print
"Warning: testJulianWeek disabled: module gzip not found"
return
0
lines
=
gzip
.
GzipFile
(
os
.
path
.
join
(
__basedir__
,
'julian_testdata.txt.gz'
)).
readlines
()
for
line
in
lines
:
d
=
DateTime
(
line
[:
10
])
result_from_mx
=
tuple
(
map
(
int
,
line
[
12
:
-
2
].
split
(
','
)))
self
.
assertEqual
(
result_from_mx
[
1
],
d
.
week
())
def
testRFC822
(
self
):
'''rfc822 conversion'''
isDST
=
time
.
localtime
(
time
.
time
())[
8
]
if
isDST
:
offset
=
time
.
altzone
else
:
offset
=
time
.
timezone
rfc822zone
=
"%+03d%02d"
%
divmod
(
(
-
offset
/
60
),
60
)
wrongzone
=
"%+03d:%02d"
%
divmod
(
(
60
-
offset
/
60
),
60
)
#one hour off, ISO format
# Create a local DateTime and test
dt
=
DateTime
(
2002
,
5
,
2
,
8
,
0
,
0
)
self
.
assertEqual
(
dt
.
rfc822
(),
'Thu, 02 May 2002 08:00:00'
+
' '
+
rfc822zone
)
# Create a non-local date time and test
dt
=
DateTime
(
'2002-05-02T08:00:00Z'
+
wrongzone
)
self
.
assertEqual
(
dt
.
rfc822
(),
'Thu, 02 May 2002 08:00:00 -0000'
)
#print dt.rfc822()
def
test_suite
():
return
unittest
.
makeSuite
(
DateTimeTests
)
if
__name__
==
"__main__"
:
unittest
.
TextTestRunner
().
run
(
test_suite
())
unittest
.
TextTestRunner
().
run
(
test_suite
())
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