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
2a421293
Commit
2a421293
authored
Dec 21, 2001
by
Andreas Jung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
merge from 2.5 branch
parent
e0b1d6ab
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
49 deletions
+48
-49
lib/python/DateTime/DateTime.py
lib/python/DateTime/DateTime.py
+48
-49
No files found.
lib/python/DateTime/DateTime.py
View file @
2a421293
...
@@ -12,11 +12,10 @@
...
@@ -12,11 +12,10 @@
##############################################################################
##############################################################################
"""Encapsulation of date/time values"""
"""Encapsulation of date/time values"""
__version__
=
'$Revision: 1.7
2
$'
[
11
:
-
2
]
__version__
=
'$Revision: 1.7
3
$'
[
11
:
-
2
]
import
re
,
sys
,
os
,
math
,
DateTimeZone
import
re
,
sys
,
os
,
math
,
DateTimeZone
from
string
import
strip
,
split
,
upper
,
lower
,
atoi
,
atof
,
find
,
join
from
time
import
time
,
gmtime
,
localtime
,
asctime
from
time
import
time
,
gmtime
,
localtime
,
asctime
from
time
import
timezone
,
strftime
from
time
import
timezone
,
strftime
from
time
import
daylight
,
timezone
,
altzone
from
time
import
daylight
,
timezone
,
altzone
...
@@ -77,7 +76,7 @@ class _timezone:
...
@@ -77,7 +76,7 @@ class _timezone:
def
info
(
self
,
t
=
None
):
def
info
(
self
,
t
=
None
):
idx
=
self
.
index
(
t
)[
0
]
idx
=
self
.
index
(
t
)[
0
]
zs
=
self
.
az
[
self
.
tinfo
[
idx
][
2
]:]
zs
=
self
.
az
[
self
.
tinfo
[
idx
][
2
]:]
return
self
.
tinfo
[
idx
][
0
],
self
.
tinfo
[
idx
][
1
],
zs
[:
find
(
zs
,
'
\
000
'
)]
return
self
.
tinfo
[
idx
][
0
],
self
.
tinfo
[
idx
][
1
],
zs
[:
zs
.
find
(
'
\
000
'
)]
...
@@ -232,7 +231,7 @@ class _cache:
...
@@ -232,7 +231,7 @@ class _cache:
self
.
_d
,
self
.
_zidx
=
{},
self
.
_zmap
.
keys
()
self
.
_d
,
self
.
_zidx
=
{},
self
.
_zmap
.
keys
()
def
__getitem__
(
self
,
k
):
def
__getitem__
(
self
,
k
):
try
:
n
=
self
.
_zmap
[
lower
(
k
)]
try
:
n
=
self
.
_zmap
[
k
.
lower
(
)]
except
KeyError
:
except
KeyError
:
if
numericTimeZoneMatch
(
k
)
==
None
:
if
numericTimeZoneMatch
(
k
)
==
None
:
raise
'DateTimeError'
,
'Unrecognized timezone: %s'
%
k
raise
'DateTimeError'
,
'Unrecognized timezone: %s'
%
k
...
@@ -251,7 +250,7 @@ def _findLocalTimeZoneName(isDST):
...
@@ -251,7 +250,7 @@ def _findLocalTimeZoneName(isDST):
try
:
try
:
# Get the name of the current time zone depending
# Get the name of the current time zone depending
# on DST.
# on DST.
_localzone
=
_cache
.
_zmap
[
lower
(
tzname
[
isDST
]
)]
_localzone
=
_cache
.
_zmap
[
tzname
[
isDST
].
lower
(
)]
except
:
except
:
try
:
try
:
# Generate a GMT-offset zone name.
# Generate a GMT-offset zone name.
...
@@ -266,7 +265,7 @@ def _findLocalTimeZoneName(isDST):
...
@@ -266,7 +265,7 @@ def _findLocalTimeZoneName(isDST):
else
:
minorOffset
=
0
else
:
minorOffset
=
0
m
=
majorOffset
>=
0
and
'+'
or
''
m
=
majorOffset
>=
0
and
'+'
or
''
lz
=
'%s%0.02d%0.02d'
%
(
m
,
majorOffset
,
minorOffset
)
lz
=
'%s%0.02d%0.02d'
%
(
m
,
majorOffset
,
minorOffset
)
_localzone
=
_cache
.
_zmap
[
lower
(
'GMT%s'
%
lz
)]
_localzone
=
_cache
.
_zmap
[
(
'GMT%s'
%
lz
).
lower
(
)]
except
:
except
:
_localzone
=
''
_localzone
=
''
return
_localzone
return
_localzone
...
@@ -628,9 +627,9 @@ class DateTime:
...
@@ -628,9 +627,9 @@ class DateTime:
if
arg
==
''
:
if
arg
==
''
:
raise
self
.
SyntaxError
,
arg
raise
self
.
SyntaxError
,
arg
if
type
(
arg
)
in
[
StringType
,
UnicodeType
]
and
lower
(
arg
)
in
self
.
_tzinfo
.
_zidx
:
if
type
(
arg
)
in
[
StringType
,
UnicodeType
]
and
arg
.
lower
(
)
in
self
.
_tzinfo
.
_zidx
:
# Current time, to be displayed in specified timezone
# Current time, to be displayed in specified timezone
t
,
tz
=
time
(),
self
.
_tzinfo
.
_zmap
[
lower
(
arg
)]
t
,
tz
=
time
(),
self
.
_tzinfo
.
_zmap
[
arg
.
lower
(
)]
ms
=
(
t
-
math
.
floor
(
t
))
ms
=
(
t
-
math
.
floor
(
t
))
# Use integer arithmetic as much as possible.
# Use integer arithmetic as much as possible.
s
,
d
=
_calcSD
(
t
)
s
,
d
=
_calcSD
(
t
)
...
@@ -654,7 +653,7 @@ class DateTime:
...
@@ -654,7 +653,7 @@ class DateTime:
x
=
_calcDependentSecond2
(
yr
,
mo
,
dy
,
hr
,
mn
,
sc
)
x
=
_calcDependentSecond2
(
yr
,
mo
,
dy
,
hr
,
mn
,
sc
)
if
tz
:
if
tz
:
try
:
tz
=
self
.
_tzinfo
.
_zmap
[
lower
(
tz
)]
try
:
tz
=
self
.
_tzinfo
.
_zmap
[
tz
.
lower
(
)]
except
KeyError
:
except
KeyError
:
if
numericTimeZoneMatch
(
tz
)
is
None
:
if
numericTimeZoneMatch
(
tz
)
is
None
:
raise
self
.
DateTimeError
,
\
raise
self
.
DateTimeError
,
\
...
@@ -678,7 +677,7 @@ class DateTime:
...
@@ -678,7 +677,7 @@ class DateTime:
# Seconds from epoch (gmt) and timezone
# Seconds from epoch (gmt) and timezone
t
,
tz
=
args
t
,
tz
=
args
ms
=
(
t
-
math
.
floor
(
t
))
ms
=
(
t
-
math
.
floor
(
t
))
tz
=
self
.
_tzinfo
.
_zmap
[
lower
(
tz
)]
tz
=
self
.
_tzinfo
.
_zmap
[
tz
.
lower
(
)]
# Use integer arithmetic as much as possible.
# Use integer arithmetic as much as possible.
s
,
d
=
_calcSD
(
t
)
s
,
d
=
_calcSD
(
t
)
x
=
_calcDependentSecond
(
tz
,
t
)
x
=
_calcDependentSecond
(
tz
,
t
)
...
@@ -722,7 +721,7 @@ class DateTime:
...
@@ -722,7 +721,7 @@ class DateTime:
x
=
_calcDependentSecond2
(
yr
,
mo
,
dy
,
hr
,
mn
,
sc
)
x
=
_calcDependentSecond2
(
yr
,
mo
,
dy
,
hr
,
mn
,
sc
)
ms
=
sc
-
math
.
floor
(
sc
)
ms
=
sc
-
math
.
floor
(
sc
)
if
tz
:
if
tz
:
try
:
tz
=
self
.
_tzinfo
.
_zmap
[
lower
(
tz
)]
try
:
tz
=
self
.
_tzinfo
.
_zmap
[
tz
.
lower
(
)]
except
KeyError
:
except
KeyError
:
if
numericTimeZoneMatch
(
tz
)
is
None
:
if
numericTimeZoneMatch
(
tz
)
is
None
:
raise
self
.
DateTimeError
,
\
raise
self
.
DateTimeError
,
\
...
@@ -838,7 +837,7 @@ class DateTime:
...
@@ -838,7 +837,7 @@ class DateTime:
tz
=
self
.
localZone
(
ltm
)
tz
=
self
.
localZone
(
ltm
)
return
tz
return
tz
def
_parse
(
self
,
st
ring
):
def
_parse
(
self
,
st
):
# Parse date-time components from a string
# Parse date-time components from a string
month
=
year
=
tz
=
tm
=
None
month
=
year
=
tz
=
tm
=
None
spaces
=
self
.
space_chars
spaces
=
self
.
space_chars
...
@@ -853,22 +852,22 @@ class DateTime:
...
@@ -853,22 +852,22 @@ class DateTime:
# Find timezone first, since it should always be the last
# Find timezone first, since it should always be the last
# element, and may contain a slash, confusing the parser.
# element, and may contain a slash, confusing the parser.
st
ring
=
strip
(
string
)
st
=
st
.
strip
(
)
sp
=
s
plit
(
string
)
sp
=
s
t
.
split
(
)
tz
=
sp
[
-
1
]
tz
=
sp
[
-
1
]
if
tz
and
(
lower
(
tz
)
in
ValidZones
):
string
=
join
(
sp
[:
-
1
])
if
tz
and
(
tz
.
lower
()
in
ValidZones
):
st
=
' '
.
join
(
sp
[:
-
1
])
else
:
tz
=
None
# Decide later, since the default time zone
else
:
tz
=
None
# Decide later, since the default time zone
# could depend on the date.
# could depend on the date.
ints
,
dels
=
[],[]
ints
,
dels
=
[],[]
i
,
l
=
0
,
len
(
st
ring
)
i
,
l
=
0
,
len
(
st
)
while
i
<
l
:
while
i
<
l
:
while
i
<
l
and
st
ring
[
i
]
in
spaces
:
i
=
i
+
1
while
i
<
l
and
st
[
i
]
in
spaces
:
i
=
i
+
1
if
i
<
l
and
st
ring
[
i
]
in
delimiters
:
if
i
<
l
and
st
[
i
]
in
delimiters
:
d
=
st
ring
[
i
]
d
=
st
[
i
]
i
=
i
+
1
i
=
i
+
1
else
:
d
=
''
else
:
d
=
''
while
i
<
l
and
st
ring
[
i
]
in
spaces
:
i
=
i
+
1
while
i
<
l
and
st
[
i
]
in
spaces
:
i
=
i
+
1
# The float pattern needs to look back 1 character, because it
# The float pattern needs to look back 1 character, because it
# actually looks for a preceding colon like ':33.33'. This is
# actually looks for a preceding colon like ':33.33'. This is
...
@@ -877,15 +876,15 @@ class DateTime:
...
@@ -877,15 +876,15 @@ class DateTime:
if
i
>
0
:
b
=
i
-
1
if
i
>
0
:
b
=
i
-
1
else
:
b
=
i
else
:
b
=
i
ts_results
=
fltpat
.
match
(
st
ring
,
b
)
ts_results
=
fltpat
.
match
(
st
,
b
)
if
ts_results
:
if
ts_results
:
s
=
ts_results
.
group
(
1
)
s
=
ts_results
.
group
(
1
)
i
=
i
+
len
(
s
)
i
=
i
+
len
(
s
)
ints
.
append
(
atof
(
s
))
ints
.
append
(
float
(
s
))
continue
continue
#AJ
#AJ
ts_results
=
intpat
.
match
(
st
ring
,
i
)
ts_results
=
intpat
.
match
(
st
,
i
)
if
ts_results
:
if
ts_results
:
s
=
ts_results
.
group
(
0
)
s
=
ts_results
.
group
(
0
)
...
@@ -895,31 +894,31 @@ class DateTime:
...
@@ -895,31 +894,31 @@ class DateTime:
(
len
(
ints
)
+
(
not
not
month
)
>=
3
)):
(
len
(
ints
)
+
(
not
not
month
)
>=
3
)):
tz
=
'%s%s'
%
(
d
,
s
)
tz
=
'%s%s'
%
(
d
,
s
)
else
:
else
:
v
=
atoi
(
s
)
v
=
int
(
s
)
ints
.
append
(
v
)
ints
.
append
(
v
)
continue
continue
ts_results
=
wordpat
.
match
(
st
ring
,
i
)
ts_results
=
wordpat
.
match
(
st
,
i
)
if
ts_results
:
if
ts_results
:
o
,
s
=
ts_results
.
group
(
0
),
lower
(
ts_results
.
group
(
0
)
)
o
,
s
=
ts_results
.
group
(
0
),
ts_results
.
group
(
0
).
lower
(
)
i
=
i
+
len
(
s
)
i
=
i
+
len
(
s
)
if
i
<
l
and
st
ring
[
i
]
==
'.'
:
i
=
i
+
1
if
i
<
l
and
st
[
i
]
==
'.'
:
i
=
i
+
1
# Check for month name:
# Check for month name:
if
MonthNumbers
.
has_key
(
s
):
if
MonthNumbers
.
has_key
(
s
):
v
=
MonthNumbers
[
s
]
v
=
MonthNumbers
[
s
]
if
month
is
None
:
month
=
v
if
month
is
None
:
month
=
v
else
:
raise
self
.
SyntaxError
,
st
ring
else
:
raise
self
.
SyntaxError
,
st
continue
continue
# Check for time modifier:
# Check for time modifier:
if
s
in
TimeModifiers
:
if
s
in
TimeModifiers
:
if
tm
is
None
:
tm
=
s
if
tm
is
None
:
tm
=
s
else
:
raise
self
.
SyntaxError
,
st
ring
else
:
raise
self
.
SyntaxError
,
st
continue
continue
# Check for and skip day of week:
# Check for and skip day of week:
if
DayOfWeekNames
.
has_key
(
s
):
if
DayOfWeekNames
.
has_key
(
s
):
continue
continue
raise
self
.
SyntaxError
,
st
ring
raise
self
.
SyntaxError
,
st
day
=
None
day
=
None
if
ints
[
-
1
]
>
60
and
d
not
in
[
'.'
,
':'
]
and
len
(
ints
)
>
2
:
if
ints
[
-
1
]
>
60
and
d
not
in
[
'.'
,
':'
]
and
len
(
ints
)
>
2
:
...
@@ -977,34 +976,34 @@ class DateTime:
...
@@ -977,34 +976,34 @@ class DateTime:
year
,
month
,
day
=
localtime
(
time
())[:
3
]
year
,
month
,
day
=
localtime
(
time
())[:
3
]
year
=
_correctYear
(
year
)
year
=
_correctYear
(
year
)
if
year
<
1000
:
raise
self
.
SyntaxError
,
st
ring
if
year
<
1000
:
raise
self
.
SyntaxError
,
st
leap
=
year
%
4
==
0
and
(
year
%
100
!=
0
or
year
%
400
==
0
)
leap
=
year
%
4
==
0
and
(
year
%
100
!=
0
or
year
%
400
==
0
)
try
:
try
:
if
not
day
or
day
>
self
.
_month_len
[
leap
][
month
]:
if
not
day
or
day
>
self
.
_month_len
[
leap
][
month
]:
raise
self
.
DateError
,
st
ring
raise
self
.
DateError
,
st
except
IndexError
:
except
IndexError
:
raise
self
.
DateError
,
st
ring
raise
self
.
DateError
,
st
tod
=
0
tod
=
0
if
ints
:
if
ints
:
i
=
ints
[
0
]
i
=
ints
[
0
]
# Modify hour to reflect am/pm
# Modify hour to reflect am/pm
if
tm
and
(
tm
==
'pm'
)
and
i
<
12
:
i
=
i
+
12
if
tm
and
(
tm
==
'pm'
)
and
i
<
12
:
i
=
i
+
12
if
tm
and
(
tm
==
'am'
)
and
i
==
12
:
i
=
0
if
tm
and
(
tm
==
'am'
)
and
i
==
12
:
i
=
0
if
i
>
24
:
raise
self
.
DateTimeError
,
st
ring
if
i
>
24
:
raise
self
.
DateTimeError
,
st
tod
=
tod
+
int
(
i
)
*
3600
tod
=
tod
+
int
(
i
)
*
3600
del
ints
[
0
]
del
ints
[
0
]
if
ints
:
if
ints
:
i
=
ints
[
0
]
i
=
ints
[
0
]
if
i
>
60
:
raise
self
.
DateTimeError
,
st
ring
if
i
>
60
:
raise
self
.
DateTimeError
,
st
tod
=
tod
+
int
(
i
)
*
60
tod
=
tod
+
int
(
i
)
*
60
del
ints
[
0
]
del
ints
[
0
]
if
ints
:
if
ints
:
i
=
ints
[
0
]
i
=
ints
[
0
]
if
i
>
60
:
raise
self
.
DateTimeError
,
st
ring
if
i
>
60
:
raise
self
.
DateTimeError
,
st
tod
=
tod
+
i
tod
=
tod
+
i
del
ints
[
0
]
del
ints
[
0
]
if
ints
:
raise
self
.
SyntaxError
,
st
ring
if
ints
:
raise
self
.
SyntaxError
,
st
tod_int
=
int
(
math
.
floor
(
tod
))
tod_int
=
int
(
math
.
floor
(
tod
))
...
@@ -1046,7 +1045,7 @@ class DateTime:
...
@@ -1046,7 +1045,7 @@ class DateTime:
def
toZone
(
self
,
z
):
def
toZone
(
self
,
z
):
"""Return a DateTime with the value as the current
"""Return a DateTime with the value as the current
object, represented in the indicated timezone."""
object, represented in the indicated timezone."""
t
,
tz
=
self
.
_t
,
self
.
_tzinfo
.
_zmap
[
lower
(
z
)]
t
,
tz
=
self
.
_t
,
self
.
_tzinfo
.
_zmap
[
z
.
lower
(
)]
millis
=
self
.
millis
()
millis
=
self
.
millis
()
#if (t>0 and ((t/86400.0) < 24837)):
#if (t>0 and ((t/86400.0) < 24837)):
try
:
try
:
...
@@ -1537,7 +1536,7 @@ class DateTime:
...
@@ -1537,7 +1536,7 @@ class DateTime:
try
:
try
:
# For the seconds, print two digits
# For the seconds, print two digits
# before the decimal point.
# before the decimal point.
subsec
=
split
(
'%g'
%
s
,
'.'
)[
1
]
subsec
=
(
'%g'
%
s
).
split
(
'.'
)[
1
]
return
'%4.4d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d.%s %s'
%
(
return
'%4.4d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d.%s %s'
%
(
y
,
m
,
d
,
h
,
mn
,
s
,
subsec
,
t
)
y
,
m
,
d
,
h
,
mn
,
s
,
subsec
,
t
)
except
:
except
:
...
@@ -1603,7 +1602,7 @@ class DateTime:
...
@@ -1603,7 +1602,7 @@ class DateTime:
try
:
try
:
return
self
.
__parse_iso8601
(
s
)
return
self
.
__parse_iso8601
(
s
)
except
IndexError
:
except
IndexError
:
raise
self
.
DateError
,
'Not an ISO 8601 compliant date string: "%s"'
%
s
tring
raise
self
.
DateError
,
'Not an ISO 8601 compliant date string: "%s"'
%
s
def
__parse_iso8601
(
self
,
s
):
def
__parse_iso8601
(
self
,
s
):
...
@@ -1619,24 +1618,24 @@ class DateTime:
...
@@ -1619,24 +1618,24 @@ class DateTime:
fields
=
datereg
.
split
(
s
.
strip
())
fields
=
datereg
.
split
(
s
.
strip
())
if
fields
[
1
]:
year
=
atoi
(
fields
[
1
])
if
fields
[
1
]:
year
=
int
(
fields
[
1
])
if
fields
[
3
]:
month
=
atoi
(
fields
[
3
])
if
fields
[
3
]:
month
=
int
(
fields
[
3
])
if
fields
[
5
]:
day
=
atoi
(
fields
[
5
])
if
fields
[
5
]:
day
=
int
(
fields
[
5
])
if
s
.
find
(
'T'
)
>-
1
:
if
s
.
find
(
'T'
)
>-
1
:
fields
=
timereg
.
split
(
s
[
s
.
find
(
'T'
)
+
1
:])
fields
=
timereg
.
split
(
s
[
s
.
find
(
'T'
)
+
1
:])
if
fields
[
1
]:
hour
=
atoi
(
fields
[
1
])
if
fields
[
1
]:
hour
=
int
(
fields
[
1
])
if
fields
[
3
]:
minute
=
atoi
(
fields
[
3
])
if
fields
[
3
]:
minute
=
int
(
fields
[
3
])
if
fields
[
5
]:
seconds
=
atoi
(
fields
[
5
])
if
fields
[
5
]:
seconds
=
int
(
fields
[
5
])
if
fields
[
6
]:
seconds
=
seconds
+
atof
(
fields
[
6
])
if
fields
[
6
]:
seconds
=
seconds
+
float
(
fields
[
6
])
if
s
.
find
(
'Z'
)
>-
1
:
if
s
.
find
(
'Z'
)
>-
1
:
pass
pass
if
s
[
-
3
]
==
':'
and
s
[
-
6
]
in
[
'+'
,
'-'
]:
if
s
[
-
3
]
==
':'
and
s
[
-
6
]
in
[
'+'
,
'-'
]:
hour_off
=
atoi
(
s
[
-
6
:
-
3
])
hour_off
=
int
(
s
[
-
6
:
-
3
])
min_off
=
atoi
(
s
[
-
2
:])
min_off
=
int
(
s
[
-
2
:])
return
year
,
month
,
day
,
hour
,
minute
,
seconds
,
'GMT%+03d%02d'
%
(
hour_off
,
min_off
)
return
year
,
month
,
day
,
hour
,
minute
,
seconds
,
'GMT%+03d%02d'
%
(
hour_off
,
min_off
)
...
...
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