| |
- Period
- Time
class Period |
|
A pyfdate.Period is an amount of time.
pyfdate.Period performs a function similar to the standard library datetime.timedelta.
pyfdate.Period, however, is implemented differently than the datetime.timedelta class.
pyfdate.Period stores only a single value: self.period_seconds.
This may be a positive or negative value.
pyfdate.Period objects (like datetime.timedelta objects) are used to do date
arithmetic. But since pyfdate.Time provides more sophisticated date
arithmetic features than datetime.datetime, pyfdate. Periods are probably
more widely used for their display capabilities than for their date
arithmetic capabilities. |
|
Methods defined here:
- __abs__(self)
- Returns a clone of myself, with my absolute value.
@return: a clone of myself, with my absolute value
@rtype: Period
- __add__(self, arg)
- Add one period to another.
@return: a new Period object
@rtype: Period
- __eq__(self, arg)
- Compare two Period objects for equality.
@rtype: boolean
- __ge__(self, arg)
- Compares two Period objects to determine if one is greater than,
or equal to, the other.
@rtype: boolean
- __gt__(self, arg)
- Compares two Period objects to determine if one is greater than the other.
@rtype: boolean
- __init__(self, arg1=0, hours=0, minutes=0, seconds=0)
- Thhe constructor of a Period object.
Constructor expects arguments of:
- a series of positional arguments: [days [, hours[,minutes[,seconds]]]], or
- a datetime.timedelta object, or
- a pyfdate.Period object
@rtype: Period
- __le__(self, arg)
- Compares two Period objects to determine if one is less than,
or equal to, the other.
@rtype: boolean
- __lt__(self, arg)
- Compares two Period objects to determine if one is less than the other.
@rtype: boolean
- __neq__(self, arg)
- Compare two Period objects for inequality.
@rtype: boolean
- __str__(self)
- Returns a string representation of a Period.
@rtype: string
@return: a string representation of a Period.
e.g.::
"4 days 3 hours 20 minutes 45 seconds"
- __sub__(self, arg)
- Subtract one period from another.
@return: a new Period object
@rtype: Period
- add(self, **kwargs)
- A general method for adding time to a Period object. To
subtract time, add time in negative increments or use the subtract() method.
@rtype: Period
@note:
Example::
p1 = Period()
p2 = p1.plus(weeks=2,days=3,hours=4,minutes=99, seconds=1)
- clone(self)
- Return a clone of myself.
@return: a clone of myself
@rtype: Period
- get_asDays(self)
- Returns this Period, expressed in units of days.
@return: myself, expressed in units of days
@rtype: int
- get_asHours(self)
- Returns this Period, expressed in units of hours.
@return: myself, expressed in units of hours
@rtype: int
- get_asMinutes(self)
- Returns this Period, expressed in units of minutes.
@return: myself, expressed in units of minutes
@rtype: int
- get_asSeconds(self)
- Returns this Period, expressed in units of seconds.
@return: myself, expressed in units of seconds
@rtype: int
- get_days(self)
- Return the days portion of the period, as an int.
@rtype: int
@return: days, e.g.::
3
- get_hours(self)
- Return the hours portion of the Period, as an int.
@rtype: int
@return: hours, e.g.::
15
- get_minutes(self)
- Return the minutes portion of the Period, as an int.
@rtype: int
@return: minutes, e.g.::
45
- get_p(self, **kwargs)
- Return myself in a nicely-formatted string.
@rtype: string
@return: myself in a nicely-formatted string, e.g.::
"2 days 3 hours 0 minutes 45 seconds"
@note:
::
if keyword arg showZeroComponents == True:
all components (days, hours, minutes, seconds) will be shown
else:
only non-zero components (except seconds) will be shown
if the period is empty (has a duration of zero):
if keyword arg showZeroPeriod == True:
return "0 seconds"
else:
return "" # the empty string
- get_seconds(self)
- Return the seconds portion of the Period, as an int.
@rtype: int
@return: seconds, e.g.::
45
- get_short(self)
- Return myself as a nicely formatted string: suppress components whose value is zero.
@rtype: string
@return: myself nicely formatted: suppress components whose value is zero.
If my duration is zero, return "0 seconds". e.g.::
"2 days 3 hours"
@note: This method will never return an empty string.
If my duration is zero, then it returns the string "0 seconds"
- get_shortest(self)
- Return myself as a nicely formatted string: suppress components whose value is zero.
@rtype: string
@return: myself nicely formatted: suppress components whose value is zero.
e.g.::
"2 days 3 hours"
@note: If my duration is 0, this method will return an empty string.
- get_timedelta(self)
- Returns a Period expressed as a datetime.timedelta object
@return: a Period expressed as a datetime.timedelta object
@rtype: timedelta
- get_tuple(self)
- Returns myself formatted as a 4-tuple of ints (days, hours, minutes, seconds).
@return: myself formatted as a 4-tuple of ints (days, hours, minutes, seconds)
@rtype: tuple
- minus = subtract(self, **kwargs)
- plus = add(self, **kwargs)
- subtract(self, **kwargs)
- A general method for subtracting time from a Period object.
@rtype: Period
@note: Example:
::
p1 = Period()
p2 = p1.plus(weeks=2,days=3,hours=4,minutes=99, seconds=1)
Data descriptors defined here:
- asDays
- Returns this Period, expressed in units of days.
@return: myself, expressed in units of days
@rtype: int
- asHours
- Returns this Period, expressed in units of hours.
@return: myself, expressed in units of hours
@rtype: int
- asMinutes
- Returns this Period, expressed in units of minutes.
@return: myself, expressed in units of minutes
@rtype: int
- asSeconds
- Returns this Period, expressed in units of seconds.
@return: myself, expressed in units of seconds
@rtype: int
- days
- Return the days portion of the period, as an int.
@rtype: int
@return: days, e.g.::
3
- hours
- Return the hours portion of the Period, as an int.
@rtype: int
@return: hours, e.g.::
15
- minutes
- Return the minutes portion of the Period, as an int.
@rtype: int
@return: minutes, e.g.::
45
- p
- Return myself in a nicely-formatted string.
@rtype: string
@return: myself in a nicely-formatted string, e.g.::
"2 days 3 hours 0 minutes 45 seconds"
@note:
::
if keyword arg showZeroComponents == True:
all components (days, hours, minutes, seconds) will be shown
else:
only non-zero components (except seconds) will be shown
if the period is empty (has a duration of zero):
if keyword arg showZeroPeriod == True:
return "0 seconds"
else:
return "" # the empty string
- seconds
- Return the seconds portion of the Period, as an int.
@rtype: int
@return: seconds, e.g.::
45
- short
- Return myself as a nicely formatted string: suppress components whose value is zero.
@rtype: string
@return: myself nicely formatted: suppress components whose value is zero.
If my duration is zero, return "0 seconds". e.g.::
"2 days 3 hours"
@note: This method will never return an empty string.
If my duration is zero, then it returns the string "0 seconds"
- shortest
- Return myself as a nicely formatted string: suppress components whose value is zero.
@rtype: string
@return: myself nicely formatted: suppress components whose value is zero.
e.g.::
"2 days 3 hours"
@note: If my duration is 0, this method will return an empty string.
- timedelta
- Returns a Period expressed as a datetime.timedelta object
@return: a Period expressed as a datetime.timedelta object
@rtype: timedelta
- tuple
- Returns myself formatted as a 4-tuple of ints (days, hours, minutes, seconds).
@return: myself formatted as a 4-tuple of ints (days, hours, minutes, seconds)
@rtype: tuple
|
class Time |
|
A specific point in time, identified by
year, month, day, hour, minute, second.
Python's datetime module calls this a "datetime". |
|
Methods defined here:
- __add__(self, arg)
- Add a Period to this Time to produce a new Time.
@rtype: Time
- __eq__(self, arg)
- Compare two Time objects for equality.
@rtype: boolean
- __ge__(self, arg)
- Compare two Time objects for relative position in time.
@rtype: boolean
- __gt__(self, arg)
- Compare two Time objects to determine if one is later (greater than) the other.
@rtype: boolean
- __init__(self, arg1=None, month=1, day=1, hour=0, minute=0, second=0)
- The constructor for a Time object.
Constructor expects arguments of:
- None (this will construct a Time object from current date/time) or
- a datetime.datetime object, or
- a pyfdate.Time object, or
- a series of positional arguments: year [,month[,day[,hour[,minute[,second]]]]]
@rtype: Time
- __le__(self, arg)
- Compare two Time objects for relative position in time.
@rtype: boolean
- __lt__(self, arg)
- Compare two Time objects for relative position in time.
@rtype: boolean
- __neq__(self, arg)
- Compare two Time objects for inequality.
@rtype: boolean
- __str__(self)
- Return a string representation of self as an isodate + space + isotime
@rtype: string
@return: self as an isodate + space + isotime, e.g.::
"2007-03-02 09:30:45"
- __sub__(self, arg)
- Subtract a Period or a Time from this Time object.
@rtype: Time or Period
@return: a Time (if <arg> is a Period) or a Period (if <arg> is a Time)
@arg arg: a Period object or a Time object
@type arg: Period or Time
@note:
::
If <arg> is a Period object:
Subtract a Period from this Time to produce a new Time,
else, if <arg> is a Time object:
Subtract one Time from another Time to produce a Period.
@note:
If a Period is returned, it is signed. That is::
If an earlier time is subtracted from a later time:
The Period will be positive
else:
the Period will be negative.
- add(self, **kwargs)
- A method to add time to a Time object.
This is the basic method for doing date/time arithmetic.
The units and amounts of time are specified as keyword arguments.
@rtype: Time
@return: a new Time object with the specified amounts of time added to it.
@note: To subtract amounts, you can add negative amounts (see the example)
or use the 'subtract' method.
@note: Example: To get the time that is a month and a week from the current time::
t = Time().add(months=1,weeks=1)
@note: Example: To get the time that is a month and a week from the current time::
t = Time().add(months=1).plus(weeks=1)
@note: Example: To subtract 6 weeks from the current time::
t = Time().add(weeks=-6) # note the minus sign: -6.
- addmonths(self, months)
- A method for adding months to a time object.
>>> t1 = Time(2004,1,31)
>>> t1.d
'January 31, 2004'
>>> t2 = t1.addmonths(1)
>>> t2.d
'February 29, 2004'
>>> t2 = t1.add(months=8)
>>> t2.d
'September 30, 2004'
@rtype: Time
@return: a new Time object with the specified amounts of time added to it.
@note:
You can use this method directly, e.g.::
t = Time().addmonths(6)
Or you can use the standard add() method::
t = Time().add(months=6)
- anniversaryOf(self, eventTime)
- The most recent anniversary of myself.
@return: The most recent anniversary of some event, previous to today.
@rtype: Time
@arg eventTime: the time of the event whose anniversary we want
@type eventTime: Time
@note: In a non-leapyear, the anniversary of an event that occurred
on February 29 of a leapyear will be moved to February 28.
- clone(self, **kwargs)
- Return a clone of myself.
@return: a clone of myself
@rtype: Time
@note:
It is possible to change certain parts of the cloned Time
by using keyword arguments for the component(s) to
be replaced in the clone. To make a clone of the current
time, but one set in the year 1935, for example::
t1 = Time()
t2 = t1.clone(year=1935)
Note that it is possible to trigger a ValueError, if
for example:
- The current date is February 29, 2004 (a leap year) and the
year is reset to 2007 (not a leap year).
- The current date is January 31 and the month is reset to
September (which has only 30 days).
If you *want* to raise a ValueError when such problems occur,
use the clone() method. Otherwise, use the goto() method,
which attempts to recover from such errors::
t1 = Time()
t2 = t1.goto(year=1935)
- diff(self, eventTime)
- Determine the difference (a Period) between two Times.
@rtype: Period
@note:
Unlike the __sub__ method, the diff (i.e. difference) method
always returns a Period object with a positive value.
- diffm = diffmonths(self, eventTime)
- diffmonths(self, eventTime)
- Determine the difference (a Period) between myself and the time of some event.
@rtype: tuple
@examle:
Returns the difference between two Time objects as a tuple of
(months, Period), so the Period part can be formatted as desired::
personDateOfBirth = Time(1946,5,8,6,45)
months, days = Time().diffm(personDateOfBirth)
print ("He is " + str(months) + " " + str(days) + " old.")
- diffy = diffyears(self, eventTime)
- diffyears(self, eventTime)
- Determine the difference (a Period) between myself and the time of some event.
@rtype: tuple
@note:
returns the difference between two Time objects as a tuple of
(years, Period)
- diffyearsmonths(self, eventTime)
- Determine the difference (a Period) between myself and the time of some event.
@rtype: tuple
@note:
returns the difference between two Time objects as a tuple of
(years,months, Period)
- diffym = diffyearsmonths(self, eventTime)
- exitWeekend(self, direction=None)
- return a new Time object which has been moved so it does not fall
on a Saturday or Sunday.
@rtype: Time
@type direction: string
@arg direction: the direction in which to exit the weekend::
@note:
If the weekday of the current object occurs on the weekend, the
weekday of the new object is moved out of the weekend::
if <direction> is NEXT , the day is moved to the following Monday.
if <direction> is PREVIOUS, the day is moved to the previous Friday.
if <direction> is None , then
- a Saturday is moved to the previous Friday
- a Sunday is moved to the following Monday
- flex(self, baseTime)
- A method for adding days to a date, based on a base date. If the
day-of-month of my time is less than the day-of-month of the baseTime,
then calculate the number of days difference and add them to my time.
This method is designed to be used when doing monthly arithmetic.
In the following example, we add 1 month to January 31. Because
February contains only 28 days, we get February 28.
If we want to get the counterpart of January 31 in February
(February 31, which resolves to March 3) we can "flex" the
date based on the base date of January 31.
>>> startDate = Time(2003,1,31)
>>> startDate.d
'January 31, 2003'
>>> startDate.add(months=1).d
'February 28, 2003'
>>> startDate.add(months=1).flex(startDate).d
'March 3, 2003'
@rtype: Time
@return: a new Time object that has been "flexed" based on the baseTime
- fromFile(self, filename)
- @return: a new Time object with the datetime of the last modification
date of the file with <filename>.
@rtype: Time
@arg filename: a filename
@type filename: string
- fromTimestamp(self, timestamp)
- @return: a new Time object with the datetime from <timestamp>.
@rtype: Time
@arg timestamp: a timestamp
@type timestamp: timestamp
@see: the datetime module for documentation
- get_civildate(self)
- Return a string containing the civildate.
@rtype: string
@return: the civildate, e.g.::
"April 30, 2007"
- get_civiltime(self, **kwargs)
- Return a string containing the civil time.
If keyword arg showseconds=True, time will include seconds.
If keyword arg showHundredthsOfSeconds=True, time will include hundredths of seconds.
Note that hundredths of seconds are faked to "00".
This is primarily for MS-DOS timestamps which show hundredths of seconds,
even though the clocks of PCs are not accurate to hundredths of seconds.
@rtype: string
@return: a string containing the civil time, e.g.::
"6:30pm"
@note:
Civil time as used in United States of America::
midnight = 12:00am
time between midnight and noon = am
noon = 12:00pm
time between noon and midnight = am
@type showseconds: boolean
@keyword showseconds: defaults to False.
@type showHundredthsOfSeconds: boolean
@keyword showHundredthsOfSeconds: defaults to False.
- get_civiltime2(self)
- Return a string containing the civil time (including seconds.)
@rtype: string
@return: a string containing the civil time including seconds,
e.g.::
"6:30:45pm"
- get_d(self)
- Return a string containing the civildate.
@rtype: string
@return: the civildate, e.g.::
"April 30, 2007"
- get_day(self)
- Return the day part of the datetime.
@return: day
@rtype: int
- get_dostime(self)
- Return the datetime in the format used by Microsoft's MS-DOS.
@rtype: string
@return: the datetime in the format used by Microsoft's MS-DOS
- get_dt(self)
- Return a string containing the civildate and the time, e.g. "April 30, 2007 6:30pm".
@rtype: string
@return: the civildate and the time, e.g.::
"April 30, 2007 6:30pm"
- get_dt2(self)
- Return a string containing the civildate and the time (including seconds)
e.g. "April 30, 2007 6:30:45pm".
@rtype: string
@return: the civildate and the time, e.g.::
"April 30, 2007 6:30:45pm"
- get_hour(self)
- Return the hour portion of the Time, as an int.
@return: hour
@rtype: int
- get_isodate(self, sep='-')
- Return a string containing an ISO date in format yyyy-mm-dd, e.g. "2007-10-09"
@rtype: string
@return: an ISO date in format yyyy-mm-dd, e.g.::
"2007-10-09" # Oct 9, 2007
@type sep: string
@arg sep: separator string to use. Defaults to the ISO standard: a dash.
- get_isodatetime(self, sep='T', datesep='-', timesep=':', seps=None)
- Return a string containing an ISO datetime in format yyyy-mm-ddThh:mm:ss.
@rtype: string
@return: an ISO datetime in format yyyy-mm-ddThh:mm:ss, e.g.::
"2007-10-09T11:15:00" # Oct 9, 2007 at 11:15 in the morning
@type sep: string
@arg sep: separator string to use between date and time.
Default is the ISO standard, a capital letter "T".
@arg datesep: separator string to use within date.
Default is the ISO standard, a dash "-".
@arg timesep: separator string to use within time.
Default is the ISO standard, a colon ":".
@arg seps: separator string to use within and between date and time.
If specified, seps over-rides the other separators.
Note that the value for seps may be a zero-length string.
"seps" is useful for constructing datetime strings for things like
datestamps and filenames.
- get_isofilename(self, sep='-')
- Return a string containing the ISO datetime in a format suitable for making a filename.
@rtype: string
@return: the ISO datetime in a format suitable for making a filename. E.g.::
"2007-10-09-11-15-00" # Oct 9, 2007 at 11:15 in the morning
@note: All parts of the datetime will be separated by dashes.
@note: A collection of these strings, sorted using a standard string sort,
will sort in temporal order.
@type sep: string
@arg sep: separator string to use between datetime parts. Default = "-"
- get_isotime(self, sep=':')
- Return a string containing ISO time in format hh:mm:ss, e.g. "11:15:00".
@rtype: string
@return: an ISO time in format hh:mm:ss, e.g.::
"11:15:00" # 11:15 in the morning
@type sep: string
@arg sep: separator string to use. Defaults to the ISO standard: a colon.
- get_isoweekday(self)
- Return the ISO weekday number as an int, where Monday=1 .. Sunday=7
@rtype: int
@return: the ISO weekday number, e.g.::
1 # first day of the week, Monday
- get_isoweeknumber(self)
- Return the ISO week number, as an int.
@rtype: int
@return: the ISO week number, e.g.::
1 # first week of the year
- get_minute(self)
- Return the minute portion of a Time, as an int.
@rtype: int
@return: minute, e.g.::
15 # 15 minutes past the beginning of the hour
- get_month(self)
- Return the month portion of a Time, as an int.
@rtype: int
@return: month, e.g.::
12 # for the 12th month, December
- get_monthname(self)
- Return a string containing the natural language name of the month.
@rtype: string
@return: monthname, e.g.::
"December"
- get_second(self)
- Return the second portion of a Time, as an int.
@return: second
@rtype: int
- get_t2d(self)
- Return a string containing the time and the civil date
(including seconds).
@rtype: string
@return: the time and the civildate, e.g.::
"6:30:45pm April 30, 2007"
- get_t2wd(self)
- Return a string containing the time (including seconds),
the weekday name, and the civildate.
@rtype: string
@return: the time (including seconds), the weekday name, and the civildate, e.g.::
"6:30:45pm Monday April 30, 2007"
- get_td(self)
- Return a string containing the time and the civil date.
@rtype: string
@return: the time and the civildate, e.g.::
"6:30pm April 30, 2007"
- get_tuple(self)
- Return a tuple containing the parts of the datetime.
@rtype: tuple
@return: myself formatted as a 6-tuple of ints (year, month, day, hour, minute, second).
E.g.::
(2007,10,9,11,15,0) # Oct 9, 2007 at 11:15 in the morning
- get_twd(self)
- Return a string containing the time, the weekday name, and the civildate.
@rtype: string
@return: the time, the weekday name, and the civildate, e.g.::
"6:30pm Monday April 30, 2007"
- get_unixdate(self, sep='-')
- Return a string containing a Unix date, e.g. "07-DEC-2006".
@rtype: string
@return: a string containing a Unix date, e.g.::
"07-DEC-2006"
@type sep: string
@arg sep: separator string to use. Defaults to a dash.
- get_wd(self)
- Returns a string containing the weekday name and the civildate.
@rtype: string
@return: the weekday name and the civildate.
e.g.::
"Monday April 30, 2007"
- get_wdt(self)
- Returns a string containing the weekday name, the civildate, and the time.
@rtype: string
@return: the weekday name, the civildate, and the time, e.g.::
"Monday April 30, 2007 6:30pm"
- get_wdt2(self)
- Returns a string containing the weekday name, the civildate,
and the time (including seconds).
@rtype: string
@return: the weekday name, the civildate, and the time, e.g.::
"Monday April 30, 2007 6:30:45pm"
- get_weekdayname(self, weekday=None)
- Returns the natural language name of the day of the week.
@rtype: string
@return: the natural language name of the day of the week, e.g.::
"Monday"
@type weekday: int
@arg weekday: the ISO weekday number. If not specified, defaults
to the weekday of self (this Time object).
- get_year(self)
- Return the year as an int, e.g. 2007
@rtype: int
@return: year, e.g.::
2007
- get_yearstring(self)
- Return the year as a string, e.g. "2007"
@rtype: string
@return: year,
e.g.::
"2007"
- goto(self, **kwargs)
- Returns a clone of self but with some component(s)
(year, month, day, hour, minute, second) reset to a new value.
@rtype: Time
@return: a new Time object in which the time has been moved
according to the keyword args
@note:
A "goto" can fail in a number of ways.
- The current date is February 29, 2004 (a leap year) and the
year is reset to 2007 (not a leap year).
- The current date is January 31 and the month is reset to
September (which has only 30 days).
@note: This method attempts to recover from such failures by decrementing
the "day" value to 28 before failing.
@note: Example:
To obtain a Time object whose date is May 15, 2003::
t = Time(2007,5,15)
t2 = t.goto(year=2003)
@note: Example:
To obtain a time object whose date is February 28, 2007::
t = Time(2004,2,29) # a leap year
t2 = t.goto(year=2007) # not a leap year
- gotoMonth(self, argMonth, direction='NEXT', **kwargs)
- Returns a new Time object in which the month has been moved to the specified
argMonth.
@rtype: Time
@return: a new Time object in which the month has been moved to the specified
month number.
@type argMonth: int
@arg argMonth:
The argMonth number should be specified by means
of one of pyfdate's month number constants (JANUARY, FEBRUARY, etc.)
@type direction: string
@arg direction: The direction in time::
If direction == NEXT , we will move forward in time to the following month
If direction == PREVIOUS, we will move backward in time to the preceding month
If direction == NEAREST , we will move to the nearest month
@type useToday: boolean
@keyword useToday:
If the current month is the same as argMonth, the value of the
useToday flag (True or False) will determine whether or not we use
the current month, or ignore it, in our search for the NEXT, PREVIOUS, or NEAREST month.
@note: Example:
If this month is April, to move the date to the following November::
t = Time().gotoMonth(NOVEMBER)
or
t = Time().gotoMonth(NOVEMBER,NEXT)
@note: Example:
If this month is April, to move the date to the previous November::
t = Time().gotoMonth(NOVEMBER, PREVIOUS)
@note: Example:
If this month is April, to move the date to the nearest November::
t = Time().gotoMonth(NOVEMBER, NEAREST)
@note:
Question::
If today is in November and we want to go to the NEXT (or PREVIOUS) November,
is today considered to be in the next (or previous) November?
Answer::
If useToday == True: (which is the default)
today is considered to be in the nearest November.
else: (useToday=False has been specified as a keyword arg)
today is ignored in determining the NEXT (or PREVIOUS) November.
Question::
If today is November and we want to go to the NEAREST November
and we have specified useToday=False,
which is the nearest November: last November or next November?
Answer::
NEXT (i.e. the future) November is considered nearest.
- gotoMonthBegin(self)
- Return a new Time object in which the time has been moved to the beginning of the month.
@rtype: Time
@return: a new Time object in which the time has been moved to the beginning of the month.
@note:
Example:
If today is May 15, 2007 then to obtain a time object whose date is May 1::
t = Time().gotoMonthBegin()
- gotoMonthEnd(self)
- Return a new Time object in which the time has been moved to the end of the month.
@rtype: Time
@return: a new Time object in which the time has been moved to the end of the month.
@note: Example:
If today is May 15, 2007 then to obtain a time object whose date is May 31::
t = Time().gotoMonthEnd()
- gotoWeekday(self, argWeekday, direction='NEXT', **kwargs)
- Return a new Time object in which
the date has been moved to the specified argWeekday.
@rtype: Time
@return: a new Time object in which the time has been moved to the specified weekday.
@type argWeekday: int
@arg argWeekday:
The argWeekday number should be specified by means
of one of pyfdate's weekday number constants (MONDAY, TUESDAY, etc.)
@type direction: string
@arg direction: The direction in time::
If direction == NEXT , we will move forward in time to the following weekday
If direction == PREVIOUS, we will move backward in time to the preceding weekday
If direction == NEAREST , we will move to the nearest weekday
@type useToday: boolean
@keyword useToday:
If the current weekday is the same as argWeekday, the value of the
useToday flag (True or False) will determine whether we use the current date,
or ignore it, in our search for the NEXT, PREVIOUS, or NEAREST weekday.
- gotoYearBegin(self)
- Return a new Time object in which the time has been moved to the beginning of year.
@rtype: Time
@return: a new Time object in which the time has been moved to the beginning of year.
@note: Example:
If today is May 15, 2007 then to obtain a time object whose date is January 1, 2007::
t = Time().gotoYearBegin()
- gotoYearEnd(self)
- Return a new Time object in which the time has been moved to the end of the year.
@rtype: Time
@return: a new Time object in which the time has been moved to the end of the year.
@note: Example:
If today is May 15, 2007 then to obtain a time object whose date is December 31, 2007::
t = Time().gotoYearEnd()
- isLeapYear(self)
- Return a boolean indicating whether the year is or is not a leap year.
@return: True if a <year> is a leap year; otherwise return False.
@rtype: boolean
- minus = subtract(self, **kwargs)
- plus = add(self, **kwargs)
- subtract(self, **kwargs)
- Subtract some amounts of time from the current time. Syntactic sugar
for cases in which you don't want to "add" negative amounts of time.
@rtype: Time
@return: a new Time object in which the time has been moved by the specified amounts.
Coding Example::
t1 = Time()
t2 = t1.subtract(weeks=2,days=3,hours=4,minutes=99, seconds=1)
Data descriptors defined here:
- civildate
- Return a string containing the civildate.
@rtype: string
@return: the civildate, e.g.::
"April 30, 2007"
- civiltime
- Return a string containing the civil time.
If keyword arg showseconds=True, time will include seconds.
If keyword arg showHundredthsOfSeconds=True, time will include hundredths of seconds.
Note that hundredths of seconds are faked to "00".
This is primarily for MS-DOS timestamps which show hundredths of seconds,
even though the clocks of PCs are not accurate to hundredths of seconds.
@rtype: string
@return: a string containing the civil time, e.g.::
"6:30pm"
@note:
Civil time as used in United States of America::
midnight = 12:00am
time between midnight and noon = am
noon = 12:00pm
time between noon and midnight = am
@type showseconds: boolean
@keyword showseconds: defaults to False.
@type showHundredthsOfSeconds: boolean
@keyword showHundredthsOfSeconds: defaults to False.
- civiltime2
- Return a string containing the civil time (including seconds.)
@rtype: string
@return: a string containing the civil time including seconds,
e.g.::
"6:30:45pm"
- civiltimebase
- A utility method for other civiltime methods.
@rtype: tuple
@return: a tuple containing the components of civiltime::
(hour, minute, second, am_pm_flag)
- d
- Return a string containing the civildate.
@rtype: string
@return: the civildate, e.g.::
"April 30, 2007"
- day
- Return the day part of the datetime.
@return: day
@rtype: int
- dostime
- Return the datetime in the format used by Microsoft's MS-DOS.
@rtype: string
@return: the datetime in the format used by Microsoft's MS-DOS
- dt
- Return a string containing the civildate and the time, e.g. "April 30, 2007 6:30pm".
@rtype: string
@return: the civildate and the time, e.g.::
"April 30, 2007 6:30pm"
- dt2
- Return a string containing the civildate and the time (including seconds)
e.g. "April 30, 2007 6:30:45pm".
@rtype: string
@return: the civildate and the time, e.g.::
"April 30, 2007 6:30:45pm"
- hour
- Return the hour portion of the Time, as an int.
@return: hour
@rtype: int
- isodate
- Return a string containing an ISO date in format yyyy-mm-dd, e.g. "2007-10-09"
@rtype: string
@return: an ISO date in format yyyy-mm-dd, e.g.::
"2007-10-09" # Oct 9, 2007
@type sep: string
@arg sep: separator string to use. Defaults to the ISO standard: a dash.
- isodatetime
- Return a string containing an ISO datetime in format yyyy-mm-ddThh:mm:ss.
@rtype: string
@return: an ISO datetime in format yyyy-mm-ddThh:mm:ss, e.g.::
"2007-10-09T11:15:00" # Oct 9, 2007 at 11:15 in the morning
@type sep: string
@arg sep: separator string to use between date and time.
Default is the ISO standard, a capital letter "T".
@arg datesep: separator string to use within date.
Default is the ISO standard, a dash "-".
@arg timesep: separator string to use within time.
Default is the ISO standard, a colon ":".
@arg seps: separator string to use within and between date and time.
If specified, seps over-rides the other separators.
Note that the value for seps may be a zero-length string.
"seps" is useful for constructing datetime strings for things like
datestamps and filenames.
- isofilename
- Return a string containing the ISO datetime in a format suitable for making a filename.
@rtype: string
@return: the ISO datetime in a format suitable for making a filename. E.g.::
"2007-10-09-11-15-00" # Oct 9, 2007 at 11:15 in the morning
@note: All parts of the datetime will be separated by dashes.
@note: A collection of these strings, sorted using a standard string sort,
will sort in temporal order.
@type sep: string
@arg sep: separator string to use between datetime parts. Default = "-"
- isotime
- Return a string containing ISO time in format hh:mm:ss, e.g. "11:15:00".
@rtype: string
@return: an ISO time in format hh:mm:ss, e.g.::
"11:15:00" # 11:15 in the morning
@type sep: string
@arg sep: separator string to use. Defaults to the ISO standard: a colon.
- isoweekday
- Return the ISO weekday number as an int, where Monday=1 .. Sunday=7
@rtype: int
@return: the ISO weekday number, e.g.::
1 # first day of the week, Monday
- isoweeknumber
- Return the ISO week number, as an int.
@rtype: int
@return: the ISO week number, e.g.::
1 # first week of the year
- m
- Return a string containing the natural language name of the month.
@rtype: string
@return: monthname, e.g.::
"December"
- minute
- Return the minute portion of a Time, as an int.
@rtype: int
@return: minute, e.g.::
15 # 15 minutes past the beginning of the hour
- month
- Return the month portion of a Time, as an int.
@rtype: int
@return: month, e.g.::
12 # for the 12th month, December
- monthname
- Return a string containing the natural language name of the month.
@rtype: string
@return: monthname, e.g.::
"December"
- second
- Return the second portion of a Time, as an int.
@return: second
@rtype: int
- t
- Return a string containing the civil time.
If keyword arg showseconds=True, time will include seconds.
If keyword arg showHundredthsOfSeconds=True, time will include hundredths of seconds.
Note that hundredths of seconds are faked to "00".
This is primarily for MS-DOS timestamps which show hundredths of seconds,
even though the clocks of PCs are not accurate to hundredths of seconds.
@rtype: string
@return: a string containing the civil time, e.g.::
"6:30pm"
@note:
Civil time as used in United States of America::
midnight = 12:00am
time between midnight and noon = am
noon = 12:00pm
time between noon and midnight = am
@type showseconds: boolean
@keyword showseconds: defaults to False.
@type showHundredthsOfSeconds: boolean
@keyword showHundredthsOfSeconds: defaults to False.
- t2
- Return a string containing the civil time (including seconds.)
@rtype: string
@return: a string containing the civil time including seconds,
e.g.::
"6:30:45pm"
- t2d
- Return a string containing the time and the civil date
(including seconds).
@rtype: string
@return: the time and the civildate, e.g.::
"6:30:45pm April 30, 2007"
- t2wd
- Return a string containing the time (including seconds),
the weekday name, and the civildate.
@rtype: string
@return: the time (including seconds), the weekday name, and the civildate, e.g.::
"6:30:45pm Monday April 30, 2007"
- td
- Return a string containing the time and the civil date.
@rtype: string
@return: the time and the civildate, e.g.::
"6:30pm April 30, 2007"
- twd
- Return a string containing the time, the weekday name, and the civildate.
@rtype: string
@return: the time, the weekday name, and the civildate, e.g.::
"6:30pm Monday April 30, 2007"
- unixdate
- Return a string containing a Unix date, e.g. "07-DEC-2006".
@rtype: string
@return: a string containing a Unix date, e.g.::
"07-DEC-2006"
@type sep: string
@arg sep: separator string to use. Defaults to a dash.
- w
- Returns the natural language name of the day of the week.
@rtype: string
@return: the natural language name of the day of the week, e.g.::
"Monday"
@type weekday: int
@arg weekday: the ISO weekday number. If not specified, defaults
to the weekday of self (this Time object).
- wd
- Returns a string containing the weekday name and the civildate.
@rtype: string
@return: the weekday name and the civildate.
e.g.::
"Monday April 30, 2007"
- wdt
- Returns a string containing the weekday name, the civildate, and the time.
@rtype: string
@return: the weekday name, the civildate, and the time, e.g.::
"Monday April 30, 2007 6:30pm"
- wdt2
- Returns a string containing the weekday name, the civildate,
and the time (including seconds).
@rtype: string
@return: the weekday name, the civildate, and the time, e.g.::
"Monday April 30, 2007 6:30:45pm"
- weekday
- Return the ISO weekday number as an int, where Monday=1 .. Sunday=7
@rtype: int
@return: the ISO weekday number, e.g.::
1 # first day of the week, Monday
- weekdayname
- Returns the natural language name of the day of the week.
@rtype: string
@return: the natural language name of the day of the week, e.g.::
"Monday"
@type weekday: int
@arg weekday: the ISO weekday number. If not specified, defaults
to the weekday of self (this Time object).
- weeknumber
- Return the ISO week number, as an int.
@rtype: int
@return: the ISO week number, e.g.::
1 # first week of the year
- y
- Return the year as a string, e.g. "2007"
@rtype: string
@return: year,
e.g.::
"2007"
- year
- Return the year as an int, e.g. 2007
@rtype: int
@return: year, e.g.::
2007
| |