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
10536ddb
Commit
10536ddb
authored
Jan 22, 2003
by
Andreas Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge from ajung-european-datetime-support-branch
parent
1635ca94
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
70 additions
and
14 deletions
+70
-14
doc/CHANGES.txt
doc/CHANGES.txt
+8
-0
doc/ENVIRONMENT.txt
doc/ENVIRONMENT.txt
+14
-7
lib/python/DateTime/DateTime.py
lib/python/DateTime/DateTime.py
+28
-7
lib/python/DateTime/tests/testDateTime.py
lib/python/DateTime/tests/testDateTime.py
+13
-0
lib/python/Products/OFSP/help/DateTime.py
lib/python/Products/OFSP/help/DateTime.py
+7
-0
No files found.
doc/CHANGES.txt
View file @
10536ddb
...
...
@@ -22,6 +22,14 @@ Zope Changes
support for obtaining a more useful value from other headers if a
front-end proxy is in use. See doc/ENVIRONMENT.txt for details.
- DateTime module: added support to parse international dateformats. The
Datetime constructor has a new "datefmt" parameter to enforce the
parsing of a date as "us" or "international" date. The new field
descriptor field descriptor "date_international" can be used to
enforce this behaviour inside the ZPublisher. See also
doc/ENVIRONMENT.txt to check with the DATETIME_FORMAT
Bugs Fixed
- Collector #771: ZCatalog failed to index DTML Document if the name
...
...
doc/ENVIRONMENT.txt
View file @
10536ddb
...
...
@@ -199,12 +199,12 @@ Security related
ZSP_OWNEROUS_SKIP
If set, will cause the Zope Security Policy to skip checks relating
to ownership, for servers on which ownership is not important.
to ownership, for servers on which ownership is not important.
ZSP_AUTHENTICATED_SKIP
If set, will cause the Zope Security Policy to skip checks relating
to authentication, for servers which serve only anonymous content.
to authentication, for servers which serve only anonymous content.
DISALLOW_LOCAL_PRODUCTS
...
...
@@ -272,11 +272,9 @@ Structured Text
STX_DEFAULT_LEVEL
Set this variable to change the default level for <Hx> elements.
The default level is 3.
DTML
Set this variable to change the default level for <Hx> elements.
The default level is 3.
ZOPE_DTML_REQUEST_AUTOQUOTE
...
...
@@ -288,6 +286,15 @@ DTML
HTML quoted when interpolated with a <dtml-var> or &dtml-;
construct.
DateTime
DATETIME_FORMAT
Set this variable either to "us" or "international" to force
the DateTime module to parse date strings either with
month before days before year or days before month before
year. If unset the default behaviour of DateTime is untouched
and parses ambigious date formats as US date.
Esoteric
...
...
lib/python/DateTime/DateTime.py
View file @
10536ddb
...
...
@@ -12,16 +12,21 @@
##############################################################################
"""Encapsulation of date/time values"""
__version__
=
'$Revision: 1.8
4
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.8
5
$'
[
11
:
-
2
]
import
re
,
math
,
DateTimeZone
import
os
,
re
,
math
,
DateTimeZone
from
time
import
time
,
gmtime
,
localtime
,
asctime
from
time
import
daylight
,
timezone
,
altzone
,
strftime
from
types
import
InstanceType
,
IntType
,
FloatType
,
StringType
,
UnicodeType
try
:
from
time
import
tzname
except
:
tzname
=
(
'UNKNOWN'
,
'UNKNOWN'
)
_default_datefmt
=
os
.
environ
.
get
(
'DATETIME_FORMAT'
,
"us"
).
lower
()
if
not
_default_datefmt
in
(
'us'
,
'international'
):
raise
ValueError
,
"DATETIME_FORMAT must be either 'us' or 'international'"
# To control rounding errors, we round system time to the nearest
# millisecond. Then delicate calculations can rely on that the
# maximum precision that needs to be preserved is known.
...
...
@@ -456,7 +461,7 @@ class DateTime:
__roles__
=
None
__allow_access_to_unprotected_subobjects__
=
1
def
__init__
(
self
,
*
args
):
def
__init__
(
self
,
*
args
,
**
kw
):
"""Return a new date-time object
A DateTime object always maintains its value as an absolute
...
...
@@ -601,6 +606,13 @@ class DateTime:
effect of this is as if you had taken the value of time.time()
at that time on a machine in the specified timezone).
New in Zope 2.7:
A new keyword parameter "datefmt" can be passed to the
constructor. If set to "international", the constructor
is forced to treat ambigious dates as "days before month
before year". This useful if you need to parse non-US
dates in a reliable way
In any case that a floating point number of seconds is given
or derived, it's rounded to the nearest millisecond.
...
...
@@ -613,6 +625,9 @@ class DateTime:
timezones recognized by the DateTime module. Recognition of
timezone names is case-insensitive."""
#'
datefmt
=
kw
.
get
(
'datefmt'
,
_default_datefmt
)
assert
datefmt
in
(
'us'
,
'international'
)
d
=
t
=
s
=
None
ac
=
len
(
args
)
millisecs
=
None
...
...
@@ -656,7 +671,7 @@ class DateTime:
if
arg
.
find
(
' '
)
==-
1
and
arg
[
4
]
==
'-'
:
yr
,
mo
,
dy
,
hr
,
mn
,
sc
,
tz
=
self
.
_parse_iso8601
(
arg
)
else
:
yr
,
mo
,
dy
,
hr
,
mn
,
sc
,
tz
=
self
.
_parse
(
arg
)
yr
,
mo
,
dy
,
hr
,
mn
,
sc
,
tz
=
self
.
_parse
(
arg
,
datefmt
)
if
not
self
.
_validDate
(
yr
,
mo
,
dy
):
...
...
@@ -860,7 +875,7 @@ class DateTime:
tz
=
self
.
localZone
(
ltm
)
return
tz
def
_parse
(
self
,
st
):
def
_parse
(
self
,
st
,
datefmt
=
_default_datefmt
):
# Parse date-time components from a string
month
=
year
=
tz
=
tm
=
None
spaces
=
self
.
space_chars
...
...
@@ -987,8 +1002,13 @@ class DateTime:
day
=
ints
[
0
]
month
=
ints
[
1
]
else
:
day
=
ints
[
1
]
month
=
ints
[
0
]
if
datefmt
==
"us"
:
day
=
ints
[
1
]
month
=
ints
[
0
]
else
:
day
=
ints
[
0
]
month
=
ints
[
1
]
elif
ints
[
0
]
<=
12
:
month
=
ints
[
0
]
day
=
ints
[
1
]
...
...
@@ -1685,3 +1705,4 @@ class strftimeFormatter:
def
Timezones
():
"""Return the list of recognized timezone names"""
return
_cache
.
_zlst
lib/python/DateTime/tests/testDateTime.py
View file @
10536ddb
...
...
@@ -306,6 +306,19 @@ class DateTimeTests(unittest.TestCase):
self
.
assertEqual
(
dts
[
5
],
"%+03d%02d"
%
divmod
(
(
-
offset
/
60
),
60
)
)
def
testInternationalDateformat
(
self
):
for
year
in
range
(
1990
,
2020
):
for
month
in
range
(
1
,
13
):
for
day
in
range
(
1
,
32
):
try
:
d_us
=
DateTime
(
"%d/%d/%d"
%
(
year
,
month
,
day
))
except
:
continue
d_int
=
DateTime
(
"%d.%d.%d"
%
(
day
,
month
,
year
),
datefmt
=
"international"
)
self
.
assertEqual
(
d_us
,
d_int
)
def
test_suite
():
return
unittest
.
makeSuite
(
DateTimeTests
)
...
...
lib/python/Products/OFSP/help/DateTime.py
View file @
10536ddb
...
...
@@ -195,6 +195,13 @@ class DateTime:
effect of this is as if you had taken the value of time.time()
at that time on a machine in the specified timezone).
New in Zope 2.7:
A new keyword parameter "datefmt" can be passed to the
constructor. If set to "international", the constructor
is forced to treat ambigious dates as "days before month
before year". This useful if you need to parse non-US
dates in a reliable way
If a string argument passed to the DateTime constructor cannot be
parsed, it will raise DateTime.SyntaxError. Invalid date, time, or
timezone components will raise a DateTime.DateTimeError.
...
...
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