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
7df93024
Commit
7df93024
authored
Dec 13, 2006
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Back out BBB-violating patch for
http://www.zope.org/Collectors/Zope/2191
.
parent
133491d0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
331 additions
and
530 deletions
+331
-530
doc/CHANGES.txt
doc/CHANGES.txt
+0
-3
lib/python/DateTime/DateTime.py
lib/python/DateTime/DateTime.py
+274
-390
lib/python/DateTime/tests/testDateTime.py
lib/python/DateTime/tests/testDateTime.py
+57
-137
No files found.
doc/CHANGES.txt
View file @
7df93024
...
@@ -15,9 +15,6 @@ Zope Changes
...
@@ -15,9 +15,6 @@ Zope Changes
Bugs fixed
Bugs fixed
- Collector #2191: extended DateTime parser for better support
to the ISO8601 specification.
- Reworking of _cached_result in Shared.DC.ZRDB.DA.DA:
- Reworking of _cached_result in Shared.DC.ZRDB.DA.DA:
- fixed KeyError reported in Collector #2212
- fixed KeyError reported in Collector #2212
...
...
lib/python/DateTime/DateTime.py
View file @
7df93024
...
@@ -70,52 +70,7 @@ to_month=tm[yr%4==0 and (yr%100!=0 or yr%400==0)][mo]
...
@@ -70,52 +70,7 @@ to_month=tm[yr%4==0 and (yr%100!=0 or yr%400==0)][mo]
EPOCH
=
(
to_year
+
to_month
+
dy
+
(
hr
/
24.0
+
mn
/
1440.0
+
sc
/
86400.0
))
*
86400
EPOCH
=
(
to_year
+
to_month
+
dy
+
(
hr
/
24.0
+
mn
/
1440.0
+
sc
/
86400.0
))
*
86400
jd1901
=
2415385L
jd1901
=
2415385L
numericTimeZoneMatch
=
re
.
compile
(
r'[+-][0-9][0-9][0-9][0-9]'
).
match
numericTimeZoneMatch
=
re
.
compile
(
r'[+-][0-9][0-9][0-9][0-9]'
).
match
#TS
iso8601Match
=
re
.
compile
(
r'''
(?P<year>\
d
\d\
d
\d) # four digits year
(?:-? # one optional dash
(?: # followed by:
(?P<year_day>\
d
\d\
d #
three digits year day
(?!\
d)) # whe
n there's no fourth digit
| # or:
W # one W
(?P<week>\
d
\d) # two digits week
(?:-? # one optional dash
(?P<week_day>\
d) # o
ne digit week day
)? # week day is optional
| # or:
(?P<month>\
d
\d)? # two digits month
(?:-? # one optional dash
(?P<day>\
d
\d)? # two digits day
)? # after day is optional
) #
)? # after year is optional
(?:[T ] # one T or one whitespace
(?P<hour>\
d
\d) # two digits hour
(?::? # one optional colon
(?P<minute>\
d
\d)? # two digits minute
(?::? # one optional colon
(?P<second>\
d
\d)? # two digits second
(?:[.,] # one dot or one comma
(?P<fraction>\
d+) #
n digits fraction
)? # after second is optional
)? # after minute is optional
)? # after hour is optional
(?: # timezone:
Z # one Z
| # or:
(?P<signal>[-+]) # one plus or one minus as signal
(?P<hour_off>\
d # o
ne digit for hour offset...
(?:\
d(?!
\d$) # ...or two, if not the last two digits
)?) # second hour offset digit is optional
(?::? # one optional colon
(?P<min_off>\
d
\d) # two digits minute offset
)? # after hour offset is optional
)? # timezone is optional
)? # time is optional
(?P<garbage>.*) # store the extra garbage
'''
,
re
.
VERBOSE
).
match
class
_timezone
:
class
_timezone
:
def
__init__
(
self
,
data
):
def
__init__
(
self
,
data
):
...
@@ -157,6 +112,8 @@ class _timezone:
...
@@ -157,6 +112,8 @@ class _timezone:
return
self
.
tinfo
[
idx
][
0
],
self
.
tinfo
[
idx
][
1
],
zs
[:
zs
.
find
(
'
\
000
'
)]
return
self
.
tinfo
[
idx
][
0
],
self
.
tinfo
[
idx
][
1
],
zs
[:
zs
.
find
(
'
\
000
'
)]
class
_cache
:
class
_cache
:
_zlst
=
[
'Brazil/Acre'
,
'Brazil/DeNoronha'
,
'Brazil/East'
,
_zlst
=
[
'Brazil/Acre'
,
'Brazil/DeNoronha'
,
'Brazil/East'
,
...
@@ -193,6 +150,7 @@ class _cache:
...
@@ -193,6 +150,7 @@ class _cache:
'MEWT'
,
'SWT'
,
'FWT'
,
'EET'
,
'EEST'
,
'BT'
,
'ZP4'
,
'ZP5'
,
'ZP6'
,
'MEWT'
,
'SWT'
,
'FWT'
,
'EET'
,
'EEST'
,
'BT'
,
'ZP4'
,
'ZP5'
,
'ZP6'
,
'WAST'
,
'CCT'
,
'JST'
,
'EAST'
,
'GST'
,
'NZT'
,
'NZST'
,
'IDLE'
]
'WAST'
,
'CCT'
,
'JST'
,
'EAST'
,
'GST'
,
'NZT'
,
'NZST'
,
'IDLE'
]
_zmap
=
{
'aest'
:
'GMT+1000'
,
'aedt'
:
'GMT+1100'
,
_zmap
=
{
'aest'
:
'GMT+1000'
,
'aedt'
:
'GMT+1100'
,
'aus eastern standard time'
:
'GMT+1000'
,
'aus eastern standard time'
:
'GMT+1000'
,
'sydney standard time'
:
'GMT+1000'
,
'sydney standard time'
:
'GMT+1000'
,
...
@@ -225,6 +183,7 @@ class _cache:
...
@@ -225,6 +183,7 @@ class _cache:
'gmt+0000'
:
'GMT+0'
,
'gmt+0'
:
'GMT+0'
,
'gmt+0000'
:
'GMT+0'
,
'gmt+0'
:
'GMT+0'
,
'gmt+0100'
:
'GMT+1'
,
'gmt+0200'
:
'GMT+2'
,
'gmt+0300'
:
'GMT+3'
,
'gmt+0100'
:
'GMT+1'
,
'gmt+0200'
:
'GMT+2'
,
'gmt+0300'
:
'GMT+3'
,
'gmt+0400'
:
'GMT+4'
,
'gmt+0500'
:
'GMT+5'
,
'gmt+0600'
:
'GMT+6'
,
'gmt+0400'
:
'GMT+4'
,
'gmt+0500'
:
'GMT+5'
,
'gmt+0600'
:
'GMT+6'
,
'gmt+0700'
:
'GMT+7'
,
'gmt+0800'
:
'GMT+8'
,
'gmt+0900'
:
'GMT+9'
,
'gmt+0700'
:
'GMT+7'
,
'gmt+0800'
:
'GMT+8'
,
'gmt+0900'
:
'GMT+9'
,
...
@@ -305,8 +264,7 @@ class _cache:
...
@@ -305,8 +264,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
:
try
:
n
=
self
.
_zmap
[
k
.
lower
()]
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
...
@@ -317,6 +275,7 @@ class _cache:
...
@@ -317,6 +275,7 @@ class _cache:
return
z
return
z
def
_findLocalTimeZoneName
(
isDST
):
def
_findLocalTimeZoneName
(
isDST
):
if
not
daylight
:
if
not
daylight
:
# Daylight savings does not occur in this time zone.
# Daylight savings does not occur in this time zone.
...
@@ -411,16 +370,11 @@ def _julianday(yr,mo,dy):
...
@@ -411,16 +370,11 @@ def _julianday(yr,mo,dy):
m
=-
m
m
=-
m
y
=
y
-
m
/
12L
-
1L
y
=
y
-
m
/
12L
-
1L
m
=
12L
-
m
%
12L
m
=
12L
-
m
%
12L
if
y
>
0L
:
if
y
>
0L
:
yr_correct
=
0L
yr_correct
=
0L
else
:
yr_correct
=
3L
else
:
if
m
<
3L
:
y
,
m
=
y
-
1L
,
m
+
12L
yr_correct
=
3L
if
y
*
10000L
+
m
*
100L
+
d
>
15821014L
:
b
=
2L
-
y
/
100L
+
y
/
400L
if
m
<
3L
:
else
:
b
=
0L
y
,
m
=
y
-
1L
,
m
+
12L
if
y
*
10000L
+
m
*
100L
+
d
>
15821014L
:
b
=
2L
-
y
/
100L
+
y
/
400L
else
:
b
=
0L
return
(
1461L
*
y
-
yr_correct
)
/
4L
+
306001L
*
(
m
+
1L
)
/
10000L
+
d
+
1720994L
+
b
return
(
1461L
*
y
-
yr_correct
)
/
4L
+
306001L
*
(
m
+
1L
)
/
10000L
+
d
+
1720994L
+
b
def
_calendarday
(
j
):
def
_calendarday
(
j
):
...
@@ -558,8 +512,9 @@ class DateTime:
...
@@ -558,8 +512,9 @@ class DateTime:
except
:
except
:
raise
SyntaxError
(
'Unable to parse %s, %s'
%
(
args
,
kw
))
raise
SyntaxError
(
'Unable to parse %s, %s'
%
(
args
,
kw
))
def
_parse_args
(
self
,
*
args
,
**
kw
):
def
_parse_args
(
self
,
*
args
,
**
kw
):
"""Return a new date-time object
.
"""Return a new date-time object
A DateTime object always maintains its value as an absolute
A DateTime object always maintains its value as an absolute
UTC time, and is represented in the context of some timezone
UTC time, and is represented in the context of some timezone
...
@@ -571,6 +526,7 @@ class DateTime:
...
@@ -571,6 +526,7 @@ class DateTime:
DateTimes may be created with from zero to seven arguments.
DateTimes may be created with from zero to seven arguments.
- If the function is called with no arguments or with None,
- If the function is called with no arguments or with None,
then the current date/time is returned, represented in the
then the current date/time is returned, represented in the
timezone of the local machine.
timezone of the local machine.
...
@@ -585,23 +541,23 @@ class DateTime:
...
@@ -585,23 +541,23 @@ class DateTime:
that date/time will be returned.
that date/time will be returned.
As a general rule, any date-time representation that is
As a general rule, any date-time representation that is
recognized and unambigous to a resident of North America
recognized and unambigous to a resident of North America
is
is acceptable.
The reason for this qualification is that
acceptable.(
The reason for this qualification is that
in North America, a date like: 2/1/1994 is interpreted
in North America, a date like: 2/1/1994 is interpreted
as February 1, 1994, while in some parts of the world,
as February 1, 1994, while in some parts of the world,
it is interpreted as January 2, 1994.
it is interpreted as January 2, 1994.) A date/time
string consists of two components, a date component and
A date/time string consists of two components, a date
an optional time component, separated by one or more
component and an optional time component, separated by one
spaces. If the time component is omited, 12:00am is
or more spaces. If the time component is omited, 12:00am is
assumed. Any recognized timezone name specified as the
assumed. Any recognized timezone name specified as the final
final element of the date/time string will be used for
element of the date/time string will be used for computing
computing the date/time value. (If you create a DateTime
the date/time value. If you create a DateTime with the
with the string 'Mar 9, 1997 1:45pm US/Pacific', the
string 'Mar 9, 1997 1:45pm US/Pacific', the value will
value will essentially be the same as if you had captured
essentially be the same as if you had captured time.time()
time.time() at the specified date and time on a machine in
at the specified date and time on a machine in that timezone:
that timezone)
<PRE>
<PRE>
e=DateTime('US/Eastern')
e=DateTime('US/Eastern')
# returns current date/time, represented in US/Eastern.
# returns current date/time, represented in US/Eastern.
...
@@ -610,13 +566,20 @@ class DateTime:
...
@@ -610,13 +566,20 @@ class DateTime:
y=DateTime('Mar 9, 1997 13:45:00')
y=DateTime('Mar 9, 1997 13:45:00')
# y is equal to x
# y is equal to x
</PRE>
</PRE>
New in Zope 2.4:
The DateTime constructor automatically detects and handles
ISO8601 compliant dates (YYYY-MM-DDThh:ss:mmTZD).
See http://www.w3.org/TR/NOTE-datetime for full specs.
The date component consists of year, month, and day
The date component consists of year, month, and day
values. The year value must be a one-, two-, or
values. The year value must be a one-, two-, or
four-digit integer. If a one- or two-digit year is
four-digit integer. If a one- or two-digit year is
used, the year is assumed to be in the twentieth
used, the year is assumed to be in the twentieth
century. The month may
be
an integer, from 1 to 12, a
century. The month may an integer, from 1 to 12, a
month name, or a month abreviation, where a period may
month name, or a month abreviation, where a period may
optionally follow the abreviation. The day must be an
optionally follow the abreviation. The day must be an
integer from 1 to the number of days in the month. The
integer from 1 to the number of days in the month. The
...
@@ -638,47 +601,28 @@ class DateTime:
...
@@ -638,47 +601,28 @@ class DateTime:
followed by am or pm in upper or lower case, in which
followed by am or pm in upper or lower case, in which
case a 12-hour clock is assumed.
case a 12-hour clock is assumed.
New in Zope 2.4:
- If the DateTime function is invoked with a single
The DateTime constructor automatically detects and handles
Numeric argument, the number is assumed to be
ISO8601 compliant dates (YYYY-MM-DDThh:ss:mmTZD).
a floating point value such as that returned by
time.time().
New in Zope 2.9.6:
The existing ISO8601 parser was extended to support almost
the whole ISO8601 specification. New formats includes:
<PRE>
y=DateTime('1993-045')
# returns the 45th day from 1993, which is 14th February
w=DateTime('1993-W06-7')
# returns the 7th day from the 6th week from 1993, which
# is also 14th February
</PRE>
See http://en.wikipedia.org/wiki/ISO_8601 for full specs.
- If the DateTime function is invoked with a single Numeric
A DateTime object is returned that represents
argument, the number is assumed to be a floating point value
the gmt value of the time.time() float represented in
such as that returned by time.time().
the local machine's timezone.
A DateTime object is returned that represents the GMT value
of the time.time() float represented in the local machine's
timezone.
- If the DateTime function is invoked with a single argument
- If the DateTime function is invoked with a single
that is a DateTime instane, a copy of the passed object will
argument that is a DateTime instane, a copy of the
be created.
passed object will be created.
- If the function is invoked with two numeric arguments, then
the first is taken to be an integer year and the second
argument is taken to be an offset in days from the beginning
of the year, in the context of the local machine timezone.
- If the function is invoked with two numeric arguments,
then the first is taken to be an integer year and the
second argument is taken to be an offset in days from
the beginning of the year, in the context of the local
machine timezone.
The date-time value returned is the given offset number of
The date-time value returned is the given offset number of
days from the beginning of the given year, represented in
days from the beginning of the given year, represented in
the timezone of the local machine. The offset may be positive
the timezone of the local machine. The offset may be positive
or negative.
or negative.
Two-digit years are assumed to be in the twentieth
Two-digit years are assumed to be in the twentieth
century.
century.
...
@@ -688,7 +632,6 @@ class DateTime:
...
@@ -688,7 +632,6 @@ class DateTime:
second a string naming a recognized timezone, a DateTime
second a string naming a recognized timezone, a DateTime
with a value of that gmt time will be returned, represented
with a value of that gmt time will be returned, represented
in the given timezone.
in the given timezone.
<PRE>
<PRE>
import time
import time
t=time.time()
t=time.time()
...
@@ -701,6 +644,7 @@ class DateTime:
...
@@ -701,6 +644,7 @@ class DateTime:
# now_east == now_west
# now_east == now_west
# only their representations are different
# only their representations are different
</PRE>
</PRE>
- If the function is invoked with three or more numeric
- If the function is invoked with three or more numeric
...
@@ -735,8 +679,7 @@ class DateTime:
...
@@ -735,8 +679,7 @@ class DateTime:
The module function Timezones() will return a list of the
The module function Timezones() will return a list of the
timezones recognized by the DateTime module. Recognition of
timezones recognized by the DateTime module. Recognition of
timezone names is case-insensitive.
timezone names is case-insensitive."""
#'
"""
datefmt
=
kw
.
get
(
'datefmt'
,
getDefaultDateFormat
())
datefmt
=
kw
.
get
(
'datefmt'
,
getDefaultDateFormat
())
d
=
t
=
s
=
None
d
=
t
=
s
=
None
...
@@ -767,9 +710,7 @@ class DateTime:
...
@@ -767,9 +710,7 @@ class DateTime:
raise
SyntaxError
,
arg
raise
SyntaxError
,
arg
if
isinstance
(
arg
,
DateTime
):
if
isinstance
(
arg
,
DateTime
):
"""Construct a new DateTime instance from a given
""" Construct a new DateTime instance from a given DateTime instance """
DateTime instance.
"""
t
=
arg
.
timeTime
()
t
=
arg
.
timeTime
()
lt
=
safelocaltime
(
t
)
lt
=
safelocaltime
(
t
)
tz
=
self
.
localZone
(
lt
)
tz
=
self
.
localZone
(
lt
)
...
@@ -790,13 +731,12 @@ class DateTime:
...
@@ -790,13 +731,12 @@ class DateTime:
elif
isinstance
(
arg
,
(
unicode
,
str
)):
elif
isinstance
(
arg
,
(
unicode
,
str
)):
# Date/time string
# Date/time string
iso8601
=
iso8601Match
(
arg
.
strip
())
if
arg
.
find
(
' '
)
==-
1
and
arg
[
4
]
==
'-'
:
fields_iso8601
=
iso8601
and
iso8601
.
groupdict
()
or
{}
if
fields_iso8601
and
not
fields_iso8601
.
get
(
'garbage'
):
yr
,
mo
,
dy
,
hr
,
mn
,
sc
,
tz
=
self
.
_parse_iso8601
(
arg
)
yr
,
mo
,
dy
,
hr
,
mn
,
sc
,
tz
=
self
.
_parse_iso8601
(
arg
)
else
:
else
:
yr
,
mo
,
dy
,
hr
,
mn
,
sc
,
tz
=
self
.
_parse
(
arg
,
datefmt
)
yr
,
mo
,
dy
,
hr
,
mn
,
sc
,
tz
=
self
.
_parse
(
arg
,
datefmt
)
if
not
self
.
_validDate
(
yr
,
mo
,
dy
):
if
not
self
.
_validDate
(
yr
,
mo
,
dy
):
raise
DateError
,
'Invalid date: %s'
%
arg
raise
DateError
,
'Invalid date: %s'
%
arg
if
not
self
.
_validTime
(
hr
,
mn
,
int
(
sc
)):
if
not
self
.
_validTime
(
hr
,
mn
,
int
(
sc
)):
...
@@ -1018,10 +958,8 @@ class DateTime:
...
@@ -1018,10 +958,8 @@ class DateTime:
st
=
st
.
strip
()
st
=
st
.
strip
()
sp
=
st
.
split
()
sp
=
st
.
split
()
tz
=
sp
[
-
1
]
tz
=
sp
[
-
1
]
if
tz
and
(
tz
.
lower
()
in
ValidZones
):
if
tz
and
(
tz
.
lower
()
in
ValidZones
):
st
=
' '
.
join
(
sp
[:
-
1
])
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
=
[],[]
...
@@ -1031,8 +969,7 @@ class DateTime:
...
@@ -1031,8 +969,7 @@ class DateTime:
if
i
<
l
and
st
[
i
]
in
delimiters
:
if
i
<
l
and
st
[
i
]
in
delimiters
:
d
=
st
[
i
]
d
=
st
[
i
]
i
=
i
+
1
i
=
i
+
1
else
:
else
:
d
=
''
d
=
''
while
i
<
l
and
st
[
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
...
@@ -1064,6 +1001,7 @@ class DateTime:
...
@@ -1064,6 +1001,7 @@ class DateTime:
ints
.
append
(
v
)
ints
.
append
(
v
)
continue
continue
ts_results
=
wordpat
.
match
(
st
,
i
)
ts_results
=
wordpat
.
match
(
st
,
i
)
if
ts_results
:
if
ts_results
:
o
,
s
=
ts_results
.
group
(
0
),
ts_results
.
group
(
0
).
lower
()
o
,
s
=
ts_results
.
group
(
0
),
ts_results
.
group
(
0
).
lower
()
...
@@ -1176,6 +1114,7 @@ class DateTime:
...
@@ -1176,6 +1114,7 @@ class DateTime:
del
ints
[
0
]
del
ints
[
0
]
if
ints
:
raise
SyntaxError
,
st
if
ints
:
raise
SyntaxError
,
st
tod_int
=
int
(
math
.
floor
(
tod
))
tod_int
=
int
(
math
.
floor
(
tod
))
ms
=
tod
-
tod_int
ms
=
tod
-
tod_int
hr
,
mn
,
sc
=
_calcHMS
(
tod_int
,
ms
)
hr
,
mn
,
sc
=
_calcHMS
(
tod_int
,
ms
)
...
@@ -1188,39 +1127,36 @@ class DateTime:
...
@@ -1188,39 +1127,36 @@ class DateTime:
return
year
,
month
,
day
,
hr
,
mn
,
sc
,
tz
return
year
,
month
,
day
,
hr
,
mn
,
sc
,
tz
# Internal methods
# Internal methods
def
__getinitargs__
(
self
):
def
__getinitargs__
(
self
):
return
(
None
,)
return
(
None
,)
def
_validDate
(
self
,
y
,
m
,
d
):
def
_validDate
(
self
,
y
,
m
,
d
):
if
m
<
1
or
m
>
12
or
y
<
0
or
d
<
1
or
d
>
31
:
if
m
<
1
or
m
>
12
or
y
<
0
or
d
<
1
or
d
>
31
:
return
0
return
0
return
d
<=
self
.
_month_len
[(
y
%
4
==
0
and
(
y
%
100
!=
0
or
y
%
400
==
0
))][
m
]
return
d
<=
self
.
_month_len
[(
y
%
4
==
0
and
(
y
%
100
!=
0
or
y
%
400
==
0
))][
m
]
def
_validTime
(
self
,
h
,
m
,
s
):
def
_validTime
(
self
,
h
,
m
,
s
):
return
h
>=
0
and
h
<=
23
and
m
>=
0
and
m
<=
59
and
s
>=
0
and
s
<
60
return
h
>=
0
and
h
<=
23
and
m
>=
0
and
m
<=
59
and
s
>=
0
and
s
<
60
def
__getattr__
(
self
,
name
):
def
__getattr__
(
self
,
name
):
if
'%'
in
name
:
if
'%'
in
name
:
return
strftimeFormatter
(
self
,
name
)
return
strftimeFormatter
(
self
,
name
)
raise
AttributeError
,
name
raise
AttributeError
,
name
# Conversion and comparison methods
# Conversion and comparison methods
def
timeTime
(
self
):
def
timeTime
(
self
):
"""Return the date/time as a floating-point number in UTC,
"""Return the date/time as a floating-point number in UTC,
in the format used by the python time module.
in the format used by the python time module.
Note that it is possible to create date/time values
Note that it is possible to create date/time values with
with DateTime that have no meaningful value to the
DateTime that have no meaningful value to the time module.
time module."""
"""
return
self
.
_t
return
self
.
_t
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
[
z
.
lower
()]
t
,
tz
=
self
.
_t
,
self
.
_tzinfo
.
_zmap
[
z
.
lower
()]
millis
=
self
.
millis
()
millis
=
self
.
millis
()
#if (t>0 and ((t/86400.0) < 24837)):
try
:
try
:
# Try to use time module for speed.
# Try to use time module for speed.
yr
,
mo
,
dy
,
hr
,
mn
,
sc
=
safegmtime
(
t
+
_tzoffset
(
tz
,
t
))[:
6
]
yr
,
mo
,
dy
,
hr
,
mn
,
sc
=
safegmtime
(
t
+
_tzoffset
(
tz
,
t
))[:
6
]
...
@@ -1243,29 +1179,25 @@ class DateTime:
...
@@ -1243,29 +1179,25 @@ class DateTime:
def
isFuture
(
self
):
def
isFuture
(
self
):
"""Return true if this object represents a date/time
"""Return true if this object represents a date/time
later than the time of the call.
later than the time of the call"""
"""
return
(
self
.
_t
>
time
())
return
(
self
.
_t
>
time
())
def
isPast
(
self
):
def
isPast
(
self
):
"""Return true if this object represents a date/time
"""Return true if this object represents a date/time
earlier than the time of the call.
earlier than the time of the call"""
"""
return
(
self
.
_t
<
time
())
return
(
self
.
_t
<
time
())
def
isCurrentYear
(
self
):
def
isCurrentYear
(
self
):
"""Return true if this object represents a date/time
"""Return true if this object represents a date/time
that falls within the current year, in the context
that falls within the current year, in the context
of this object
\
'
s timezone representation.
of this object
\
'
s timezone representation"""
"""
t
=
time
()
t
=
time
()
return
safegmtime
(
t
+
_tzoffset
(
self
.
_tz
,
t
))[
0
]
==
self
.
_year
return
safegmtime
(
t
+
_tzoffset
(
self
.
_tz
,
t
))[
0
]
==
self
.
_year
def
isCurrentMonth
(
self
):
def
isCurrentMonth
(
self
):
"""Return true if this object represents a date/time
"""Return true if this object represents a date/time
that falls within the current month, in the context
that falls within the current month, in the context
of this object
\
'
s timezone representation.
of this object
\
'
s timezone representation"""
"""
t
=
time
()
t
=
time
()
gmt
=
safegmtime
(
t
+
_tzoffset
(
self
.
_tz
,
t
))
gmt
=
safegmtime
(
t
+
_tzoffset
(
self
.
_tz
,
t
))
return
gmt
[
0
]
==
self
.
_year
and
gmt
[
1
]
==
self
.
_month
return
gmt
[
0
]
==
self
.
_year
and
gmt
[
1
]
==
self
.
_month
...
@@ -1273,8 +1205,7 @@ class DateTime:
...
@@ -1273,8 +1205,7 @@ class DateTime:
def
isCurrentDay
(
self
):
def
isCurrentDay
(
self
):
"""Return true if this object represents a date/time
"""Return true if this object represents a date/time
that falls within the current day, in the context
that falls within the current day, in the context
of this object
\
'
s timezone representation.
of this object
\
'
s timezone representation"""
"""
t
=
time
()
t
=
time
()
gmt
=
safegmtime
(
t
+
_tzoffset
(
self
.
_tz
,
t
))
gmt
=
safegmtime
(
t
+
_tzoffset
(
self
.
_tz
,
t
))
return
gmt
[
0
]
==
self
.
_year
and
gmt
[
1
]
==
self
.
_month
and
gmt
[
2
]
==
self
.
_day
return
gmt
[
0
]
==
self
.
_year
and
gmt
[
1
]
==
self
.
_month
and
gmt
[
2
]
==
self
.
_day
...
@@ -1282,8 +1213,7 @@ class DateTime:
...
@@ -1282,8 +1213,7 @@ class DateTime:
def
isCurrentHour
(
self
):
def
isCurrentHour
(
self
):
"""Return true if this object represents a date/time
"""Return true if this object represents a date/time
that falls within the current hour, in the context
that falls within the current hour, in the context
of this object
\
'
s timezone representation.
of this object
\
'
s timezone representation"""
"""
t
=
time
()
t
=
time
()
gmt
=
safegmtime
(
t
+
_tzoffset
(
self
.
_tz
,
t
))
gmt
=
safegmtime
(
t
+
_tzoffset
(
self
.
_tz
,
t
))
return
(
gmt
[
0
]
==
self
.
_year
and
gmt
[
1
]
==
self
.
_month
and
return
(
gmt
[
0
]
==
self
.
_year
and
gmt
[
1
]
==
self
.
_month
and
...
@@ -1292,8 +1222,7 @@ class DateTime:
...
@@ -1292,8 +1222,7 @@ class DateTime:
def
isCurrentMinute
(
self
):
def
isCurrentMinute
(
self
):
"""Return true if this object represents a date/time
"""Return true if this object represents a date/time
that falls within the current minute, in the context
that falls within the current minute, in the context
of this object
\
'
s timezone representation.
of this object
\
'
s timezone representation"""
"""
t
=
time
()
t
=
time
()
gmt
=
safegmtime
(
t
+
_tzoffset
(
self
.
_tz
,
t
))
gmt
=
safegmtime
(
t
+
_tzoffset
(
self
.
_tz
,
t
))
return
(
gmt
[
0
]
==
self
.
_year
and
gmt
[
1
]
==
self
.
_month
and
return
(
gmt
[
0
]
==
self
.
_year
and
gmt
[
1
]
==
self
.
_month
and
...
@@ -1303,26 +1232,22 @@ class DateTime:
...
@@ -1303,26 +1232,22 @@ class DateTime:
def
earliestTime
(
self
):
def
earliestTime
(
self
):
"""Return a new DateTime object that represents the earliest
"""Return a new DateTime object that represents the earliest
possible time (in whole seconds) that still falls within
possible time (in whole seconds) that still falls within
the current object
\
'
s day, in the object
\
'
s timezone context.
the current object
\
'
s day, in the object
\
'
s timezone context"""
"""
return
self
.
__class__
(
self
.
_year
,
self
.
_month
,
self
.
_day
,
0
,
0
,
0
,
self
.
_tz
)
return
self
.
__class__
(
self
.
_year
,
self
.
_month
,
self
.
_day
,
0
,
0
,
0
,
self
.
_tz
)
def
latestTime
(
self
):
def
latestTime
(
self
):
"""Return a new DateTime object that represents the latest
"""Return a new DateTime object that represents the latest
possible time (in whole seconds) that still falls within
possible time (in whole seconds) that still falls within
the current object
\
'
s day, in the object
\
'
s timezone context.
the current object
\
'
s day, in the object
\
'
s timezone context"""
"""
return
self
.
__class__
(
self
.
_year
,
self
.
_month
,
self
.
_day
,
return
self
.
__class__
(
self
.
_year
,
self
.
_month
,
self
.
_day
,
23
,
59
,
59
,
self
.
_tz
)
23
,
59
,
59
,
self
.
_tz
)
def
greaterThan
(
self
,
t
):
def
greaterThan
(
self
,
t
):
"""Compare this DateTime object to another DateTime object
"""Compare this DateTime object to another DateTime object
OR a floating point number such as that which is returned
OR a floating point number such as that which is returned
by the python time module.
by the python time module. Returns true if the object
represents a date/time greater than the specified DateTime
Returns true if the object represents a date/time greater
or time module style time.
than the specified DateTime or time module style time.
Revised to give more correct results through comparison of
Revised to give more correct results through comparison of
long integer milliseconds.
long integer milliseconds.
"""
"""
...
@@ -1339,12 +1264,9 @@ class DateTime:
...
@@ -1339,12 +1264,9 @@ class DateTime:
def
greaterThanEqualTo
(
self
,
t
):
def
greaterThanEqualTo
(
self
,
t
):
"""Compare this DateTime object to another DateTime object
"""Compare this DateTime object to another DateTime object
OR a floating point number such as that which is returned
OR a floating point number such as that which is returned
by the python time module.
by the python time module. Returns true if the object
represents a date/time greater than or equal to the
Returns true if the object represents a date/time greater
specified DateTime or time module style time.
than or equal to the specified DateTime or time module style
time.
Revised to give more correct results through comparison of
Revised to give more correct results through comparison of
long integer milliseconds.
long integer milliseconds.
"""
"""
...
@@ -1361,11 +1283,9 @@ class DateTime:
...
@@ -1361,11 +1283,9 @@ class DateTime:
def
equalTo
(
self
,
t
):
def
equalTo
(
self
,
t
):
"""Compare this DateTime object to another DateTime object
"""Compare this DateTime object to another DateTime object
OR a floating point number such as that which is returned
OR a floating point number such as that which is returned
by the python time module.
by the python time module. Returns true if the object
represents a date/time equal to the specified DateTime
Returns true if the object represents a date/time equal to
or time module style time.
the specified DateTime or time module style time.
Revised to give more correct results through comparison of
Revised to give more correct results through comparison of
long integer milliseconds.
long integer milliseconds.
"""
"""
...
@@ -1382,11 +1302,9 @@ class DateTime:
...
@@ -1382,11 +1302,9 @@ class DateTime:
def
notEqualTo
(
self
,
t
):
def
notEqualTo
(
self
,
t
):
"""Compare this DateTime object to another DateTime object
"""Compare this DateTime object to another DateTime object
OR a floating point number such as that which is returned
OR a floating point number such as that which is returned
by the python time module.
by the python time module. Returns true if the object
represents a date/time not equal to the specified DateTime
Returns true if the object represents a date/time not equal
or time module style time.
to the specified DateTime or time module style time.
Revised to give more correct results through comparison of
Revised to give more correct results through comparison of
long integer milliseconds.
long integer milliseconds.
"""
"""
...
@@ -1403,11 +1321,9 @@ class DateTime:
...
@@ -1403,11 +1321,9 @@ class DateTime:
def
lessThan
(
self
,
t
):
def
lessThan
(
self
,
t
):
"""Compare this DateTime object to another DateTime object
"""Compare this DateTime object to another DateTime object
OR a floating point number such as that which is returned
OR a floating point number such as that which is returned
by the python time module.
by the python time module. Returns true if the object
represents a date/time less than the specified DateTime
Returns true if the object represents a date/time less than
or time module style time.
the specified DateTime or time module style time.
Revised to give more correct results through comparison of
Revised to give more correct results through comparison of
long integer milliseconds.
long integer milliseconds.
"""
"""
...
@@ -1424,11 +1340,9 @@ class DateTime:
...
@@ -1424,11 +1340,9 @@ class DateTime:
def
lessThanEqualTo
(
self
,
t
):
def
lessThanEqualTo
(
self
,
t
):
"""Compare this DateTime object to another DateTime object
"""Compare this DateTime object to another DateTime object
OR a floating point number such as that which is returned
OR a floating point number such as that which is returned
by the python time module.
by the python time module. Returns true if the object
represents a date/time less than or equal to the specified
Returns true if the object represents a date/time less than
DateTime or time module style time.
or equal to the specified DateTime or time module style time.
Revised to give more correct results through comparison of
Revised to give more correct results through comparison of
long integer milliseconds.
long integer milliseconds.
"""
"""
...
@@ -1443,15 +1357,13 @@ class DateTime:
...
@@ -1443,15 +1357,13 @@ class DateTime:
__le__
=
lessThanEqualTo
__le__
=
lessThanEqualTo
def
isLeapYear
(
self
):
def
isLeapYear
(
self
):
"""Return true if the current year (in the context of the
"""Return true if the current year (in the context of the object
\
'
s
object
\
'
s timezone) is a leap year.
timezone) is a leap year"""
"""
return
self
.
_year
%
4
==
0
and
(
self
.
_year
%
100
!=
0
or
self
.
_year
%
400
==
0
)
return
self
.
_year
%
4
==
0
and
(
self
.
_year
%
100
!=
0
or
self
.
_year
%
400
==
0
)
def
dayOfYear
(
self
):
def
dayOfYear
(
self
):
"""Return the day of the year, in context of the timezone
"""Return the day of the year, in context of
representation of the object.
the timezone representation of the object"""
"""
d
=
int
(
self
.
_d
+
(
_tzoffset
(
self
.
_tz
,
self
.
_t
)
/
86400.0
))
d
=
int
(
self
.
_d
+
(
_tzoffset
(
self
.
_tz
,
self
.
_t
)
/
86400.0
))
return
int
((
d
+
jd1901
)
-
_julianday
(
self
.
_year
,
1
,
0
))
return
int
((
d
+
jd1901
)
-
_julianday
(
self
.
_year
,
1
,
0
))
...
@@ -1459,8 +1371,7 @@ class DateTime:
...
@@ -1459,8 +1371,7 @@ class DateTime:
# Component access
# Component access
def
parts
(
self
):
def
parts
(
self
):
"""Return a tuple containing the calendar year, month,
"""Return a tuple containing the calendar year, month,
day, hour, minute second and timezone of the object.
day, hour, minute second and timezone of the object"""
"""
return
self
.
_year
,
self
.
_month
,
self
.
_day
,
self
.
_hour
,
\
return
self
.
_year
,
self
.
_month
,
self
.
_day
,
self
.
_hour
,
\
self
.
_minute
,
self
.
_second
,
self
.
_tz
self
.
_minute
,
self
.
_second
,
self
.
_tz
...
@@ -1473,15 +1384,15 @@ class DateTime:
...
@@ -1473,15 +1384,15 @@ class DateTime:
return
_tzoffset
(
self
.
_tz
,
self
.
_t
)
return
_tzoffset
(
self
.
_tz
,
self
.
_t
)
def
year
(
self
):
def
year
(
self
):
"""Return the calendar year of the object
.
"""
"""Return the calendar year of the object"""
return
self
.
_year
return
self
.
_year
def
month
(
self
):
def
month
(
self
):
"""Return the month of the object as an integer
.
"""
"""Return the month of the object as an integer"""
return
self
.
_month
return
self
.
_month
def
Month
(
self
):
def
Month
(
self
):
"""Return the full month name
.
"""
"""Return the full month name"""
return
self
.
_fmon
return
self
.
_fmon
def
aMonth
(
self
):
def
aMonth
(
self
):
...
@@ -1489,7 +1400,7 @@ class DateTime:
...
@@ -1489,7 +1400,7 @@ class DateTime:
return
self
.
_amon
return
self
.
_amon
def
Mon
(
self
):
def
Mon
(
self
):
"""Compatibility: see aMonth
.
"""
"""Compatibility: see aMonth"""
return
self
.
_amon
return
self
.
_amon
def
pMonth
(
self
):
def
pMonth
(
self
):
...
@@ -1497,63 +1408,63 @@ class DateTime:
...
@@ -1497,63 +1408,63 @@ class DateTime:
return
self
.
_pmon
return
self
.
_pmon
def
Mon_
(
self
):
def
Mon_
(
self
):
"""Compatibility: see pMonth
.
"""
"""Compatibility: see pMonth"""
return
self
.
_pmon
return
self
.
_pmon
def
day
(
self
):
def
day
(
self
):
"""Return the integer day
.
"""
"""Return the integer day"""
return
self
.
_day
return
self
.
_day
def
Day
(
self
):
def
Day
(
self
):
"""Return the full name of the day of the week
.
"""
"""Return the full name of the day of the week"""
return
self
.
_fday
return
self
.
_fday
def
DayOfWeek
(
self
):
def
DayOfWeek
(
self
):
"""Compatibility: see Day
.
"""
"""Compatibility: see Day"""
return
self
.
_fday
return
self
.
_fday
def
aDay
(
self
):
def
aDay
(
self
):
"""Return the abreviated name of the day of the week
.
"""
"""Return the abreviated name of the day of the week"""
return
self
.
_aday
return
self
.
_aday
def
pDay
(
self
):
def
pDay
(
self
):
"""Return the abreviated (with period) name of the day of the week
.
"""
"""Return the abreviated (with period) name of the day of the week"""
return
self
.
_pday
return
self
.
_pday
def
Day_
(
self
):
def
Day_
(
self
):
"""Compatibility: see pDay
.
"""
"""Compatibility: see pDay"""
return
self
.
_pday
return
self
.
_pday
def
dow
(
self
):
def
dow
(
self
):
"""Return the integer day of the week, where sunday is 0
.
"""
"""Return the integer day of the week, where sunday is 0"""
return
self
.
_dayoffset
return
self
.
_dayoffset
def
dow_1
(
self
):
def
dow_1
(
self
):
"""Return the integer day of the week, where sunday is 1
.
"""
"""Return the integer day of the week, where sunday is 1"""
return
self
.
_dayoffset
+
1
return
self
.
_dayoffset
+
1
def
h_12
(
self
):
def
h_12
(
self
):
"""Return the 12-hour clock representation of the hour
.
"""
"""Return the 12-hour clock representation of the hour"""
return
self
.
_pmhour
return
self
.
_pmhour
def
h_24
(
self
):
def
h_24
(
self
):
"""Return the 24-hour clock representation of the hour
.
"""
"""Return the 24-hour clock representation of the hour"""
return
self
.
_hour
return
self
.
_hour
def
ampm
(
self
):
def
ampm
(
self
):
"""Return the appropriate time modifier (am or pm)
.
"""
"""Return the appropriate time modifier (am or pm)"""
return
self
.
_pm
return
self
.
_pm
def
hour
(
self
):
def
hour
(
self
):
"""Return the 24-hour clock representation of the hour
.
"""
"""Return the 24-hour clock representation of the hour"""
return
self
.
_hour
return
self
.
_hour
def
minute
(
self
):
def
minute
(
self
):
"""Return the minute
.
"""
"""Return the minute"""
return
self
.
_minute
return
self
.
_minute
def
second
(
self
):
def
second
(
self
):
"""Return the second
.
"""
"""Return the second"""
return
self
.
_second
return
self
.
_second
def
millis
(
self
):
def
millis
(
self
):
...
@@ -1570,7 +1481,7 @@ class DateTime:
...
@@ -1570,7 +1481,7 @@ class DateTime:
return
millis
return
millis
def
strftime
(
self
,
format
):
def
strftime
(
self
,
format
):
"""Format the date/time using the *current timezone representation*."""
# Format the date/time using the *current timezone representation*.
x
=
_calcDependentSecond2
(
self
.
_year
,
self
.
_month
,
self
.
_day
,
x
=
_calcDependentSecond2
(
self
.
_year
,
self
.
_month
,
self
.
_day
,
self
.
_hour
,
self
.
_minute
,
self
.
_second
)
self
.
_hour
,
self
.
_minute
,
self
.
_second
)
ltz
=
self
.
_calcTimezoneName
(
x
,
0
)
ltz
=
self
.
_calcTimezoneName
(
x
,
0
)
...
@@ -1592,6 +1503,7 @@ class DateTime:
...
@@ -1592,6 +1503,7 @@ class DateTime:
microseconds
).
strftime
(
format
)
microseconds
).
strftime
(
format
)
return
format_is_unicode
and
unicode
(
ds
,
'utf-8'
)
or
ds
return
format_is_unicode
and
unicode
(
ds
,
'utf-8'
)
or
ds
# General formats from previous DateTime
# General formats from previous DateTime
def
Date
(
self
):
def
Date
(
self
):
"""Return the date string for the object."""
"""Return the date string for the object."""
...
@@ -1624,20 +1536,21 @@ class DateTime:
...
@@ -1624,20 +1536,21 @@ class DateTime:
self
.
_pmhour
,
self
.
_minute
,
self
.
_second
,
self
.
_pm
)
self
.
_pmhour
,
self
.
_minute
,
self
.
_second
,
self
.
_pm
)
def
yy
(
self
):
def
yy
(
self
):
"""Return calendar year as a 2 digit string
.
"""
"""Return calendar year as a 2 digit string"""
return
str
(
self
.
_year
)[
-
2
:]
return
str
(
self
.
_year
)[
-
2
:]
def
mm
(
self
):
def
mm
(
self
):
"""Return month as a 2 digit string
.
"""
"""Return month as a 2 digit string"""
return
'%02d'
%
self
.
_month
return
'%02d'
%
self
.
_month
def
dd
(
self
):
def
dd
(
self
):
"""Return day as a 2 digit string
.
"""
"""Return day as a 2 digit string"""
return
'%02d'
%
self
.
_day
return
'%02d'
%
self
.
_day
def
rfc822
(
self
):
def
rfc822
(
self
):
"""Return the date in RFC 822 format
.
"""
"""Return the date in RFC 822 format"""
tzoffset
=
_tzoffset2rfc822zone
(
_tzoffset
(
self
.
_tz
,
self
.
_t
))
tzoffset
=
_tzoffset2rfc822zone
(
_tzoffset
(
self
.
_tz
,
self
.
_t
))
return
'%s, %2.2d %s %d %2.2d:%2.2d:%2.2d %s'
%
(
return
'%s, %2.2d %s %d %2.2d:%2.2d:%2.2d %s'
%
(
self
.
_aday
,
self
.
_day
,
self
.
_amon
,
self
.
_year
,
self
.
_aday
,
self
.
_day
,
self
.
_amon
,
self
.
_year
,
self
.
_hour
,
self
.
_minute
,
self
.
_nearsec
,
tzoffset
)
self
.
_hour
,
self
.
_minute
,
self
.
_nearsec
,
tzoffset
)
...
@@ -1645,57 +1558,51 @@ class DateTime:
...
@@ -1645,57 +1558,51 @@ class DateTime:
# New formats
# New formats
def
fCommon
(
self
):
def
fCommon
(
self
):
"""Return a string representing the object
\
'
s value
"""Return a string representing the object
\
'
s value
in the format: March 1, 1997 1:45 pm.
in the format: March 1, 1997 1:45 pm"""
"""
return
'%s %s, %4.4d %s:%2.2d %s'
%
(
return
'%s %s, %4.4d %s:%2.2d %s'
%
(
self
.
_fmon
,
self
.
_day
,
self
.
_year
,
self
.
_pmhour
,
self
.
_fmon
,
self
.
_day
,
self
.
_year
,
self
.
_pmhour
,
self
.
_minute
,
self
.
_pm
)
self
.
_minute
,
self
.
_pm
)
def
fCommonZ
(
self
):
def
fCommonZ
(
self
):
"""Return a string representing the object
\
'
s value
"""Return a string representing the object
\
'
s value
in the format: March 1, 1997 1:45 pm US/Eastern.
in the format: March 1, 1997 1:45 pm US/Eastern"""
"""
return
'%s %s, %4.4d %d:%2.2d %s %s'
%
(
return
'%s %s, %4.4d %d:%2.2d %s %s'
%
(
self
.
_fmon
,
self
.
_day
,
self
.
_year
,
self
.
_pmhour
,
self
.
_fmon
,
self
.
_day
,
self
.
_year
,
self
.
_pmhour
,
self
.
_minute
,
self
.
_pm
,
self
.
_tz
)
self
.
_minute
,
self
.
_pm
,
self
.
_tz
)
def
aCommon
(
self
):
def
aCommon
(
self
):
"""Return a string representing the object
\
'
s value
"""Return a string representing the object
\
'
s value
in the format: Mar 1, 1997 1:45 pm.
in the format: Mar 1, 1997 1:45 pm"""
"""
return
'%s %s, %4.4d %s:%2.2d %s'
%
(
return
'%s %s, %4.4d %s:%2.2d %s'
%
(
self
.
_amon
,
self
.
_day
,
self
.
_year
,
self
.
_pmhour
,
self
.
_amon
,
self
.
_day
,
self
.
_year
,
self
.
_pmhour
,
self
.
_minute
,
self
.
_pm
)
self
.
_minute
,
self
.
_pm
)
def
aCommonZ
(
self
):
def
aCommonZ
(
self
):
"""Return a string representing the object
\
'
s value
"""Return a string representing the object
\
'
s value
in the format: Mar 1, 1997 1:45 pm US/Eastern.
in the format: Mar 1, 1997 1:45 pm US/Eastern"""
"""
return
'%s %s, %4.4d %d:%2.2d %s %s'
%
(
return
'%s %s, %4.4d %d:%2.2d %s %s'
%
(
self
.
_amon
,
self
.
_day
,
self
.
_year
,
self
.
_pmhour
,
self
.
_amon
,
self
.
_day
,
self
.
_year
,
self
.
_pmhour
,
self
.
_minute
,
self
.
_pm
,
self
.
_tz
)
self
.
_minute
,
self
.
_pm
,
self
.
_tz
)
def
pCommon
(
self
):
def
pCommon
(
self
):
"""Return a string representing the object
\
'
s value
"""Return a string representing the object
\
'
s value
in the format: Mar. 1, 1997 1:45 pm.
in the format: Mar. 1, 1997 1:45 pm"""
"""
return
'%s %s, %4.4d %s:%2.2d %s'
%
(
return
'%s %s, %4.4d %s:%2.2d %s'
%
(
self
.
_pmon
,
self
.
_day
,
self
.
_year
,
self
.
_pmhour
,
self
.
_pmon
,
self
.
_day
,
self
.
_year
,
self
.
_pmhour
,
self
.
_minute
,
self
.
_pm
)
self
.
_minute
,
self
.
_pm
)
def
pCommonZ
(
self
):
def
pCommonZ
(
self
):
"""Return a string representing the object
\
'
s value
"""Return a string representing the object
\
'
s value
in the format: Mar. 1, 1997 1:45 pm US/Eastern.
in the format: Mar. 1, 1997 1:45 pm US/Eastern"""
"""
return
'%s %s, %4.4d %d:%2.2d %s %s'
%
(
return
'%s %s, %4.4d %d:%2.2d %s %s'
%
(
self
.
_pmon
,
self
.
_day
,
self
.
_year
,
self
.
_pmhour
,
self
.
_pmon
,
self
.
_day
,
self
.
_year
,
self
.
_pmhour
,
self
.
_minute
,
self
.
_pm
,
self
.
_tz
)
self
.
_minute
,
self
.
_pm
,
self
.
_tz
)
def
ISO
(
self
):
"""Return the object in ISO standard format.
Note: this is *not* ISO 8601-format! See the ISO8601 and
def
ISO
(
self
):
HTML4 methods below for ISO 8601-compliant output.
"""Return the object in ISO standard format. Note:
this is *not* ISO 8601-format! See the ISO8601 and
HTML4 methods below for ISO 8601-compliant output
Dates are output as: YYYY-MM-DD HH:MM:SS
Dates are output as: YYYY-MM-DD HH:MM:SS
"""
"""
...
@@ -1704,33 +1611,33 @@ class DateTime:
...
@@ -1704,33 +1611,33 @@ class DateTime:
self
.
_hour
,
self
.
_minute
,
self
.
_second
)
self
.
_hour
,
self
.
_minute
,
self
.
_second
)
def
ISO8601
(
self
):
def
ISO8601
(
self
):
"""Return the object in ISO 8601-compatible format containing the
"""Return the object in ISO 8601-compatible format containing
date, time with seconds-precision and the time zone identifier.
the date, time with seconds-precision and the time zone
identifier - see http://www.w3.org/TR/NOTE-datetime
See: http://www.w3.org/TR/NOTE-datetime
Dates are output as: YYYY-MM-DDTHH:MM:SSTZD
Dates are output as: YYYY-MM-DDTHH:MM:SSTZD
T is a literal character.
T is a literal character.
TZD is Time Zone Designator, format +HH:MM or -HH:MM
TZD is Time Zone Designator, format +HH:MM or -HH:MM
The HTML4 method below offers the same formatting, but converts
The HTML4 method below offers the same formatting, but converts
to UTC before returning the value and sets the TZD "Z"
.
to UTC before returning the value and sets the TZD "Z"
"""
"""
tzoffset
=
_tzoffset2iso8601zone
(
_tzoffset
(
self
.
_tz
,
self
.
_t
))
tzoffset
=
_tzoffset2iso8601zone
(
_tzoffset
(
self
.
_tz
,
self
.
_t
))
return
"%0.4d-%0.2d-%0.2dT%0.2d:%0.2d:%0.2d%s"
%
(
return
"%0.4d-%0.2d-%0.2dT%0.2d:%0.2d:%0.2d%s"
%
(
self
.
_year
,
self
.
_month
,
self
.
_day
,
self
.
_year
,
self
.
_month
,
self
.
_day
,
self
.
_hour
,
self
.
_minute
,
self
.
_second
,
tzoffset
)
self
.
_hour
,
self
.
_minute
,
self
.
_second
,
tzoffset
)
def
HTML4
(
self
):
def
HTML4
(
self
):
"""Return the object in the format used in the HTML4.0 specification,
"""Return the object in the format used in the HTML4.0 specification,
one of the standard forms in ISO8601.
one of the standard forms in ISO8601. See
http://www.w3.org/TR/NOTE-datetime
See: http://www.w3.org/TR/NOTE-datetime
Dates are output as: YYYY-MM-DDTHH:MM:SSZ
Dates are output as: YYYY-MM-DDTHH:MM:SSZ
T, Z are literal characters.
T, Z are literal characters.
The time is in UTC.
The time is in UTC.
"""
"""
newdate
=
self
.
toZone
(
'UTC'
)
newdate
=
self
.
toZone
(
'UTC'
)
return
"%0.4d-%0.2d-%0.2dT%0.2d:%0.2d:%0.2dZ"
%
(
return
"%0.4d-%0.2d-%0.2dT%0.2d:%0.2d:%0.2dZ"
%
(
newdate
.
_year
,
newdate
.
_month
,
newdate
.
_day
,
newdate
.
_year
,
newdate
.
_month
,
newdate
.
_day
,
...
@@ -1738,8 +1645,7 @@ class DateTime:
...
@@ -1738,8 +1645,7 @@ class DateTime:
def
__add__
(
self
,
other
):
def
__add__
(
self
,
other
):
"""A DateTime may be added to a number and a number may be
"""A DateTime may be added to a number and a number may be
added to a DateTime; two DateTimes cannot be added.
added to a DateTime; two DateTimes cannot be added."""
"""
if
hasattr
(
other
,
'_t'
):
if
hasattr
(
other
,
'_t'
):
raise
DateTimeError
,
'Cannot add two DateTimes'
raise
DateTimeError
,
'Cannot add two DateTimes'
o
=
float
(
other
)
o
=
float
(
other
)
...
@@ -1751,14 +1657,12 @@ class DateTime:
...
@@ -1751,14 +1657,12 @@ class DateTime:
x
=
_calcDependentSecond
(
tz
,
t
)
x
=
_calcDependentSecond
(
tz
,
t
)
yr
,
mo
,
dy
,
hr
,
mn
,
sc
=
_calcYMDHMS
(
x
,
ms
)
yr
,
mo
,
dy
,
hr
,
mn
,
sc
=
_calcYMDHMS
(
x
,
ms
)
return
self
.
__class__
(
yr
,
mo
,
dy
,
hr
,
mn
,
sc
,
self
.
_tz
,
t
,
d
,
s
)
return
self
.
__class__
(
yr
,
mo
,
dy
,
hr
,
mn
,
sc
,
self
.
_tz
,
t
,
d
,
s
)
__radd__
=
__add__
__radd__
=
__add__
def
__sub__
(
self
,
other
):
def
__sub__
(
self
,
other
):
"""Either a DateTime or a number may be subtracted from a
"""Either a DateTime or a number may be subtracted from a
DateTime, however, a DateTime may not be subtracted from
DateTime, however, a DateTime may not be subtracted from
a number.
a number."""
"""
if
hasattr
(
other
,
'_d'
):
if
hasattr
(
other
,
'_d'
):
if
0
:
# This logic seems right but is incorrect.
if
0
:
# This logic seems right but is incorrect.
my_t
=
self
.
_t
+
_tzoffset
(
self
.
_tz
,
self
.
_t
)
my_t
=
self
.
_t
+
_tzoffset
(
self
.
_tz
,
self
.
_t
)
...
@@ -1769,15 +1673,14 @@ class DateTime:
...
@@ -1769,15 +1673,14 @@ class DateTime:
return
self
.
__add__
(
-
(
other
))
return
self
.
__add__
(
-
(
other
))
def
__repr__
(
self
):
def
__repr__
(
self
):
"""Convert a DateTime to a string that looks like a Python
"""Convert a DateTime to a string that
expression.
looks like a Python expression."""
"""
return
'%s(
\
'
%s
\
'
)'
%
(
self
.
__class__
.
__name__
,
str
(
self
))
return
'%s(
\
'
%s
\
'
)'
%
(
self
.
__class__
.
__name__
,
str
(
self
))
def
__str__
(
self
):
def
__str__
(
self
):
"""Convert a DateTime to a string."""
"""Convert a DateTime to a string."""
y
,
m
,
d
=
self
.
_year
,
self
.
_month
,
self
.
_day
y
,
m
,
d
=
self
.
_year
,
self
.
_month
,
self
.
_day
h
,
mn
,
s
,
t
=
self
.
_hour
,
self
.
_minute
,
self
.
_second
,
self
.
_tz
h
,
mn
,
s
,
t
=
self
.
_hour
,
self
.
_minute
,
self
.
_second
,
self
.
_tz
if
h
==
mn
==
s
==
0
:
if
h
==
mn
==
s
==
0
:
# hh:mm:ss all zero -- suppress the time.
# hh:mm:ss all zero -- suppress the time.
return
'%4.4d/%2.2d/%2.2d'
%
(
y
,
m
,
d
)
return
'%4.4d/%2.2d/%2.2d'
%
(
y
,
m
,
d
)
...
@@ -1793,17 +1696,15 @@ class DateTime:
...
@@ -1793,17 +1696,15 @@ class DateTime:
y
,
m
,
d
,
h
,
mn
,
s
,
t
)
y
,
m
,
d
,
h
,
mn
,
s
,
t
)
def
__cmp__
(
self
,
obj
):
def
__cmp__
(
self
,
obj
):
"""Compare a DateTime with another DateTime object, or a
"""Compare a DateTime with another DateTime object, or
float such as those returned by time.time().
a float such as those returned by time.time().
NOTE: __cmp__ support is provided for backward compatibility
NOTE: __cmp__ support is provided for backward
only, and mixing DateTimes with ExtensionClasses could cause
compatibility only, and mixing DateTimes with
__cmp__ to break.
ExtensionClasses could cause __cmp__ to break.
You should use the methods lessThan, greaterThan,
You should use the methods lessThan, greaterThan, lessThanEqualTo,
lessThanEqualTo, greaterThanEqualTo, equalTo and
greaterThanEqualTo, equalTo and notEqualTo to avoid potential
notEqualTo to avoid potential problems later!!"""
problems later!
"""
# Optimized for sorting speed.
# Optimized for sorting speed.
try
:
try
:
return
cmp
(
self
.
_millis
,
obj
.
_millis
)
return
cmp
(
self
.
_millis
,
obj
.
_millis
)
...
@@ -1813,20 +1714,20 @@ class DateTime:
...
@@ -1813,20 +1714,20 @@ class DateTime:
return
cmp
(
self
.
_t
,
obj
)
return
cmp
(
self
.
_t
,
obj
)
def
__hash__
(
self
):
def
__hash__
(
self
):
"""Compute a hash value for a DateTime
.
"""
"""Compute a hash value for a DateTime"""
return
int
(((
self
.
_year
%
100
*
12
+
self
.
_month
)
*
31
+
return
int
(((
self
.
_year
%
100
*
12
+
self
.
_month
)
*
31
+
self
.
_day
+
self
.
time
)
*
100
)
self
.
_day
+
self
.
time
)
*
100
)
def
__int__
(
self
):
def
__int__
(
self
):
"""Convert to an integer number of seconds since the epoch (gmt)
.
"""
"""Convert to an integer number of seconds since the epoch (gmt)"""
return
int
(
self
.
millis
()
/
1000
)
return
int
(
self
.
millis
()
/
1000
)
def
__long__
(
self
):
def
__long__
(
self
):
"""Convert to a long-int number of seconds since the epoch (gmt)
.
"""
"""Convert to a long-int number of seconds since the epoch (gmt)"""
return
long
(
self
.
millis
()
/
1000
)
return
long
(
self
.
millis
()
/
1000
)
def
__float__
(
self
):
def
__float__
(
self
):
"""Convert to floating-point number of seconds since the epoch (gmt)
.
"""
"""Convert to floating-point number of seconds since the epoch (gmt)"""
return
float
(
self
.
_t
)
return
float
(
self
.
_t
)
def
_parse_iso8601
(
self
,
s
):
def
_parse_iso8601
(
self
,
s
):
...
@@ -1837,75 +1738,56 @@ class DateTime:
...
@@ -1837,75 +1738,56 @@ class DateTime:
'Not an ISO 8601 compliant date string: "%s"'
%
s
)
'Not an ISO 8601 compliant date string: "%s"'
%
s
)
def
__parse_iso8601
(
self
,
s
):
def
__parse_iso8601
(
self
,
s
):
"""Parse an ISO 8601 compliant date.
""" parse an ISO 8601 compliant date """
year
=
0
See: http://www.omg.org/docs/ISO-stds/06-08-01.pdf
month
=
day
=
1
"""
hour
=
minute
=
seconds
=
hour_off
=
min_off
=
0
month
=
day
=
week_day
=
1
year
=
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
(
'T([0-9]{2})(:([0-9][0-9]))?(:([0-9][0-9]))?(
\
.[
0
-9]{1,20})?'
)
zonereg
=
re
.
compile
(
'([+-][0-9][0-9])(:?([0-9][0-9]))'
)
# Date part
fields
=
datereg
.
split
(
s
.
strip
(),
1
)
if
fields
[
1
]:
year
=
int
(
fields
[
1
])
if
fields
[
3
]:
month
=
int
(
fields
[
3
])
if
fields
[
5
]:
day
=
int
(
fields
[
5
])
t
=
fields
[
6
]
if
t
:
if
not
fields
[
5
]:
# Specifying time requires specifying a day.
raise
IndexError
iso8601
=
iso8601Match
(
s
.
strip
())
fields
=
timereg
.
split
(
t
)
fields
=
iso8601
and
iso8601
.
groupdict
()
or
{}
if
not
iso8601
or
fields
.
get
(
'garbage'
):
if
fields
[
1
]:
hour
=
int
(
fields
[
1
])
if
fields
[
3
]:
minute
=
int
(
fields
[
3
])
if
fields
[
5
]:
seconds
=
int
(
fields
[
5
])
if
fields
[
6
]:
seconds
=
seconds
+
float
(
fields
[
6
])
z
=
fields
[
7
]
if
z
and
z
.
startswith
(
'Z'
):
# Waaaa! This is wrong, since 'Z' and '+HH:MM'
# are supposed to be mutually exclusive.
# It's only here to prevent breaking 2.7 beta.
z
=
z
[
1
:]
if
z
:
fields
=
zonereg
.
split
(
z
)
hour_off
=
int
(
fields
[
1
])
min_off
=
int
(
fields
[
3
])
if
fields
[
4
]:
# Garbage after time zone
raise
IndexError
raise
IndexError
if
fields
[
'year'
]:
return
year
,
month
,
day
,
hour
,
minute
,
seconds
,
'GMT%+03d%02d'
%
(
hour_off
,
min_off
)
year
=
int
(
fields
[
'year'
])
if
fields
[
'month'
]:
month
=
int
(
fields
[
'month'
])
if
fields
[
'day'
]:
day
=
int
(
fields
[
'day'
])
if
fields
[
'year_day'
]:
d
=
DateTime
(
'%s-01-01'
%
year
)
+
int
(
fields
[
'year_day'
])
-
1
month
=
d
.
month
()
day
=
d
.
day
()
if
fields
[
'week'
]:
week
=
int
(
fields
[
'week'
])
if
fields
[
'week_day'
]:
week_day
=
int
(
fields
[
'week_day'
])
d
=
DateTime
(
'%s-01-04'
%
year
)
d
=
d
-
(
d
.
dow
()
+
6
)
%
7
+
week
*
7
+
week_day
-
8
month
=
d
.
month
()
day
=
d
.
day
()
if
fields
[
'hour'
]:
hour
=
int
(
fields
[
'hour'
])
if
fields
[
'minute'
]:
minute
=
int
(
fields
[
'minute'
])
elif
fields
[
'fraction'
]:
minute
=
60.0
*
float
(
'0.%s'
%
fields
[
'fraction'
])
seconds
,
minute
=
math
.
modf
(
minute
)
minute
=
int
(
minute
)
seconds
=
60.0
*
seconds
# Avoid reprocess when handling seconds, bellow
fields
[
'fraction'
]
=
None
if
fields
[
'second'
]:
seconds
=
int
(
fields
[
'second'
])
if
fields
[
'fraction'
]:
seconds
=
seconds
+
float
(
'0.%s'
%
fields
[
'fraction'
])
elif
fields
[
'fraction'
]:
seconds
=
60.0
*
float
(
'0.%s'
%
fields
[
'fraction'
])
if
fields
[
'hour_off'
]:
hour_off
=
int
(
fields
[
'hour_off'
])
if
fields
[
'signal'
]
==
'-'
:
hour_off
*=
-
1
if
fields
[
'min_off'
]:
min_off
=
int
(
fields
[
'min_off'
])
tz
=
'GMT%+03d%02d'
%
(
hour_off
,
min_off
)
return
year
,
month
,
day
,
hour
,
minute
,
seconds
,
tz
def
JulianDay
(
self
):
def
JulianDay
(
self
):
"""
Return the Julian day.
"""
Return the Julian day according to
See:
http://www.tondering.dk/claus/cal/node3.html#sec-calcjd
http://www.tondering.dk/claus/cal/node3.html#sec-calcjd
"""
"""
a
=
(
14
-
self
.
_month
)
/
12
#integer division, discard remainder
a
=
(
14
-
self
.
_month
)
/
12
#integer division, discard remainder
y
=
self
.
_year
+
4800
-
a
y
=
self
.
_year
+
4800
-
a
...
@@ -1913,9 +1795,9 @@ class DateTime:
...
@@ -1913,9 +1795,9 @@ class DateTime:
return
self
.
_day
+
(
153
*
m
+
2
)
/
5
+
365
*
y
+
y
/
4
-
y
/
100
+
y
/
400
-
32045
return
self
.
_day
+
(
153
*
m
+
2
)
/
5
+
365
*
y
+
y
/
4
-
y
/
100
+
y
/
400
-
32045
def
week
(
self
):
def
week
(
self
):
"""
Return the week number according to ISO.
"""
Return the week number according to ISO
See:
http://www.tondering.dk/claus/cal/node6.html#SECTION00670000000000000000
see
http://www.tondering.dk/claus/cal/node6.html#SECTION00670000000000000000
"""
"""
J
=
self
.
JulianDay
()
J
=
self
.
JulianDay
()
d4
=
(
J
+
31741
-
(
J
%
7
))
%
146097
%
36524
%
1461
d4
=
(
J
+
31741
-
(
J
%
7
))
%
146097
%
36524
%
1461
...
@@ -1924,7 +1806,9 @@ class DateTime:
...
@@ -1924,7 +1806,9 @@ class DateTime:
return
d1
/
7
+
1
return
d1
/
7
+
1
def
encode
(
self
,
out
):
def
encode
(
self
,
out
):
"""Encode value for XML-RPC."""
"""
Encode value for XML-RPC
"""
out
.
write
(
'<value><dateTime.iso8601>'
)
out
.
write
(
'<value><dateTime.iso8601>'
)
out
.
write
(
self
.
ISO8601
())
out
.
write
(
self
.
ISO8601
())
out
.
write
(
'</dateTime.iso8601></value>
\
n
'
)
out
.
write
(
'</dateTime.iso8601></value>
\
n
'
)
...
@@ -1936,11 +1820,11 @@ class strftimeFormatter:
...
@@ -1936,11 +1820,11 @@ class strftimeFormatter:
self
.
_dt
=
dt
self
.
_dt
=
dt
self
.
_f
=
format
self
.
_f
=
format
def
__call__
(
self
):
def
__call__
(
self
):
return
self
.
_dt
.
strftime
(
self
.
_f
)
return
self
.
_dt
.
strftime
(
self
.
_f
)
# Module methods
# Module methods
def
Timezones
():
def
Timezones
():
"""Return the list of recognized timezone names"""
"""Return the list of recognized timezone names"""
return
_cache
.
_zlst
return
_cache
.
_zlst
lib/python/DateTime/tests/testDateTime.py
View file @
7df93024
##############################################################################
#
# To run these tests, use:
# Copyright (c) 2003 Zope Corporation and Contributors.
# python unittest.py DateTime.tests.suite
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import
math
import
math
import
os
import
os
...
@@ -48,30 +38,30 @@ class DateTimeTests(unittest.TestCase):
...
@@ -48,30 +38,30 @@ class DateTimeTests(unittest.TestCase):
math
.
floor
(
dt2
.
time
*
86400000.0
))
math
.
floor
(
dt2
.
time
*
86400000.0
))
def
testBug1203
(
self
):
def
testBug1203
(
self
):
# 01:59:60 occurred in old DateTime
'''01:59:60 occurred in old DateTime'''
dt
=
DateTime
(
7200
,
'GMT'
)
dt
=
DateTime
(
7200
,
'GMT'
)
self
.
assert_
(
str
(
dt
).
find
(
'60'
)
<
0
,
dt
)
self
.
assert_
(
str
(
dt
).
find
(
'60'
)
<
0
,
dt
)
def
testDSTInEffect
(
self
):
def
testDSTInEffect
(
self
):
# Checks GMT offset for a DST date in the US/Eastern time zone
'''Checks GMT offset for a DST date in the US/Eastern time zone'''
dt
=
DateTime
(
2000
,
5
,
9
,
15
,
0
,
0
,
'US/Eastern'
)
dt
=
DateTime
(
2000
,
5
,
9
,
15
,
0
,
0
,
'US/Eastern'
)
self
.
assertEqual
(
dt
.
toZone
(
'GMT'
).
hour
(),
19
,
self
.
assertEqual
(
dt
.
toZone
(
'GMT'
).
hour
(),
19
,
(
dt
,
dt
.
toZone
(
'GMT'
)))
(
dt
,
dt
.
toZone
(
'GMT'
)))
def
testDSTNotInEffect
(
self
):
def
testDSTNotInEffect
(
self
):
# Checks GMT offset for a non-DST date in the US/Eastern time zone
'''Checks GMT offset for a non-DST date in the US/Eastern time zone'''
dt
=
DateTime
(
2000
,
11
,
9
,
15
,
0
,
0
,
'US/Eastern'
)
dt
=
DateTime
(
2000
,
11
,
9
,
15
,
0
,
0
,
'US/Eastern'
)
self
.
assertEqual
(
dt
.
toZone
(
'GMT'
).
hour
(),
20
,
self
.
assertEqual
(
dt
.
toZone
(
'GMT'
).
hour
(),
20
,
(
dt
,
dt
.
toZone
(
'GMT'
)))
(
dt
,
dt
.
toZone
(
'GMT'
)))
def
testAddPrecision
(
self
):
def
testAddPrecision
(
self
):
# Precision of serial additions
'''Precision of serial additions'''
dt
=
DateTime
()
dt
=
DateTime
()
self
.
assertEqual
(
str
(
dt
+
0.10
+
3.14
+
6.76
-
10
),
str
(
dt
),
self
.
assertEqual
(
str
(
dt
+
0.10
+
3.14
+
6.76
-
10
),
str
(
dt
),
dt
)
dt
)
def
testConstructor3
(
self
):
def
testConstructor3
(
self
):
# Constructor from date/time string
'''Constructor from date/time string'''
dt
=
DateTime
()
dt
=
DateTime
()
dt1s
=
'%d/%d/%d %d:%d:%f %s'
%
(
dt1s
=
'%d/%d/%d %d:%d:%f %s'
%
(
dt
.
year
(),
dt
.
year
(),
...
@@ -87,19 +77,19 @@ class DateTimeTests(unittest.TestCase):
...
@@ -87,19 +77,19 @@ class DateTimeTests(unittest.TestCase):
self
.
assertEqual
(
repr
(
dt
),
repr
(
dt1
))
self
.
assertEqual
(
repr
(
dt
),
repr
(
dt1
))
def
testConstructor4
(
self
):
def
testConstructor4
(
self
):
# Constructor from time float
'''Constructor from time float'''
dt
=
DateTime
()
dt
=
DateTime
()
dt1
=
DateTime
(
float
(
dt
))
dt1
=
DateTime
(
float
(
dt
))
self
.
_compare
(
dt
,
dt1
)
self
.
_compare
(
dt
,
dt1
)
def
testConstructor5
(
self
):
def
testConstructor5
(
self
):
# Constructor from time float and timezone
'''Constructor from time float and timezone'''
dt
=
DateTime
()
dt
=
DateTime
()
dt1
=
DateTime
(
float
(
dt
),
dt
.
timezone
())
dt1
=
DateTime
(
float
(
dt
),
dt
.
timezone
())
self
.
assertEqual
(
str
(
dt
),
str
(
dt1
),
(
dt
,
dt1
))
self
.
assertEqual
(
str
(
dt
),
str
(
dt1
),
(
dt
,
dt1
))
def
testConstructor6
(
self
):
def
testConstructor6
(
self
):
# Constructor from year and julian date
'''Constructor from year and julian date'''
# This test must normalize the time zone, or it *will* break when
# This test must normalize the time zone, or it *will* break when
# DST changes!
# DST changes!
dt1
=
DateTime
(
2000
,
5.500000578705
)
dt1
=
DateTime
(
2000
,
5.500000578705
)
...
@@ -107,7 +97,7 @@ class DateTimeTests(unittest.TestCase):
...
@@ -107,7 +97,7 @@ class DateTimeTests(unittest.TestCase):
self
.
_compare
(
dt
,
dt1
)
self
.
_compare
(
dt
,
dt1
)
def
testConstructor7
(
self
):
def
testConstructor7
(
self
):
# Constructor from parts
'''Constructor from parts'''
dt
=
DateTime
()
dt
=
DateTime
()
dt1
=
DateTime
(
dt1
=
DateTime
(
dt
.
year
(),
dt
.
year
(),
...
@@ -122,19 +112,19 @@ class DateTimeTests(unittest.TestCase):
...
@@ -122,19 +112,19 @@ class DateTimeTests(unittest.TestCase):
self
.
assertEqual
(
repr
(
dt
),
repr
(
dt1
))
self
.
assertEqual
(
repr
(
dt
),
repr
(
dt1
))
def
testDayOfWeek
(
self
):
def
testDayOfWeek
(
self
):
# strftime() used to always be passed a day of week of 0
'''strftime() used to always be passed a day of week of 0.'''
dt
=
DateTime
(
'2000/6/16'
)
dt
=
DateTime
(
'2000/6/16'
)
s
=
dt
.
strftime
(
'%A'
)
s
=
dt
.
strftime
(
'%A'
)
self
.
assertEqual
(
s
,
'Friday'
,
(
dt
,
s
))
self
.
assertEqual
(
s
,
'Friday'
,
(
dt
,
s
))
def
testOldDate
(
self
):
def
testOldDate
(
self
):
# Fails when an 1800 date is displayed with negative signs
'''Fails when an 1800 date is displayed with negative signs'''
dt
=
DateTime
(
'1830/5/6 12:31:46.213 pm'
)
dt
=
DateTime
(
'1830/5/6 12:31:46.213 pm'
)
dt1
=
dt
.
toZone
(
'GMT+6'
)
dt1
=
dt
.
toZone
(
'GMT+6'
)
self
.
assert_
(
str
(
dt1
).
find
(
'-'
)
<
0
,
(
dt
,
dt1
))
self
.
assert_
(
str
(
dt1
).
find
(
'-'
)
<
0
,
(
dt
,
dt1
))
def
testSubtraction
(
self
):
def
testSubtraction
(
self
):
# Reconstruction of a DateTime from its parts, with subtraction
'''Reconstruction of a DateTime from its parts, with subtraction'''
dt
=
DateTime
()
dt
=
DateTime
()
dt1
=
dt
-
3.141592653
dt1
=
dt
-
3.141592653
dt2
=
DateTime
(
dt2
=
DateTime
(
...
@@ -148,25 +138,25 @@ class DateTimeTests(unittest.TestCase):
...
@@ -148,25 +138,25 @@ class DateTimeTests(unittest.TestCase):
self
.
assertEqual
(
dt1
,
dt3
,
(
dt
,
dt1
,
dt2
,
dt3
))
self
.
assertEqual
(
dt1
,
dt3
,
(
dt
,
dt1
,
dt2
,
dt3
))
def
testTZ1add
(
self
):
def
testTZ1add
(
self
):
# Time zone manipulation: add to a date
'''Time zone manipulation: add to a date'''
dt
=
DateTime
(
'1997/3/8 1:45am GMT-4'
)
dt
=
DateTime
(
'1997/3/8 1:45am GMT-4'
)
dt1
=
DateTime
(
'1997/3/9 1:45pm GMT+8'
)
dt1
=
DateTime
(
'1997/3/9 1:45pm GMT+8'
)
self
.
assertEqual
(
dt
+
1.0
,
dt1
,
(
dt
,
dt1
))
self
.
assertEqual
(
dt
+
1.0
,
dt1
,
(
dt
,
dt1
))
def
testTZ1sub
(
self
):
def
testTZ1sub
(
self
):
# Time zone manipulation: subtract from a date
'''Time zone manipulation: subtract from a date'''
dt
=
DateTime
(
'1997/3/8 1:45am GMT-4'
)
dt
=
DateTime
(
'1997/3/8 1:45am GMT-4'
)
dt1
=
DateTime
(
'1997/3/9 1:45pm GMT+8'
)
dt1
=
DateTime
(
'1997/3/9 1:45pm GMT+8'
)
self
.
assertEqual
(
dt1
-
1.0
,
dt
,
(
dt
,
dt1
))
self
.
assertEqual
(
dt1
-
1.0
,
dt
,
(
dt
,
dt1
))
def
testTZ1diff
(
self
):
def
testTZ1diff
(
self
):
# Time zone manipulation: diff two dates
'''Time zone manipulation: diff two dates'''
dt
=
DateTime
(
'1997/3/8 1:45am GMT-4'
)
dt
=
DateTime
(
'1997/3/8 1:45am GMT-4'
)
dt1
=
DateTime
(
'1997/3/9 1:45pm GMT+8'
)
dt1
=
DateTime
(
'1997/3/9 1:45pm GMT+8'
)
self
.
assertEqual
(
dt1
-
dt
,
1.0
,
(
dt
,
dt1
))
self
.
assertEqual
(
dt1
-
dt
,
1.0
,
(
dt
,
dt1
))
def
testCompareMethods
(
self
):
def
testCompareMethods
(
self
):
# Compare two dates using several methods
'''Compare two dates using several methods'''
dt
=
DateTime
(
'1997/1/1'
)
dt
=
DateTime
(
'1997/1/1'
)
dt1
=
DateTime
(
'1997/2/2'
)
dt1
=
DateTime
(
'1997/2/2'
)
self
.
failUnless
(
dt1
.
greaterThan
(
dt
))
self
.
failUnless
(
dt1
.
greaterThan
(
dt
))
...
@@ -177,7 +167,7 @@ class DateTimeTests(unittest.TestCase):
...
@@ -177,7 +167,7 @@ class DateTimeTests(unittest.TestCase):
self
.
failUnless
(
not
dt
.
equalTo
(
dt1
))
self
.
failUnless
(
not
dt
.
equalTo
(
dt1
))
def
testCompareOperations
(
self
,
dt
=
None
,
dt1
=
None
):
def
testCompareOperations
(
self
,
dt
=
None
,
dt1
=
None
):
# Compare two dates using several operations
"""Compare two dates using several operations"""
if
dt
is
None
:
if
dt
is
None
:
dt
=
DateTime
(
'1997/1/1'
)
dt
=
DateTime
(
'1997/1/1'
)
if
dt1
is
None
:
if
dt1
is
None
:
...
@@ -190,7 +180,7 @@ class DateTimeTests(unittest.TestCase):
...
@@ -190,7 +180,7 @@ class DateTimeTests(unittest.TestCase):
self
.
failUnless
(
not
(
dt
==
dt1
))
self
.
failUnless
(
not
(
dt
==
dt1
))
def
testUpgradeOldInstances
(
self
):
def
testUpgradeOldInstances
(
self
):
# Compare dates that don't have the _millis attribute yet
"""Compare dates that don't have the _millis attribute yet."""
dt
=
DateTime
(
'1997/1/1'
)
dt
=
DateTime
(
'1997/1/1'
)
dt1
=
DateTime
(
'1997/2/2'
)
dt1
=
DateTime
(
'1997/2/2'
)
del
dt
.
_millis
del
dt
.
_millis
...
@@ -198,7 +188,7 @@ class DateTimeTests(unittest.TestCase):
...
@@ -198,7 +188,7 @@ class DateTimeTests(unittest.TestCase):
self
.
testCompareOperations
(
dt
,
dt1
)
self
.
testCompareOperations
(
dt
,
dt1
)
def
testTZ2
(
self
):
def
testTZ2
(
self
):
# Time zone manipulation test 2
'''Time zone manipulation test 2'''
dt
=
DateTime
()
dt
=
DateTime
()
dt1
=
dt
.
toZone
(
'GMT'
)
dt1
=
dt
.
toZone
(
'GMT'
)
s
=
dt
.
second
()
s
=
dt
.
second
()
...
@@ -206,13 +196,13 @@ class DateTimeTests(unittest.TestCase):
...
@@ -206,13 +196,13 @@ class DateTimeTests(unittest.TestCase):
self
.
assertEqual
(
s
,
s1
,
(
dt
,
dt1
,
s
,
s1
))
self
.
assertEqual
(
s
,
s1
,
(
dt
,
dt1
,
s
,
s1
))
def
testTZDiffDaylight
(
self
):
def
testTZDiffDaylight
(
self
):
# Diff dates across daylight savings dates
'''Diff dates across daylight savings dates'''
dt
=
DateTime
(
'2000/6/8 1:45am US/Eastern'
)
dt
=
DateTime
(
'2000/6/8 1:45am US/Eastern'
)
dt1
=
DateTime
(
'2000/12/8 12:45am US/Eastern'
)
dt1
=
DateTime
(
'2000/12/8 12:45am US/Eastern'
)
self
.
assertEqual
(
dt1
-
dt
,
183
,
(
dt
,
dt1
,
dt1
-
dt
))
self
.
assertEqual
(
dt1
-
dt
,
183
,
(
dt
,
dt1
,
dt1
-
dt
))
def
testY10KDate
(
self
):
def
testY10KDate
(
self
):
# Comparison of a Y10K date and a Y2K date
'''Comparison of a Y10K date and a Y2K date'''
dt
=
DateTime
(
'10213/09/21'
)
dt
=
DateTime
(
'10213/09/21'
)
dt1
=
DateTime
(
2000
,
1
,
1
)
dt1
=
DateTime
(
2000
,
1
,
1
)
...
@@ -222,7 +212,7 @@ class DateTimeTests(unittest.TestCase):
...
@@ -222,7 +212,7 @@ class DateTimeTests(unittest.TestCase):
self
.
assertEqual
(
ddays
,
3000000L
,
ddays
)
self
.
assertEqual
(
ddays
,
3000000L
,
ddays
)
def
test_tzoffset
(
self
):
def
test_tzoffset
(
self
):
# Test time-zone given as an offset
'''Test time-zone given as an offset'''
# GMT
# GMT
dt
=
DateTime
(
'Tue, 10 Sep 2001 09:41:03 GMT'
)
dt
=
DateTime
(
'Tue, 10 Sep 2001 09:41:03 GMT'
)
...
@@ -257,106 +247,38 @@ class DateTimeTests(unittest.TestCase):
...
@@ -257,106 +247,38 @@ class DateTimeTests(unittest.TestCase):
self
.
assertEqual
(
dt
.
tzoffset
(),
15900
)
self
.
assertEqual
(
dt
.
tzoffset
(),
15900
)
def
testISO8601
(
self
):
def
testISO8601
(
self
):
# ISO8601 reference dates
''' iso 8601 dates '''
ref0
=
DateTime
(
'2002/5/2 8:00am GMT'
)
ref0
=
DateTime
(
'2002/5/2 8:00am GMT'
)
ref1
=
DateTime
(
'2002/5/2 8:00am US/Eastern'
)
ref1
=
DateTime
(
'2002/5/2 8:00am US/Eastern'
)
ref2
=
DateTime
(
'2006/11/6 10:30 UTC'
)
ref3
=
DateTime
(
'2004/06/14 14:30:15 GMT-3'
)
ref4
=
DateTime
(
'2006/01/01 UTC'
)
# Basic tests
isoDt
=
DateTime
(
'2002-05-02T08:00:00'
)
isoDt
=
DateTime
(
'2002-05-02T08:00:00'
)
self
.
assertEqual
(
ref0
,
isoDt
)
self
.
assertEqual
(
ref0
,
isoDt
)
isoDt
=
DateTime
(
'2002-05-02T08:00:00Z'
)
isoDt
=
DateTime
(
'2002-05-02T08:00:00Z'
)
self
.
assertEqual
(
ref0
,
isoDt
)
self
.
assertEqual
(
ref0
,
isoDt
)
isoDt
=
DateTime
(
'2002-05-02T08:00:00-04:00'
)
isoDt
=
DateTime
(
'2002-05-02T08:00:00-04:00'
)
self
.
assertEqual
(
ref1
,
isoDt
)
self
.
assertEqual
(
ref1
,
isoDt
)
isoDt
=
DateTime
(
'2002-05-02 08:00:00-04:00'
)
self
.
assertEqual
(
ref1
,
isoDt
)
# Bug 1386: the colon in the timezone offset is optional
# Bug 1386: the colon in the timezone offset is optional
isoDt
=
DateTime
(
'2002-05-02T08:00:00-0400'
)
isoDt
=
DateTime
(
'2002-05-02T08:00:00-0400'
)
self
.
assertEqual
(
ref1
,
isoDt
)
self
.
assertEqual
(
ref1
,
isoDt
)
# Bug 2191: date reduced formats
dgood
=
'2002-05-02'
isoDt
=
DateTime
(
'2006-01-01'
)
tgood
=
'T08:00:00-04:00'
self
.
assertEqual
(
ref4
,
isoDt
)
for
dbad
in
'2002-5-2'
,
'2002-10-2'
,
'2002-2-10'
,
'02-2-10'
:
isoDt
=
DateTime
(
'200601-01'
)
self
.
assertRaises
(
DateTime
.
SyntaxError
,
DateTime
,
dbad
)
self
.
assertEqual
(
ref4
,
isoDt
)
self
.
assertRaises
(
DateTime
.
SyntaxError
,
DateTime
,
dbad
+
tgood
)
isoDt
=
DateTime
(
'20060101'
)
for
tbad
in
'08:00'
,
'T8:00'
:
#, 'T08:00Z-04:00':
self
.
assertEqual
(
ref4
,
isoDt
)
self
.
assertRaises
(
DateTime
.
SyntaxError
,
DateTime
,
dgood
+
tbad
)
isoDt
=
DateTime
(
'2006-01'
)
self
.
assertEqual
(
ref4
,
isoDt
)
isoDt
=
DateTime
(
'200601'
)
self
.
assertEqual
(
ref4
,
isoDt
)
isoDt
=
DateTime
(
'2006'
)
self
.
assertEqual
(
ref4
,
isoDt
)
# Bug 2191: date/time separators are also optional
isoDt
=
DateTime
(
'20020502T08:00:00'
)
self
.
assertEqual
(
ref0
,
isoDt
)
isoDt
=
DateTime
(
'2002-05-02T080000'
)
self
.
assertEqual
(
ref0
,
isoDt
)
isoDt
=
DateTime
(
'20020502T080000'
)
self
.
assertEqual
(
ref0
,
isoDt
)
# Bug 2191: timezones with only one digit for hour
isoDt
=
DateTime
(
'20020502T080000+0'
)
self
.
assertEqual
(
ref0
,
isoDt
)
isoDt
=
DateTime
(
'20020502 080000-4'
)
self
.
assertEqual
(
ref1
,
isoDt
)
isoDt
=
DateTime
(
'20020502T080000-400'
)
self
.
assertEqual
(
ref1
,
isoDt
)
isoDt
=
DateTime
(
'20020502T080000-4:00'
)
self
.
assertEqual
(
ref1
,
isoDt
)
# Bug 2191: optional seconds/minutes
isoDt
=
DateTime
(
'2002-05-02T0800'
)
self
.
assertEqual
(
ref0
,
isoDt
)
isoDt
=
DateTime
(
'2002-05-02T08'
)
self
.
assertEqual
(
ref0
,
isoDt
)
# Bug 2191: week format
isoDt
=
DateTime
(
'2002-W18-4T0800'
)
self
.
assertEqual
(
ref0
,
isoDt
)
isoDt
=
DateTime
(
'2002-W184T0800'
)
self
.
assertEqual
(
ref0
,
isoDt
)
isoDt
=
DateTime
(
'2002W18-4T0800'
)
self
.
assertEqual
(
ref0
,
isoDt
)
isoDt
=
DateTime
(
'2002W184T08'
)
self
.
assertEqual
(
ref0
,
isoDt
)
isoDt
=
DateTime
(
'2004-W25-1T14:30:15-03:00'
)
self
.
assertEqual
(
ref3
,
isoDt
)
isoDt
=
DateTime
(
'2004-W25T14:30:15-03:00'
)
self
.
assertEqual
(
ref3
,
isoDt
)
# Bug 2191: day of year format
isoDt
=
DateTime
(
'2002-122T0800'
)
self
.
assertEqual
(
ref0
,
isoDt
)
isoDt
=
DateTime
(
'2002122T0800'
)
self
.
assertEqual
(
ref0
,
isoDt
)
# Bug 2191: hours/minutes fractions
isoDt
=
DateTime
(
'2006-11-06T10.5'
)
self
.
assertEqual
(
ref2
,
isoDt
)
isoDt
=
DateTime
(
'2006-11-06T10,5'
)
self
.
assertEqual
(
ref2
,
isoDt
)
isoDt
=
DateTime
(
'20040614T1430.25-3'
)
self
.
assertEqual
(
ref3
,
isoDt
)
isoDt
=
DateTime
(
'2004-06-14T1430,25-3'
)
self
.
assertEqual
(
ref3
,
isoDt
)
isoDt
=
DateTime
(
'2004-06-14T14:30.25-3'
)
self
.
assertEqual
(
ref3
,
isoDt
)
isoDt
=
DateTime
(
'20040614T14:30,25-3'
)
self
.
assertEqual
(
ref3
,
isoDt
)
# ISO8601 standard format
iso8601_string
=
'2002-05-02T08:00:00-04:00'
iso8601_string
=
'2002-05-02T08:00:00-04:00'
iso8601DT
=
DateTime
(
iso8601_string
)
iso8601DT
=
DateTime
(
iso8601_string
)
self
.
assertEqual
(
iso8601_string
,
iso8601DT
.
ISO8601
())
self
.
assertEqual
(
iso8601_string
,
iso8601DT
.
ISO8601
())
def
testJulianWeek
(
self
):
def
testJulianWeek
(
self
):
# Check JulianDayWeek function
""" check JulianDayWeek function """
try
:
try
:
import
gzip
import
gzip
except
ImportError
:
except
ImportError
:
...
@@ -378,7 +300,7 @@ class DateTimeTests(unittest.TestCase):
...
@@ -378,7 +300,7 @@ class DateTimeTests(unittest.TestCase):
self
.
assertEqual
(
DateTime
(
d
),
d
)
self
.
assertEqual
(
DateTime
(
d
),
d
)
def
testRFC822
(
self
):
def
testRFC822
(
self
):
# rfc822 conversion
'''rfc822 conversion'''
dt
=
DateTime
(
'2002-05-02T08:00:00+00:00'
)
dt
=
DateTime
(
'2002-05-02T08:00:00+00:00'
)
self
.
assertEqual
(
dt
.
rfc822
(),
'Thu, 02 May 2002 08:00:00 +0000'
)
self
.
assertEqual
(
dt
.
rfc822
(),
'Thu, 02 May 2002 08:00:00 +0000'
)
...
@@ -393,10 +315,9 @@ class DateTimeTests(unittest.TestCase):
...
@@ -393,10 +315,9 @@ class DateTimeTests(unittest.TestCase):
dts
=
dt
.
rfc822
().
split
(
' '
)
dts
=
dt
.
rfc822
().
split
(
' '
)
times
=
dts
[
4
].
split
(
':'
)
times
=
dts
[
4
].
split
(
':'
)
_isDST
=
time
.
localtime
(
time
.
time
())[
8
]
_isDST
=
time
.
localtime
(
time
.
time
())[
8
]
if
_isDST
:
if
_isDST
:
offset
=
time
.
altzone
offset
=
time
.
altzone
else
:
offset
=
time
.
timezone
else
:
offset
=
time
.
timezone
self
.
assertEqual
(
dts
[
0
],
dt
.
aDay
()
+
','
)
self
.
assertEqual
(
dts
[
0
],
dt
.
aDay
()
+
','
)
self
.
assertEqual
(
int
(
dts
[
1
]),
dt
.
day
())
self
.
assertEqual
(
int
(
dts
[
1
]),
dt
.
day
())
self
.
assertEqual
(
dts
[
2
],
dt
.
aMonth
())
self
.
assertEqual
(
dts
[
2
],
dt
.
aMonth
())
...
@@ -406,14 +327,14 @@ class DateTimeTests(unittest.TestCase):
...
@@ -406,14 +327,14 @@ class DateTimeTests(unittest.TestCase):
self
.
assertEqual
(
int
(
times
[
2
]),
int
(
dt
.
second
()))
self
.
assertEqual
(
int
(
times
[
2
]),
int
(
dt
.
second
()))
self
.
assertEqual
(
dts
[
5
],
"%+03d%02d"
%
divmod
(
(
-
offset
/
60
),
60
)
)
self
.
assertEqual
(
dts
[
5
],
"%+03d%02d"
%
divmod
(
(
-
offset
/
60
),
60
)
)
def
testInternationalDateformat
(
self
):
def
testInternationalDateformat
(
self
):
for
year
in
range
(
1990
,
2020
):
for
year
in
range
(
1990
,
2020
):
for
month
in
range
(
1
,
13
):
for
month
in
range
(
1
,
13
):
for
day
in
range
(
1
,
32
):
for
day
in
range
(
1
,
32
):
try
:
try
:
d_us
=
DateTime
(
"%d/%d/%d"
%
(
year
,
month
,
day
))
d_us
=
DateTime
(
"%d/%d/%d"
%
(
year
,
month
,
day
))
except
:
continue
except
:
continue
d_int
=
DateTime
(
"%d.%d.%d"
%
(
day
,
month
,
year
),
d_int
=
DateTime
(
"%d.%d.%d"
%
(
day
,
month
,
year
),
datefmt
=
"international"
)
datefmt
=
"international"
)
...
@@ -432,7 +353,7 @@ class DateTimeTests(unittest.TestCase):
...
@@ -432,7 +353,7 @@ class DateTimeTests(unittest.TestCase):
'TimeError raised'
)
'TimeError raised'
)
def
testStrftimeTZhandling
(
self
):
def
testStrftimeTZhandling
(
self
):
# strftime timezone testing
'''strftime timezone testing'''
# This is a test for collector issue #1127
# This is a test for collector issue #1127
format
=
'%Y-%m-%d %H:%M %Z'
format
=
'%Y-%m-%d %H:%M %Z'
dt
=
DateTime
(
'Wed, 19 Nov 2003 18:32:07 -0215'
)
dt
=
DateTime
(
'Wed, 19 Nov 2003 18:32:07 -0215'
)
...
@@ -442,14 +363,14 @@ class DateTimeTests(unittest.TestCase):
...
@@ -442,14 +363,14 @@ class DateTimeTests(unittest.TestCase):
self
.
assertEqual
(
dt_string
,
dt_localstring
)
self
.
assertEqual
(
dt_string
,
dt_localstring
)
def
testStrftimeFarDates
(
self
):
def
testStrftimeFarDates
(
self
):
# Checks strftime in dates <= 1900 or >= 2038
'''Checks strftime in dates <= 1900 or >= 2038'''
dt
=
DateTime
(
'1900/01/30'
)
dt
=
DateTime
(
'1900/01/30'
)
self
.
assertEqual
(
dt
.
strftime
(
'%d/%m/%Y'
),
'30/01/1900'
)
self
.
assertEqual
(
dt
.
strftime
(
'%d/%m/%Y'
),
'30/01/1900'
)
dt
=
DateTime
(
'2040/01/30'
)
dt
=
DateTime
(
'2040/01/30'
)
self
.
assertEqual
(
dt
.
strftime
(
'%d/%m/%Y'
),
'30/01/2040'
)
self
.
assertEqual
(
dt
.
strftime
(
'%d/%m/%Y'
),
'30/01/2040'
)
def
testZoneInFarDates
(
self
):
def
testZoneInFarDates
(
self
):
# Checks time zone in dates <= 1900 or >= 2038
'''Checks time zone in dates <= 1900 or >= 2038'''
dt1
=
DateTime
(
'2040/01/30 14:33 GMT+1'
)
dt1
=
DateTime
(
'2040/01/30 14:33 GMT+1'
)
dt2
=
DateTime
(
'2040/01/30 11:33 GMT-2'
)
dt2
=
DateTime
(
'2040/01/30 11:33 GMT-2'
)
self
.
assertEqual
(
dt1
.
strftime
(
'%d/%m/%Y %H:%M'
),
self
.
assertEqual
(
dt1
.
strftime
(
'%d/%m/%Y %H:%M'
),
...
@@ -460,7 +381,6 @@ class DateTimeTests(unittest.TestCase):
...
@@ -460,7 +381,6 @@ class DateTimeTests(unittest.TestCase):
ok
=
dt
.
strftime
(
'Le %d/%m/%Y a %Hh%M'
).
replace
(
'a'
,
u'
\
xe0
'
)
ok
=
dt
.
strftime
(
'Le %d/%m/%Y a %Hh%M'
).
replace
(
'a'
,
u'
\
xe0
'
)
self
.
assertEqual
(
dt
.
strftime
(
u'Le %d/%m/%Y
\
xe0
%Hh%M'
),
ok
)
self
.
assertEqual
(
dt
.
strftime
(
u'Le %d/%m/%Y
\
xe0
%Hh%M'
),
ok
)
def
test_suite
():
def
test_suite
():
return
unittest
.
makeSuite
(
DateTimeTests
)
return
unittest
.
makeSuite
(
DateTimeTests
)
...
...
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