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
ecd8674c
Commit
ecd8674c
authored
Nov 29, 2005
by
Philipp von Weitershausen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert DateTime.txt to reST and a (pretty extensive) doctest.
parent
3159cf5b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
772 additions
and
536 deletions
+772
-536
lib/python/DateTime/DateTime.txt
lib/python/DateTime/DateTime.txt
+767
-535
lib/python/DateTime/tests/testDateTime.py
lib/python/DateTime/tests/testDateTime.py
+5
-1
No files found.
lib/python/DateTime/DateTime.txt
View file @
ecd8674c
DateTime
====================
The DateTime package
====================
Encapsulation of date/time values
Encapsulation of date/time values.
Module Functions
Timezones()
Function Timezones()
====================
Returns the list of recognized timezone names:
>>> from DateTime import Timezones
>>> Timezones() # doctest: +ELLIPSIS
['Brazil/Acre', 'Brazil/DeNoronha', ..., 'NZST', 'IDLE']
Return the list of recognized timezone names
Class DateTime
Class DateTime
==============
DateTime objects represent instants in time and provide interfaces for
DateTime objects represent instants in time and provide interfaces for
controlling its representation without affecting the absolute value of
the
controlling its representation without affecting the absolute value of
object.
the
object.
DateTime objects may be created from a wide variety of string or numeric data,
DateTime objects may be created from a wide variety of string or
or may be computed from other DateTime objects. DateTimes support the ability
numeric data, or may be computed from other DateTime objects.
to convert their representations to many major timezones, as well as the
DateTimes support the ability to convert their representations to many
ablility to create a DateTime object in the context of a given timezone.
major timezones, as well as the ablility to create a DateTime object
in the context of a given timezone.
DateTime objects provide partial numerical behavior:
DateTime objects provide partial numerical behavior:
* Two date-time objects can be subtracted to obtain a time, in days between
* Two date-time objects can be subtracted to obtain a time, in days
the two.
between
the two.
* A date-time object and a positive or negative number may be added to obtain
* A date-time object and a positive or negative number may be added to
a new date-time object that is the given number of days later than the
obtain a new date-time object that is the given number of days later
input date-time object.
than the
input date-time object.
* A positive or negative number and a date-time object may be added to obtain
* A positive or negative number and a date-time object may be added to
a new date-time object that is the given number of days later than the
obtain a new date-time object that is the given number of days later
input date-time object.
than the
input date-time object.
* A positive or negative number may be subtracted from a date-time object to
* A positive or negative number may be subtracted from a date-time
obtain a new date-time object that is the given number of days earlier than
object to obtain a new date-time object that is the given number of
the input date-time object.
days earlier than
the input date-time object.
DateTime objects may be converted to integer, long, or float numbers
of days
DateTime objects may be converted to integer, long, or float numbers
since January 1, 1901, using the standard int, long, and float functions
of days since January 1, 1901, using the standard int, long, and float
(Compatibility Note: int, long and float return the number of days since 1901
functions (Compatibility Note: int, long and float return the number
in GMT rather than local machine timezone). DateTime objects also provide
of days since 1901 in GMT rather than local machine timezone).
access to their value in a float format usable with the python time module,
DateTime objects also provide access to their value in a float format
provided that the value of the object falls in the range of the epoch-based
usable with the python time module, provided that the value of the
time module.
object falls in the range of the epoch-based
time module.
A DateTime object should be considered immutable; all conversion and numeric
A DateTime object should be considered immutable; all conversion and numeric
operations return a new DateTime object rather than modify the current object.
operations return a new DateTime object rather than modify the current object.
Constructor For DateTime
A DateTime object always maintains its value as an absolute UTC time,
and is represented in the context of some timezone based on the
DateTime()
arguments used to create the object. A DateTime object's methods
return values based on the timezone context.
Return a new date-time object
A DateTime object always maintains its value as an absolute UTC time,
Note that in all cases the local machine timezone is used for
and is represented in the context of some timezone based on the
representation if no timezone is specified.
arguments used to create the object. A DateTime object's methods return
values based on the timezone context.
Note that in all cases the local machine timezone is used for
Constructor for DateTime
representation if no timezone is specified.
------------------------
DateTimes may be created with from zero to seven arguments.
DateTime() returns a new date-time object. DateTimes may be created
with from zero to seven arguments:
o
If the function is called with no arguments, then the current date/
*
If the function is called with no arguments, then the current date/
time is returned, represented in the timezone of the local machine.
time is returned, represented in the timezone of the local machine.
o
If the function is invoked with a single string argument which is a
*
If the function is invoked with a single string argument which is a
recognized timezone name, an object representing the current time
recognized timezone name, an object representing the current time is
is
returned, represented in the specified timezone.
returned, represented in the specified timezone.
o
If the function is invoked with a single string argument
*
If the function is invoked with a single string argument
representing a valid date/time, an object representing that date/
representing a valid date/time, an object representing that date/
time will be returned.
time will be returned.
As a general rule, any date-time representation that is recognized
As a general rule, any date-time representation that is recognized
and unambigous to a resident of North America is acceptable.(The
and unambigous to a resident of North America is acceptable. (The
reason for this qualification is that in North America, a date
reason for this qualification is that in North America, a date like:
like: 2/1/1994 is interpreted as February 1, 1994, while in some
2/1/1994 is interpreted as February 1, 1994, while in some parts of
parts of the world, it is interpreted as January 2, 1994.) A date/
the world, it is interpreted as January 2, 1994.) A date/ time
time string consists of two components, a date component and an
string consists of two components, a date component and an optional
optional time component, separated by one or more spaces. If the
time component, separated by one or more spaces. If the time
time component is omited, 12:00am is assumed. Any recognized
component is omited, 12:00am is assumed. Any recognized timezone
timezone name specified as the final element of the date/time
name specified as the final element of the date/time string will be
string will be used for computing the date/time value. (If you
used for computing the date/time value. (If you create a DateTime
create a DateTime with the string Mar 9, 1997 1:45pm US/Pacific,
with the string "Mar 9, 1997 1:45pm US/Pacific", the value will
the value will essentially be the same as if you had captured
essentially be the same as if you had captured time.time() at the
time.time() at the specified date and time on a machine in that
specified date and time on a machine in that timezone).
timezone)
o Returns current date/time, represented in US/Eastern:
>>> from DateTime import DateTime
e=DateTime(US/Eastern)
>>> e = DateTime('US/Eastern')
# returns current date/time, represented in US/Eastern.
>>> e.timezone()
'US/Eastern'
o Returns specified time, represented in local machine zone:
>>> x = DateTime('1997/3/9 1:45pm')
x=DateTime(1997/3/9 1:45pm)
>>> x.parts() # doctest: +ELLIPSIS
# returns specified time, represented in local machine zone.
(1997, 3, 9, 13, 45, 0.0, ...)
o Specified time in local machine zone, verbose format:
>>> y = DateTime('Mar 9, 1997 13:45:00')
>>> y.parts() # doctest: +ELLIPSIS
y=DateTime(Mar 9, 1997 13:45:00)
(1997, 3, 9, 13, 45, 0.0, ...)
# y is equal to x
>>> y == x
True
The date component consists of year, month, and day values. The
The date component consists of year, month, and day values. The
year value must be a one-, two-, or four-digit integer. If a one-
year value must be a one-, two-, or four-digit integer. If a one-
...
@@ -133,10 +135,10 @@ Constructor For DateTime
...
@@ -133,10 +135,10 @@ Constructor For DateTime
and 59 inclusively. The second value may be an integer value
and 59 inclusively. The second value may be an integer value
between 0 and 59.999 inclusively. The second value or both the
between 0 and 59.999 inclusively. The second value or both the
minute and second values may be ommitted. The time may be followed
minute and second values may be ommitted. The time may be followed
by am or pm in upper or lower case, in which case a 12-hour clock
by am or pm in upper or lower case, in which case a 12-hour clock is
is
assumed.
assumed.
o
If the DateTime function is invoked with a single Numeric argument,
*
If the DateTime function is invoked with a single Numeric argument,
the number is assumed to be either a floating point value such as
the number is assumed to be either a floating point value such as
that returned by time.time() , or a number of days after January 1,
that returned by time.time() , or a number of days after January 1,
1901 00:00:00 UTC.
1901 00:00:00 UTC.
...
@@ -148,403 +150,633 @@ Constructor For DateTime
...
@@ -148,403 +150,633 @@ Constructor For DateTime
viewpoint of the local machine's timezone. A negative argument will
viewpoint of the local machine's timezone. A negative argument will
yield a date-time value before 1901.
yield a date-time value before 1901.
o
If the function is invoked with two numeric arguments, then the
*
If the function is invoked with two numeric arguments, then the
first is taken to be an integer year and the second argument is
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
taken to be an offset in days from the beginning of the year, in the
the context of the local machine timezone. The date-time value
context of the local machine timezone. The date-time value returned
returned is the given offset number of days from the beginning of
is the given offset number of days from the beginning of the given
the given year, represented in the timezone of the local machine.
year, represented in the timezone of the local machine. The offset
The offset may be positive or negative. Two-digit years are assumed
may be positive or negative. Two-digit years are assumed to be in
to be in
the twentieth century.
the twentieth century.
o
If the function is invoked with two arguments, the first a float
*
If the function is invoked with two arguments, the first a float
representing a number of seconds past the epoch in gmt (such as
representing a number of seconds past the epoch in gmt (such as
those returned by time.time()) and the second a string naming a
those returned by time.time()) and the second a string naming a
recognized timezone, a DateTime with a value of that gmt time will
recognized timezone, a DateTime with a value of that gmt time will
be returned, represented in the given timezone.
be returned, represented in the given timezone.
import time
t=time.time()
now_east=DateTime(t,'US/Eastern')
# Time t represented as US/Eastern
>>> import time
>>> t = time.time()
Time t represented as US/Eastern:
now_west=DateTime(t,'US/Pacific')
>>> now_east = DateTime(t, 'US/Eastern')
# Time t represented as US/Pacific
Time t represented as US/Pacific:
>>> now_west = DateTime(t, 'US/Pacific')
Only their representations are different:
>>> now_east == now_west
True
# now_east == now_west
* If the function is invoked with three or more numeric arguments,
# only their representations are different
o If the function is invoked with three or more numeric arguments,
then the first is taken to be an integer year, the second is taken
then the first is taken to be an integer year, the second is taken
to be an integer month, and the third is taken to be an integer
to be an integer month, and the third is taken to be an integer day.
day. If the combination of values is not valid, then a
If the combination of values is not valid, then a DateTimeError is
DateTimeError is raised. Two-digit years are assumed to be in the
raised. Two-digit years are assumed to be in the twentieth century.
twentieth century. The fourth, fifth, and sixth arguments are
The fourth, fifth, and sixth arguments are floating point, positive
floating point, positive or negative offsets in units of hours,
or negative offsets in units of hours, minutes, and days, and
minutes, and days, and default to zero if not given. An optional
default to zero if not given. An optional string may be given as
string may be given as the final argument to indicate timezone (the
the final argument to indicate timezone (the effect of this is as if
effect of this is as if you had taken the value of time.time() at
you had taken the value of time.time() at that time on a machine in
that time on a machine in the specified timezone).
the specified timezone).
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.
The module function Timezones() will return a list of the timezones
recognized by the DateTime module. Recognition of timezone names is
case-insensitive.
Instance Methods for DateTime (IDateTime interface)
---------------------------------------------------
Conversion and comparison methods
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* ``timeTime()`` returns the date/time as a floating-point number in
UTC, in the format used by the python time module. Note that it is
possible to create date /time values with DateTime that have no
meaningful value to the time module, and in such cases a
DateTimeError is raised. A DateTime object's value must generally
be between Jan 1, 1970 (or your local machine epoch) and Jan 2038 to
produce a valid time.time() style value.
>>> dt = DateTime('Mar 9, 1997 13:45:00 US/Eastern')
>>> dt.timeTime()
857933100.0
>>> DateTime('2040/01/01').timeTime()
2208985200.0
If a string argument passed to the DateTime constructor cannot be
>>> DateTime('1900/01/01').timeTime()
parsed, it will raise DateTime.SyntaxError. Invalid date, time, or
-2208992400.0
timezone components will raise a DateTime.DateTimeError.
The module function Timezones() will return a list of the timezones
* ``toZone(z)`` returns a DateTime with the value as the current
recognized by the DateTime module. Recognition of timezone names is
object, represented in the indicated timezone:
case-insensitive.
Instance Methods For DateTime
>>> dt.toZone('UTC')
DateTime('1997/03/09 18:45:00 Universal')
aMonth()
>>> dt.toZone('UTC') == dt
True
Return the abreviated month name.
* ``isFuture()`` returns true if this object represents a date/time
later than the time of the call:
pCommon()
>>> dt.isFuture()
False
>>> DateTime('Jan 1 3000').isFuture() # not time-machine safe!
True
Return a string representing the object's value in the format: Mar. 1,
* ``isPast()`` returns true if this object represents a date/time
1997 1:45 pm
earlier than the time of the call:
minute()
>>> dt.isPast()
True
>>> DateTime('Jan 1 3000').isPast() # not time-machine safe!
False
Return the minute
* ``isCurrentYear()`` returns true if this object represents a
date/time that falls within the current year, in the context of this
object's timezone representation:
isLeapYear()
>>> dt.isCurrentYear()
False
>>> DateTime().isCurrentYear()
True
Return true if the current year (in the context of the object's
* ``isCurrentMonth()`` returns true if this object represents a
timezone) is a leap year
date/time that falls within the current month, in the context of
this object's timezone representation:
pMonth()
>>> dt.isCurrentMonth()
False
>>> DateTime().isCurrentMonth()
True
Return the abreviated (with period) month name.
* ``isCurrentDay()`` returns true if this object represents a
date/time that falls within the current day, in the context of this
object's timezone representation:
DayOfWeek()
>>> dt.isCurrentDay()
False
>>> DateTime().isCurrentDay()
True
Compatibility: see Day
* ``isCurrentHour()`` returns true if this object represents a
date/time that falls within the current hour, in the context of this
object's timezone representation:
Day_()
>>> dt.isCurrentHour()
False
Compatibility: see pDay
>>> DateTime().isCurrentHour()
True
isCurrentDay()
* ``isCurrentMinute()`` returns true if this object represents a
date/time that falls within the current minute, in the context of
this object's timezone representation:
Return true if this object represents a date/time that falls within the
>>> dt.isCurrentMinute()
current day, in the context of this object's timezone representation
False
>>> DateTime().isCurrentMinute()
True
Mon()
* ``isLeapYear()`` returns true if the current year (in the context of
the object's timezone) is a leap year:
Compatibility: see aMonth
>>> dt.isLeapYear()
False
>>> DateTime('Mar 8 2004').isLeapYear()
True
hour()
* ``earliestTime()`` returns a new DateTime object that represents the
earliest possible time (in whole seconds) that still falls within
the current object's day, in the object's timezone context:
Return the 24-hour clock representation of the hour
>>> dt.earliestTime()
DateTime('1997/03/09')
Date()
* ``latestTime()`` return a new DateTime object that represents the
latest possible time (in whole seconds) that still falls within the
current object's day, in the object's timezone context
Return the date string for the object.
>>> dt.latestTime()
DateTime('1997/03/09 23:59:59 US/Eastern')
aCommonZ()
Component access
~~~~~~~~~~~~~~~~
Return a string representing the object's value in the format: Mar 1
,
* ``parts()`` returns a tuple containing the calendar year, month
,
1997 1:45 pm US/Eastern
day, hour, minute second and timezone of the object
fCommonZ()
>>> dt.parts()
(1997, 3, 9, 13, 45, 0.0, 'US/Eastern')
Return a string representing the object's value in the format: March 1,
* ``timezone()`` returns the timezone in which the object is represented:
1997 1:45 pm US/Eastern
isCurrentYear()
>>> dt.timezone() in Timezones()
True
Return true if this object represents a date/time that falls within the
* ``tzoffset()`` returns the timezone offset for the objects timezone:
current year, in the context of this object's timezone representation
AMPMMinutes()
>>> dt.tzoffset()
-18000
Return the time string for an object not showing seconds.
* ``year()`` returns the calendar year of the object:
dd()
>>> dt.year()
1997
Return day as a 2 digit string
* ``month()`` retursn the month of the object as an integer:
TimeMinutes()
>>> dt.month()
3
Return the time string for an object not showing seconds.
* ``Month()`` returns the full month name:
h_24()
>>> dt.Month()
'March'
Return the 24-hour clock representation of the hour
* ``aMonth()`` returns the abreviated month name:
isPast()
>>> dt.aMonth()
'Mar'
Return true if this object represents a date/time earlier than the time
* ``pMonth()`` returns the abreviated (with period) month name:
of the call
dow()
>>> dt.pMonth()
'Mar.'
Return the integer day of the week, where sunday is 0
* ``day()`` returns the integer day:
isFuture()
>>> dt.day()
9
Return true if this object represents a date/time later than the time
* ``Day()`` returns the full name of the day of the week:
of the call
pCommonZ()
>>> dt.Day()
'Sunday'
Return a string representing the object's value in the format: Mar. 1,
* ``dayOfYear()`` returns the day of the year, in context of the
1997 1:45 pm US/Eastern
timezone representation of the object:
timezone()
>>> dt.dayOfYear()
68
Return the timezone in which the object is represented.
* ``aDay()`` returns the abreviated name of the day of the week:
h_12()
>>> dt.aDay()
'Sun'
Return the 12-hour clock representation of the hour
* ``pDay()`` returns the abreviated (with period) name of the day of
the week:
PreciseTime()
>>> dt.pDay()
'Sun.'
Return the time string for the object.
* ``dow()`` returns the integer day of the week, where Sunday is 0:
isCurrentMinute()
>>> dt.dow()
0
Return true if this object represents a date/time that falls within the
* ``dow_1()`` returns the integer day of the week, where sunday is 1:
current minute, in the context of this object's timezone representation
rfc822()
>>> dt.dow_1()
1
Return the date in RFC 822 format
* ``h_12()`` returns the 12-hour clock representation of the hour:
equalTo(t)
>>> dt.h_12()
1
Compare this DateTime object to another DateTime object OR a floating
* ``h_24()`` returns the 24-hour clock representation of the hour:
point number such as that which is returned by the python time module.
Returns true if the object represents a date/time equal to the
specified DateTime or time module style time.
yy()
>>> dt.h_24()
13
Return calendar year as a 2 digit string
* ``ampm()`` returns the appropriate time modifier (am or pm):
mm()
>>> dt.ampm()
'pm'
Return month as a 2 digit string
* ``hour()`` returns the 24-hour clock representation of the hour:
Mon_()
>>> dt.hour()
13
Compatibility: see pMonth
* ``minute()`` returns the minute:
toZone(z)
>>> dt.minute()
45
Return a DateTime with the value as the current object, represented in
* ``second()`` returns the second:
the indicated timezone.
earliestTime()
>>> dt.second()
0.0
Return a new DateTime object that represents the earliest possible time
* ``millis()`` returns the milliseconds since the epoch in GMT.
(in whole seconds) that still falls within the current object's day, in
the object's timezone context
aDay()
>>> dt.millis()
857933100000L
Return the abreviated name of the day of the week
strftime()
~~~~~~~~~~
dayOfYear()
See ``tests/testDateTime.py``.
Return the day of the year, in context of the timezone representation
General formats from previous DateTime
of the object
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
latestTime()
* ``Date()`` return the date string for the object:
Return a new DateTime object that represents the latest possible time
>>> dt.Date()
(in whole seconds) that still falls within the current object's day, in
'1997/03/09'
the object's timezone context
notEqualTo(t)
* ``Time()`` returns the time string for an object to the nearest
second:
Compare this DateTime object to another DateTime object OR a floating
>>> dt.Time()
point number such as that which is returned by the python time module.
'13:45:00'
Returns true if the object represents a date/time not equal to the
specified DateTime or time module style time.
PreciseAMPM()
* ``TimeMinutes()`` returns the time string for an object not showing
seconds:
Return the time string for the object.
>>> dt.TimeMinutes()
'13:45'
day()
* ``AMPM()`` returns the time string for an object to the nearest second:
Return the integer day
>>> dt.AMPM()
'01:45:00 pm'
timeTime()
* ``AMPMMinutes()`` returns the time string for an object not showing
seconds:
Return the date/time as a floating-point number in UTC, in the format
>>> dt.AMPMMinutes()
used by the python time module. Note that it is possible to create date
'01:45 pm'
/time values with DateTime that have no meaningful value to the time
module, and in such cases a DateTimeError is raised. A DateTime
object's value must generally be between Jan 1, 1970 (or your local
machine epoch) and Jan 2038 to produce a valid time.time() style value.
ampm()
* ``PreciseTime()`` returns the time string for the object:
Return the appropriate time modifier (am or pm)
>>> dt.PreciseTime()
'13:45:00.000'
greaterThan(t)
* ``PreciseAMPM()``return the time string for the object:
Compare this DateTime object to another DateTime object OR a floating
>>> dt.PreciseAMPM()
point number such as that which is returned by the python time module.
'01:45:00.000 pm'
Returns true if the object represents a date/time greater than the
specified DateTime or time module style time.
month()
* ``yy()`` returns the calendar year as a 2 digit string
Return the month of the object as an integer
>>> dt.yy()
'97'
AMPM()
* ``mm()`` returns the month as a 2 digit string
Return the time string for an object to the nearest second.
>>> dt.mm()
'03'
second()
* ``dd()`` returns the day as a 2 digit string:
Return the second
>>> dt.dd()
'09'
parts()
* ``rfc822()`` returns the date in RFC 822 format:
Return a tuple containing the calendar year, month, day, hour, minute
>>> dt.rfc822()
second and timezone of the object
'Sun, 09 Mar 1997 13:45:00 -0500'
greaterThanEqualTo(t)
New formats
~~~~~~~~~~~
Compare this DateTime object to another DateTime object OR a floating
* ``fCommon()`` returns a string representing the object's value in
point number such as that which is returned by the python time module.
the format: March 9, 1997 1:45 pm:
Returns true if the object represents a date/time greater than or equal
to the specified DateTime or time module style time.
lessThanEqualTo(t)
>>> dt.fCommon()
'March 9, 1997 1:45 pm'
Compare this DateTime object to another DateTime object OR a floating
* ``fCommonZ()`` returns a string representing the object's value in
point number such as that which is returned by the python time module.
the format: March 9, 1997 1:45 pm US/Eastern:
Returns true if the object represents a date/time less than or equal to
the specified DateTime or time module style time.
isCurrentHour()
>>> dt.fCommonZ()
'March 9, 1997 1:45 pm US/Eastern'
Return true if this object represents a date/time that falls within the
* ``aCommon()`` returns a string representing the object's value in
current hour, in the context of this object's timezone representation
the format: Mar 9, 1997 1:45 pm:
aCommon()
>>> dt.aCommon()
'Mar 9, 1997 1:45 pm'
Return a string representing the object's value in the format: Mar 1,
* ``aCommonZ()`` return a string representing the object's value in
1997 1:45 pm
the format: Mar 9, 1997 1:45 pm US/Eastern:
dow_1()
>>> dt.aCommonZ()
'Mar 9, 1997 1:45 pm US/Eastern'
Return the integer day of the week, where sunday is 1
* ``pCommon()`` returns a string representing the object's value in
the format Mar. 9, 1997 1:45 pm:
Day()
>>> dt.pCommon()
'Mar. 9, 1997 1:45 pm'
Return the full name of the day of the week
* ``pCommonZ()`` returns a string representing the object's value in
the format: Mar. 9, 1997 1:45 pm US/Eastern:
fCommon()
>>> dt.pCommonZ()
'Mar. 9, 1997 1:45 pm US/Eastern'
Return a string representing the object's value in the format: March 1,
* ``ISO()`` returns a string with the date/time in ISO format. Note:
1997 1:45 pm
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
Month()
>>> dt.ISO()
'1997-03-09 13:45:00'
Return the full month name
* ``ISO8601()`` returns the object in ISO 8601-compatible format
containing the date, time with seconds-precision and the time zone
identifier - see http://www.w3.org/TR/NOTE-datetime. Dates are
output as: YYYY-MM-DDTHH:MM:SSTZD (T is a literal character, TZD is
Time Zone Designator, format +HH:MM or -HH:MM).
isCurrentMonth()
The ``HTML4()`` method below offers the same formatting, but
converts to UTC before returning the value and sets the TZD"Z"
Return true if this object represents a date/time that falls within the
>>> dt.ISO8601()
current month, in the context of this object's timezone representation
'1997-03-09T13:45:00-05:00'
year()
Return the calendar year of the object
* ``HTML4()`` returns the object in the format used in the HTML4.0
specification, one of the standard forms in ISO8601. See
http://www.w3.org/TR/NOTE-datetime. Dates are output as:
YYYY-MM-DDTHH:MM:SSZ (T, Z are literal characters, the time is in
UTC.):
lessThan(t)
>>> dt.HTML4()
'1997-03-09T18:45:00Z'
Compare this DateTime object to another DateTime object OR a floating
* ``JulianDay()`` returns the Julian day according to
point number such as that which is returned by the python time module.
http://www.tondering.dk/claus/cal/node3.html#sec-calcjd
Returns true if the object represents a date/time less than the
specified DateTime or time module style time.
Time()
>>> dt.JulianDay()
2450517
Return the time string for an object to the nearest second.
* ``week()`` returns the week number according to ISO
see http://www.tondering.dk/claus/cal/node6.html#SECTION00670000000000000000
pDay()
>>> dt.week()
10
Return the abreviated (with period) name of the day of the week
Deprecated API
~~~~~~~~~~~~~~
General Services Provided by DateTime
* DayOfWeek(): see Day()
`aDateTime`
Convert a DateTime to a string that looks like a Python expression.
str(aDateTime)
Convert a DateTime to a string.
* Day_(): see pDay()
cmp(aDateTime, other
)
* Mon(): see aMonth(
)
Compare a DateTime with another DateTime object, or a float such as
* Mon_(): see pMonth
those returned by time.time().
NOTE: __cmp__ support is provided for backward compatibility only, and
General Services Provided by DateTime
mixing DateTimes with ExtensionClasses could cause __cmp__ to break.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You should use the methods lessThan, greaterThan, lessThanEqualTo,
greaterThanEqualTo, equalTo and notEqualTo to avoid potential problems
DateTimes can be repr()'ed; the result will be a string indicating how
later!!
to make a DateTime object like this:
hash(aDateTime)
>>> `dt`
"DateTime('1997/03/09 13:45:00 US/Eastern')"
Compute a hash value for a DateTime
When we convert them into a string, we get a nicer string that could
actually be shown to a user:
>>> str(dt)
'1997/03/09 13:45:00 US/Eastern'
The hash value of a DateTime is based on the date and time and is
equal for different representations of the DateTime:
>>> hash(dt)
3618678
>>> hash(dt.toZone('UTC'))
3618678
A DateTime can be compared with another DateTime or float via
``cmp()``. NOTE: __cmp__ support is provided for backward
compatibility only, and mixing DateTimes with ExtensionClasses could
cause __cmp__ to break. You should use the methods lessThan,
greaterThan, lessThanEqualTo, greaterThanEqualTo, equalTo and
notEqualTo to avoid potential problems later!
>>> cmp(dt, dt)
0
>>> cmp(dt, dt.toZone('UTC'))
0
>>> cmp(dt, dt.timeTime())
0
>>> cmp(dt, DateTime('2000/01/01'))
-1
>>> cmp(dt, DateTime('1900/01/01'))
1
DateTime objects can be compared to other DateTime objects OR floating
point numbers such as the ones which are returned by the python time
module. On comparison for equality, True is returned if the object
represents a date/time equal to the specified DateTime or time module
style time:
>>> dt == dt
True
>>> dt == dt.toZone('UTC')
True
>>> dt == dt.timeTime()
True
>>> dt == DateTime()
False
>>> dt.equalTo(dt)
True
>>> dt.equalTo(dt.toZone('UTC'))
True
>>> dt.equalTo(dt.timeTime())
True
>>> dt.equalTo(DateTime())
False
Same goes for inequalities:
>>> dt != dt
False
>>> dt != dt.toZone('UTC')
False
>>> dt != dt.timeTime()
False
>>> dt != DateTime()
True
>>> dt.notEqualTo(dt)
False
>>> dt.notEqualTo(dt.toZone('UTC'))
False
>>> dt.notEqualTo(dt.timeTime())
False
>>> dt.notEqualTo(DateTime())
True
>>> dt > dt
False
>>> DateTime() > dt
True
>>> dt > DateTime().timeTime()
False
>>> DateTime().timeTime() > dt
True
>>> dt.greaterThan(dt)
False
>>> DateTime().greaterThan(dt)
True
>>> dt.greaterThan(DateTime().timeTime())
False
>>> dt >= dt
True
>>> DateTime() >= dt
True
>>> dt >= DateTime().timeTime()
False
>>> DateTime().timeTime() >= dt
True
>>> dt.greaterThanEqualTo(dt)
True
>>> DateTime().greaterThanEqualTo(dt)
True
>>> dt.greaterThanEqualTo(DateTime().timeTime())
False
>>> dt < dt
False
>>> DateTime() < dt
False
>>> dt < DateTime().timeTime()
True
>>> DateTime().timeTime() < dt
False
>>> dt.lessThan(dt)
False
>>> DateTime().lessThan(dt)
False
>>> dt.lessThan(DateTime().timeTime())
True
>>> dt <= dt
True
>>> DateTime() <= dt
False
>>> dt <= DateTime().timeTime()
True
>>> DateTime().timeTime() <= dt
False
>>> dt.lessThanEqualTo(dt)
True
>>> DateTime().lessThanEqualTo(dt)
False
>>> dt.lessThanEqualTo(DateTime().timeTime())
True
Numeric Services Provided by DateTime
Numeric Services Provided by DateTime
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aDateTime + other
A DateTime may be added to a number and a number may be added to a
A DateTime may be added to a number and a number may be added to a
DateTime:
DateTime; two DateTimes cannot be added.
>>> dt + 5
aDateTime - other
DateTime('1997/03/14 13:45:00 US/Eastern')
>>> 5 + dt
Either a DateTime or a number may be subtracted from a DateTime,
DateTime('1997/03/14 13:45:00 US/Eastern')
however, a DateTime may not be subtracted from a number.
Two DateTimes cannot be added:
other + aDateTimeAdd aDateTime to other.
>>> dt + dt
A DateTime may be added to a number and a number may be added to a
Traceback (most recent call last):
DateTime; two DateTimes cannot be added.
...
DateTimeError: Cannot add two DateTimes
int(aDateTime)
Either a DateTime or a number may be subtracted from a DateTime,
Convert to an integer number of days since Jan. 1, 1901 (gmt)
however, a DateTime may not be subtracted from a number:
long(aDateTime)
>>> DateTime('1997/03/10 13:45 US/Eastern') - dt
1.0
Convert to a long-int number of days since Jan. 1, 1901 (gmt)
>>> dt - 1
DateTime('1997/03/08 13:45:00 US/Eastern')
float(aDateTime)
>>> 1 - dt
Traceback (most recent call last):
Convert to floating-point number of days since Jan. 1, 1901 (gmt)
...
TypeError: unsupported operand type(s) for -: 'int' and 'instance'
-------------------------------------------------------------------------------
Last Modified: 14 March 1997
DateTimes can also be converted to integers (number of seconds since
the epoch), longs (not too long ;)) and floats:
>>> int(dt)
857933100
>>> long(dt)
857933100L
>>> float(dt)
857933100.0
lib/python/DateTime/tests/testDateTime.py
View file @
ecd8674c
...
@@ -379,7 +379,11 @@ class DateTimeTests(unittest.TestCase):
...
@@ -379,7 +379,11 @@ class DateTimeTests(unittest.TestCase):
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
)
from
zope.testing
import
doctest
return
unittest
.
TestSuite
([
unittest
.
makeSuite
(
DateTimeTests
),
doctest
.
DocFileSuite
(
'DateTime.txt'
,
package
=
'DateTime'
)
])
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
(
defaultTest
=
'test_suite'
)
unittest
.
main
(
defaultTest
=
'test_suite'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment