pyfdate
index
c:\mydata\www\pyfdate\pyfdate.py

@version: 0.5.6
@date:    2008-01-19
@status:  beta
@author:  Stephen Ferg
@contact: http://www.ferg.org/contact_info
@license: Creative Commons Attribution License 2.0 http://creativecommons.org/licenses/by/2.0/
@see:     http://www.ferg.org/pyfdate
@note:
 
ABOUT PYFDATE
 
The purpose of pyfdate is to provide a variety of
user-friendly features for working with datetimes, doing date arithmetic,
and formatting dates, times, and periods of time.
Pyfdate doesn't attempt to be all things to all people:
rather, its goal is to make it easy to do 95% if the things that people
want to do with dates and times.
 
Pyfdate provides two classes:
 
Time:
        - A specific point in time, identified by year, month, day, hour, minute, second.
        Python's datetime module calls this a "datetime".
 
Period:
        - An amount of time, measured in days, hours, minutes, and seconds.
 
In order to keep pyfdate simple, there are a number of things that it does not attempt to do.
        - Pyfdate doesn't provide any facilities for parsing strings into date/times.
        - The smallest unit of time that Pyfdate can handle is a second.
          It cannot be used to work with hundredths or thousandths of seconds.
        - Pyfdate doesn't know anything about timezones.
        - Pyfdate doesn't know anything about daylight savings time.
 
INTERNATIONAL LANGUAGE SUPPORT
 
By default, pyfdate's language for displaying
dates and times (e.g. weekday names and month names) is American English.
 
If pyfdate can successfully import pyfdate_local, the language for displaying
dates and times is taken from the pyfdate_local.py file.
 
Localization files are available for a number of languages.
For example: pyfdate_local_francais.py for French.
 
To use the file for language foobar, simply copy pyfdate_local_foobar.py to
pyfdate_local.py  And of course it is possible to customize
pyfdate_local.py for any particular language of your choice.
 
 
BACKGROUND
 
Many ideas for pyfdate functionality grew out of Steve Ferg's experiences with
an earlier (non-Python) program called "fdate", which provided datetime
arithmetic functionality for MS-DOS batch files. The name "pyfdate" is derived
from "Python" and "fdate".

 
Modules
       
copy
datetime
os
sys
time
types

 
Classes
       
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
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 including 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 hundredths of seconds.
@rtype: string
@return: a string containing the civil time including hundredths of seconds,
e.g.::
        "6:30:00pm"
 
@note: 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.
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_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 character to use. Defaults to the ISO standard: a dash.
get_isodatetime(self, sep='T')
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 character to use between date and time.
Default is the ISO standard, a capital letter "T".
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 character 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 character 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_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 character 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_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 including 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 hundredths of seconds.
@rtype: string
@return: a string containing the civil time including hundredths of seconds,
e.g.::
        "6:30:00pm"
 
@note: 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.
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"
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 character 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 character to use between date and time.
Default is the ISO standard, a capital letter "T".
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 character 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 character 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 including 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.
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 character 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"
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

 
Functions
       
CalendarMonthToNumericMonth(year, month)
Convert a calendar month (year,month)
to a numeric representation:
 
>>> CalendarMonthToNumericMonth(2007,4)
24075
 
@rtype: int
NumericMonthToCalendarMonth(months)
Convert a numeric representation of a month
to a calendar month (year, month).
 
>>> NumericMonthToCalendarMonth(24075)
(2007, 4)
 
@rtype: tuple
argsToString(*args)
A utility routine for showing arguments in error messages.
Useful for debugging.
 
>>> from pyfdate import *
>>> s = argsToString("test",2,Time())
>>> print s
arg     1: "test" <type 'str'>
arg     2: 2 <type 'int'>
arg     3: 2008-01-01 14:40:18 <type 'instance'>
 
@rtype: string
isLeapYear(year)
Return True if year is a leapyear; otherwise return False.
 
>>> isLeapYear(2004)
True
>>> isLeapYear(2000)
True
>>> isLeapYear(2005)
False
 
@rtype: boolean
@return: True if year is a leapyear; otherwise return False.
kwargsToString(**kwargs)
A utility routine for showing keyword arguments in error messages.
Useful for debugging.
 
>>> from pyfdate import *
>>> s = kwargsToString(first="test", second=2, third=Time())
>>> print s
first     : "test" <type 'str'>
second    : 2 <type 'int'>
third     : 2008-01-01 14:36:38 <type 'instance'>
 
@rtype: string
numsplit(s)
split a string into its numeric parts and return
a list containing the numeric parts converted to ints.
 
This function can be used to parse a string containing
an ISO datetime.
 
>>> from pyfdate import *
>>> numsplit("2007_10_09")
[2007, 10, 9]
>>> numsplit("2007-10-09T23:45:59")
[2007, 10, 9, 23, 45, 59]
>>> numsplit("2007/10/09 23.45.59")
[2007, 10, 9, 23, 45, 59]
to24hour(hour, ampm)
Convert an hour expressed as am/pm into one expressed in 24 hour time.
 
>>> to24hour(12,"am")
0
>>> to24hour(1,"am")
1
>>> to24hour(12,"PM")
12
>>> to24hour(1,"PM")
13
 
@rtype: int
@return: the number of of an hour in 24-hour (aka "military") time.
 
@type hour: int
@arg  hour: must be an integer (or a string that can be converted to an integer)
in the range of 1 to 12
 
@type ampm: string
@arg  ampm: must be a string containing either "am" or "pm" (in upper or lower case)

 
Data
        APRIL = 4
AUGUST = 8
CivilDateFormat = 'm d, y'
CivilTimeSeparator = ':'
DAY = 'day'
DAYS = 'days'
DECEMBER = 12
FEBRUARY = 2
FRIDAY = 5
HOUR = 'hour'
HOURS = 'hours'
HOURS_IN_DAY = 24
JANUARY = 1
JULY = 7
JUNE = 6
LANG = 'American English'
MARCH = 3
MAY = 5
MINUTE = 'minute'
MINUTES = 'minutes'
MINUTES_IN_DAY = 1440
MINUTES_IN_HOUR = 60
MONDAY = 1
MONTH = 'month'
MONTHS = 'months'
MONTH_NAMES = {1: 'January', 2: 'February', 3: 'March', 4: 'April', 5: 'May', 6: 'June', 7: 'July', 8: 'August', 9: 'September', 10: 'October', ...}
NEAREST = 'NEAREST'
NEXT = 'NEXT'
NORMAL_DAYS_IN_MONTH = {1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, ...}
NOVEMBER = 11
OCTOBER = 10
PREVIOUS = 'PREVIOUS'
SATURDAY = 6
SECOND = 'second'
SECONDS = 'seconds'
SECONDS_IN_DAY = 86400
SECONDS_IN_HOUR = 3600
SECONDS_IN_MINUTE = 60
SEPTEMBER = 9
SUNDAY = 7
THURSDAY = 4
TUESDAY = 2
TimeExpressedIn24Hours = False
WEDNESDAY = 3
WEEK = 'week'
WEEKDAY_NAMES = {1: 'Monday', 2: 'Tuesday', 3: 'Wednesday', 4: 'Thursday', 5: 'Friday', 6: 'Saturday', 7: 'Sunday'}
WEEKS = 'weeks'
YEAR = 'year'
YEARS = 'years'