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
59db7e71
Commit
59db7e71
authored
Jun 05, 2001
by
Andreas Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added parser/constructor for ISO 8601 dates
parent
6b166e2e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
1 deletion
+53
-1
lib/python/DateTime/DateTime.py
lib/python/DateTime/DateTime.py
+53
-1
No files found.
lib/python/DateTime/DateTime.py
View file @
59db7e71
...
@@ -84,7 +84,7 @@
...
@@ -84,7 +84,7 @@
##############################################################################
##############################################################################
"""Encapsulation of date/time values"""
"""Encapsulation of date/time values"""
__version__
=
'$Revision: 1.6
5
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.6
6
$'
[
11
:
-
2
]
import
re
,
sys
,
os
,
math
,
DateTimeZone
import
re
,
sys
,
os
,
math
,
DateTimeZone
...
@@ -1620,3 +1620,55 @@ class strftimeFormatter:
...
@@ -1620,3 +1620,55 @@ class strftimeFormatter:
def
Timezones
():
def
Timezones
():
"""Return the list of recognized timezone names"""
"""Return the list of recognized timezone names"""
return
_cache
.
_zlst
return
_cache
.
_zlst
# Parse a ISO 8601
def
parse_iso8601
(
s
):
""" parse an ISO 8601 compliant date string and return an
instance of DateTime
"""
try
:
return
_parse_iso8601
(
s
)
except
:
print
sys
.
exc_type
,
sys
.
exc_value
raise
'DateTimeError'
,
'not ISO 8601 compliant date string: %s'
%
s
def
_parse_iso8601
(
s
):
year
=
0
month
=
day
=
1
hour
=
minute
=
seconds
=
hour_off
=
min_off
=
0
datereg
=
re
.
compile
(
'([0-9]{4})(-([0-9][0-9]))?(-([0-9][0-9]))?'
)
timereg
=
re
.
compile
(
'([0-9]{2})(:([0-9][0-9]))?(:([0-9][0-9]))?(
\
.[
0
-9]{1,20})?'
)
# Date part
fields
=
datereg
.
split
(
s
.
strip
())
if
fields
[
1
]:
year
=
atoi
(
fields
[
1
])
if
fields
[
3
]:
month
=
atoi
(
fields
[
3
])
if
fields
[
5
]:
day
=
atoi
(
fields
[
5
])
if
s
.
find
(
'T'
)
>-
1
:
fields
=
timereg
.
split
(
s
[
s
.
find
(
'T'
)
+
1
:])
if
fields
[
1
]:
hour
=
atoi
(
fields
[
1
])
if
fields
[
3
]:
minute
=
atoi
(
fields
[
3
])
if
fields
[
5
]:
seconds
=
atoi
(
fields
[
5
])
if
fields
[
6
]:
seconds
=
seconds
+
atof
(
fields
[
6
])
if
s
.
find
(
'Z'
)
>-
1
:
pass
if
s
[
-
3
]
==
':'
and
s
[
-
6
]
in
[
'+'
,
'-'
]:
hour_off
=
atoi
(
s
[
-
6
:
-
3
])
min_off
=
atoi
(
s
[
-
2
:])
ts
=
mktime
((
year
,
month
,
day
,
hour
,
minute
,
seconds
,
0
,
0
,
0
))
ts
=
ts
+
(
hour_off
*
60
-
min_off
)
return
DateTime
(
ts
)
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