Module pyfdate :: Class Time
[hide private]
[frames] | no frames]

Class Time

source code

A specific point in time, identified by year, month, day, hour, minute, second.

Python's datetime module calls this a "datetime".

Instance Methods [hide private]
Time
__init__(self, arg1=None, month=1, day=1, hour=0, minute=0, second=0)
The constructor for a Time object.
source code
Time
__add__(self, arg)
Add a Period to this Time to produce a new Time.
source code
boolean
__eq__(self, arg)
Compare two Time objects for equality.
source code
boolean
__ge__(self, arg)
Compare two Time objects for relative position in time.
source code
boolean
__gt__(self, arg)
Compare two Time objects to determine if one is later (greater than) the other.
source code
boolean
__le__(self, arg)
Compare two Time objects for relative position in time.
source code
boolean
__lt__(self, arg)
Compare two Time objects for relative position in time.
source code
boolean
__neq__(self, arg)
Compare two Time objects for inequality.
source code
string
__str__(self)
Return a string representation of self as an isodate + space + isotime
source code
Time or Period
__sub__(self, arg)
Subtract a Period or a Time from this Time object.
source code
Time
add(self, **kwargs)
A method to add time to a Time object.
source code
Time
plus(self, **kwargs)
A method to add time to a Time object.
source code
Time
addmonths(self, months)
A method for adding months to a time object.
source code
Time
anniversaryOf(self, eventTime)
The most recent anniversary of myself.
source code
Time
clone(self, **kwargs)
Return a clone of myself.
source code
Period
diff(self, eventTime)
Determine the difference (a Period) between two Times.
source code
tuple
diffyears(self, eventTime)
Determine the difference (a Period) between myself and the time of some event.
source code
tuple
diffy(self, eventTime)
Determine the difference (a Period) between myself and the time of some event.
source code
tuple
diffyearsmonths(self, eventTime)
Determine the difference (a Period) between myself and the time of some event.
source code
tuple
diffym(self, eventTime)
Determine the difference (a Period) between myself and the time of some event.
source code
tuple
diffmonths(self, eventTime)
Determine the difference (a Period) between myself and the time of some event.
source code
tuple
diffm(self, eventTime)
Determine the difference (a Period) between myself and the time of some event.
source code
Time
exitWeekend(self, direction=None)
return a new Time object which has been moved so it does not fall on a Saturday or Sunday.
source code
Time
flex(self, baseTime)
A method for adding days to a date, based on a base date.
source code
Time
fromFile(self, filename)
Returns: a new Time object with the datetime of the last modification date of the file with <filename>.
source code
Time
fromTimestamp(self, timestamp)
Returns: a new Time object with the datetime from <timestamp>.
source code
string
get_civildate(self)
Return a string containing the civildate.
source code
tuple
__getCiviltimeBase(self, **kwargs)
A utility method for other civiltime methods.
source code
string
get_civiltime(self, **kwargs)
Return a string containing the civil time.
source code
string
get_civiltime2(self)
Return a string containing the civil time (including seconds.)
source code
string
get_d(self)
Return a string containing the civildate.
source code
string
get_dostime(self)
Return the datetime in the format used by Microsoft's MS-DOS.
source code
int
get_day(self)
Return the day part of the datetime.
source code
string
get_dt(self)
Return a string containing the civildate and the time, e.g.
source code
string
get_dt2(self)
Return a string containing the civildate and the time (including seconds) e.g.
source code
int
get_hour(self)
Return the hour portion of the Time, as an int.
source code
string
get_isodate(self, sep='-')
Return a string containing an ISO date in format yyyy-mm-dd, e.g.
source code
string
get_isotime(self, sep=':')
Return a string containing ISO time in format hh:mm:ss, e.g.
source code
string
get_isodatetime(self, sep='T', datesep='-', timesep=':', seps=None)
Return a string containing an ISO datetime in format yyyy-mm-ddThh:mm:ss.
source code
string
get_isofilename(self, sep='-')
Return a string containing the ISO datetime in a format suitable for making a filename.
source code
int
get_isoweekday(self)
Return the ISO weekday number as an int, where Monday=1 ..
source code
int
get_isoweeknumber(self)
Return the ISO week number, as an int.
source code
int
get_minute(self)
Return the minute portion of a Time, as an int.
source code
int
get_month(self)
Return the month portion of a Time, as an int.
source code
string
get_monthname(self)
Return a string containing the natural language name of the month.
source code
int
get_second(self)
Return the second portion of a Time, as an int.
source code
string
get_td(self)
Return a string containing the time and the civil date.
source code
string
get_t2d(self)
Return a string containing the time and the civil date (including seconds).
source code
tuple
get_tuple(self)
Return a tuple containing the parts of the datetime.
source code
string
get_twd(self)
Return a string containing the time, the weekday name, and the civildate.
source code
string
get_t2wd(self)
Return a string containing the time (including seconds), the weekday name, and the civildate.
source code
string
get_unixdate(self, sep='-')
Return a string containing a Unix date, e.g.
source code
string
get_weekdayname(self, weekday=None)
Returns the natural language name of the day of the week.
source code
string
get_wd(self)
Returns a string containing the weekday name and the civildate.
source code
string
get_wdt(self)
Returns a string containing the weekday name, the civildate, and the time.
source code
string
get_wdt2(self)
Returns a string containing the weekday name, the civildate, and the time (including seconds).
source code
int
get_year(self)
Return the year as an int, e.g.
source code
string
get_yearstring(self)
Return the year as a string, e.g.
source code
Time
goto(self, **kwargs)
Returns a clone of self but with some component(s) (year, month, day, hour, minute, second) reset to a new value.
source code
Time
gotoMonth(self, argMonth, direction='NEXT', **kwargs)
Returns a new Time object in which the month has been moved to the specified argMonth.
source code
Time
gotoMonthBegin(self)
Return a new Time object in which the time has been moved to the beginning of the month.
source code
Time
gotoMonthEnd(self)
Return a new Time object in which the time has been moved to the end of the month.
source code
Time
gotoYearBegin(self)
Return a new Time object in which the time has been moved to the beginning of year.
source code
Time
gotoYearEnd(self)
Return a new Time object in which the time has been moved to the end of the year.
source code
Time
__gotoNearestMonth(self, month, useTodayFlag)
Return a new Time object in which the month has been moved (forward or backward) to the closest month with month number <month>.
source code
Time
__gotoNearestWeekday(self, weekday, useTodayFlag)
Return a new Time object in which the weekday has been moved (forward or backward) to the closest weekday with weekday number <weekday>.
source code
Time
gotoWeekday(self, argWeekday, direction='NEXT', **kwargs)
Return a new Time object in which the date has been moved to the specified argWeekday.
source code
boolean
isLeapYear(self)
Return a boolean indicating whether the year is or is not a leap year.
source code
Time
subtract(self, **kwargs)
Subtract some amounts of time from the current time.
source code
Time
minus(self, **kwargs)
Subtract some amounts of time from the current time.
source code
Properties [hide private]
string civildate
Return a string containing the civildate.
tuple civiltimebase
A utility method for other civiltime methods.
string civiltime
Return a string containing the civil time.
string t
Return a string containing the civil time.
string civiltime2
Return a string containing the civil time (including seconds.)
string t2
Return a string containing the civil time (including seconds.)
string d
Return a string containing the civildate.
string dostime
Return the datetime in the format used by Microsoft's MS-DOS.
int day
Return the day part of the datetime.
string dt
Return a string containing the civildate and the time, e.g.
string dt2
Return a string containing the civildate and the time (including seconds) e.g.
int hour
Return the hour portion of the Time, as an int.
string isodate
Return a string containing an ISO date in format yyyy-mm-dd, e.g.
string isotime
Return a string containing ISO time in format hh:mm:ss, e.g.
string isodatetime
Return a string containing an ISO datetime in format yyyy-mm-ddThh:mm:ss.
string isofilename
Return a string containing the ISO datetime in a format suitable for making a filename.
int isoweekday
Return the ISO weekday number as an int, where Monday=1 ..
int weekday
Return the ISO weekday number as an int, where Monday=1 ..
int weeknumber
Return the ISO week number, as an int.
int isoweeknumber
Return the ISO week number, as an int.
int minute
Return the minute portion of a Time, as an int.
int month
Return the month portion of a Time, as an int.
string monthname
Return a string containing the natural language name of the month.
string m
Return a string containing the natural language name of the month.
int second
Return the second portion of a Time, as an int.
string td
Return a string containing the time and the civil date.
string t2d
Return a string containing the time and the civil date (including seconds).
string twd
Return a string containing the time, the weekday name, and the civildate.
string t2wd
Return a string containing the time (including seconds), the weekday name, and the civildate.
string unixdate
Return a string containing a Unix date, e.g.
string weekdayname
Returns the natural language name of the day of the week.
string w
Returns the natural language name of the day of the week.
string wd
Returns a string containing the weekday name and the civildate.
string wdt
Returns a string containing the weekday name, the civildate, and the time.
string wdt2
Returns a string containing the weekday name, the civildate, and the time (including seconds).
int year
Return the year as an int, e.g.
string y
Return the year as a string, e.g.
Method Details [hide private]

__init__(self, arg1=None, month=1, day=1, hour=0, minute=0, second=0)
(Constructor)

source code 

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]]]]]
Returns: Time

__str__(self)
(Informal representation operator)

source code 

Return a string representation of self as an isodate + space + isotime

Returns: string
self as an isodate + space + isotime, e.g.:
       "2007-03-02 09:30:45"

__sub__(self, arg)
(Subtraction operator)

source code 

Subtract a Period or a Time from this Time object.

Parameters:
  • arg (Period or Time) - a Period object or a Time object
Returns: Time or Period
a Time (if <arg> is a Period) or a Period (if <arg> is a Time)
Notes:
  • :
           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.
    
  • 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)

source code 

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.

Returns: Time
a new Time object with the specified amounts of time added to it.
Notes:
  • To subtract amounts, you can add negative amounts (see the example) or use the 'subtract' method.
  • Example: To get the time that is a month and a week from the current time:
           t = Time().add(months=1,weeks=1)
    
  • Example: To get the time that is a month and a week from the current time:
           t = Time().add(months=1).plus(weeks=1)
    
  • Example: To subtract 6 weeks from the current time:
           t = Time().add(weeks=-6)    # note the minus sign: -6.
    

plus(self, **kwargs)

source code 

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.

Returns: Time
a new Time object with the specified amounts of time added to it.
Notes:
  • To subtract amounts, you can add negative amounts (see the example) or use the 'subtract' method.
  • Example: To get the time that is a month and a week from the current time:
           t = Time().add(months=1,weeks=1)
    
  • Example: To get the time that is a month and a week from the current time:
           t = Time().add(months=1).plus(weeks=1)
    
  • Example: To subtract 6 weeks from the current time:
           t = Time().add(weeks=-6)    # note the minus sign: -6.
    

addmonths(self, months)

source code 

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'
Returns: Time
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)

source code 

The most recent anniversary of myself.

Parameters:
  • eventTime (Time) - the time of the event whose anniversary we want
Returns: Time
The most recent anniversary of some event, previous to today.

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)

source code 

Return a clone of myself.

Returns: Time
a clone of myself

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)

source code 

Determine the difference (a Period) between two Times.

Returns: Period

Note: Unlike the __sub__ method, the diff (i.e. difference) method always returns a Period object with a positive value.

diffyears(self, eventTime)

source code 

Determine the difference (a Period) between myself and the time of some event.

Returns: tuple

Note: returns the difference between two Time objects as a tuple of (years, Period)

diffy(self, eventTime)

source code 

Determine the difference (a Period) between myself and the time of some event.

Returns: tuple

Note: returns the difference between two Time objects as a tuple of (years, Period)

diffyearsmonths(self, eventTime)

source code 

Determine the difference (a Period) between myself and the time of some event.

Returns: tuple

Note: returns the difference between two Time objects as a tuple of (years,months, Period)

diffym(self, eventTime)

source code 

Determine the difference (a Period) between myself and the time of some event.

Returns: tuple

Note: returns the difference between two Time objects as a tuple of (years,months, Period)

exitWeekend(self, direction=None)

source code 

return a new Time object which has been moved so it does not fall on a Saturday or Sunday.

Parameters:
  • direction (string) - 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
    
Returns: Time

flex(self, baseTime)

source code 

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'
Returns: Time
a new Time object that has been "flexed" based on the baseTime

fromFile(self, filename)

source code 
Parameters:
  • filename (string) - a filename
Returns: Time
a new Time object with the datetime of the last modification date of the file with <filename>.

fromTimestamp(self, timestamp)

source code 
Parameters:
  • timestamp (timestamp) - a timestamp
Returns: Time
a new Time object with the datetime from <timestamp>.

See Also: the datetime module for documentation

get_civildate(self)

source code 

Return a string containing the civildate.

Returns: string
the civildate, e.g.:
       "April 30, 2007"

__getCiviltimeBase(self, **kwargs)

source code 

A utility method for other civiltime methods.

Returns: tuple
a tuple containing the components of civiltime:
       (hour, minute, second, am_pm_flag)

get_civiltime(self, **kwargs)

source code 

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.

Parameters:
  • showseconds (boolean) - defaults to False.
  • showHundredthsOfSeconds (boolean) - defaults to False.
Returns: string
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

get_civiltime2(self)

source code 

Return a string containing the civil time (including seconds.)

Returns: string
a string containing the civil time including seconds, e.g.:
       "6:30:45pm"

get_d(self)

source code 

Return a string containing the civildate.

Returns: string
the civildate, e.g.:
       "April 30, 2007"

get_dostime(self)

source code 

Return the datetime in the format used by Microsoft's MS-DOS.

Returns: string
the datetime in the format used by Microsoft's MS-DOS

get_day(self)

source code 

Return the day part of the datetime.

Returns: int
day

get_dt(self)

source code 

Return a string containing the civildate and the time, e.g. "April 30, 2007 6:30pm".

Returns: string
the civildate and the time, e.g.:
       "April 30, 2007 6:30pm"

get_dt2(self)

source code 

Return a string containing the civildate and the time (including seconds) e.g. "April 30, 2007 6:30:45pm".

Returns: string
the civildate and the time, e.g.:
       "April 30, 2007 6:30:45pm"

get_hour(self)

source code 

Return the hour portion of the Time, as an int.

Returns: int
hour

get_isodate(self, sep='-')

source code 

Return a string containing an ISO date in format yyyy-mm-dd, e.g. "2007-10-09"

Parameters:
  • sep (string) - separator string to use. Defaults to the ISO standard: a dash.
Returns: string
an ISO date in format yyyy-mm-dd, e.g.:
       "2007-10-09" # Oct 9, 2007

get_isotime(self, sep=':')

source code 

Return a string containing ISO time in format hh:mm:ss, e.g. "11:15:00".

Parameters:
  • sep (string) - separator string to use. Defaults to the ISO standard: a colon.
Returns: string
an ISO time in format hh:mm:ss, e.g.:
       "11:15:00"  # 11:15 in the morning

get_isodatetime(self, sep='T', datesep='-', timesep=':', seps=None)

source code 

Return a string containing an ISO datetime in format yyyy-mm-ddThh:mm:ss.

Parameters:
  • sep (string) - separator string to use between date and time. Default is the ISO standard, a capital letter "T".
  • datesep - separator string to use within date. Default is the ISO standard, a dash "-".
  • timesep - separator string to use within time. Default is the ISO standard, a colon ":".
  • 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.
Returns: string
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

get_isofilename(self, sep='-')

source code 

Return a string containing the ISO datetime in a format suitable for making a filename.

Parameters:
  • sep (string) - separator string to use between datetime parts. Default = "-"
Returns: string
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
Notes:
  • All parts of the datetime will be separated by dashes.
  • A collection of these strings, sorted using a standard string sort, will sort in temporal order.

get_isoweekday(self)

source code 

Return the ISO weekday number as an int, where Monday=1 .. Sunday=7

Returns: int
the ISO weekday number, e.g.:
       1 # first day of the week, Monday

get_isoweeknumber(self)

source code 

Return the ISO week number, as an int.

Returns: int
the ISO week number, e.g.:
       1 # first week of the year

get_minute(self)

source code 

Return the minute portion of a Time, as an int.

Returns: int
minute, e.g.:
       15 # 15 minutes past the beginning of the hour

get_month(self)

source code 

Return the month portion of a Time, as an int.

Returns: int
month, e.g.:
       12  # for the 12th month, December

get_monthname(self)

source code 

Return a string containing the natural language name of the month.

Returns: string
monthname, e.g.:
       "December"

get_second(self)

source code 

Return the second portion of a Time, as an int.

Returns: int
second

get_td(self)

source code 

Return a string containing the time and the civil date.

Returns: string
the time and the civildate, e.g.:
       "6:30pm April 30, 2007"

get_t2d(self)

source code 

Return a string containing the time and the civil date (including seconds).

Returns: string
the time and the civildate, e.g.:
       "6:30:45pm April 30, 2007"

get_tuple(self)

source code 

Return a tuple containing the parts of the datetime.

Returns: tuple
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)

source code 

Return a string containing the time, the weekday name, and the civildate.

Returns: string
the time, the weekday name, and the civildate, e.g.:
       "6:30pm Monday April 30, 2007"

get_t2wd(self)

source code 

Return a string containing the time (including seconds), the weekday name, and the civildate.

Returns: string
the time (including seconds), the weekday name, and the civildate, e.g.:
       "6:30:45pm Monday April 30, 2007"

get_unixdate(self, sep='-')

source code 

Return a string containing a Unix date, e.g. "07-DEC-2006".

Parameters:
  • sep (string) - separator string to use. Defaults to a dash.
Returns: string
a string containing a Unix date, e.g.:
       "07-DEC-2006"

get_weekdayname(self, weekday=None)

source code 

Returns the natural language name of the day of the week.

Parameters:
  • weekday (int) - the ISO weekday number. If not specified, defaults to the weekday of self (this Time object).
Returns: string
the natural language name of the day of the week, e.g.:
       "Monday"

get_wd(self)

source code 

Returns a string containing the weekday name and the civildate.

Returns: string
the weekday name and the civildate. e.g.:
       "Monday April 30, 2007"

get_wdt(self)

source code 

Returns a string containing the weekday name, the civildate, and the time.

Returns: string
the weekday name, the civildate, and the time, e.g.:
       "Monday April 30, 2007 6:30pm"

get_wdt2(self)

source code 

Returns a string containing the weekday name, the civildate, and the time (including seconds).

Returns: string
the weekday name, the civildate, and the time, e.g.:
       "Monday April 30, 2007 6:30:45pm"

get_year(self)

source code 

Return the year as an int, e.g. 2007

Returns: int
year, e.g.:
       2007

get_yearstring(self)

source code 

Return the year as a string, e.g. "2007"

Returns: string
year, e.g.:
       "2007"

goto(self, **kwargs)

source code 

Returns a clone of self but with some component(s) (year, month, day, hour, minute, second) reset to a new value.

Returns: Time
a new Time object in which the time has been moved according to the keyword args
Notes:
  • 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).
  • This method attempts to recover from such failures by decrementing the "day" value to 28 before failing.
  • Example: To obtain a Time object whose date is May 15, 2003:
           t  = Time(2007,5,15)
           t2 = t.goto(year=2003)
    
  • 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)

source code 

Returns a new Time object in which the month has been moved to the specified argMonth.

Parameters:
  • argMonth (int) - The argMonth number should be specified by means of one of pyfdate's month number constants (JANUARY, FEBRUARY, etc.)
  • direction (string) - 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
    
  • useToday (boolean) - 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.
Returns: Time
a new Time object in which the month has been moved to the specified month number.
Notes:
  • Example: If this month is April, to move the date to the following November:
           t = Time().gotoMonth(NOVEMBER)
           or
           t = Time().gotoMonth(NOVEMBER,NEXT)
    
  • Example: If this month is April, to move the date to the previous November:
           t = Time().gotoMonth(NOVEMBER, PREVIOUS)
    
  • Example: If this month is April, to move the date to the nearest November:
           t = Time().gotoMonth(NOVEMBER, NEAREST)
    
  • 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)

source code 

Return a new Time object in which the time has been moved to the beginning of the month.

Returns: Time
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)

source code 

Return a new Time object in which the time has been moved to the end of the month.

Returns: Time
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()

gotoYearBegin(self)

source code 

Return a new Time object in which the time has been moved to the beginning of year.

Returns: Time
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)

source code 

Return a new Time object in which the time has been moved to the end of the year.

Returns: Time
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()

__gotoNearestMonth(self, month, useTodayFlag)

source code 

Return a new Time object in which the month has been moved (forward or backward) to the closest month with month number <month>.

Parameters:
  • month (int) - the monthnumber of the the desired month. The monthnumber should be specified by means of one of pyfdate's month number constants.
  • useTodayFlag (boolean) - specifies what to do it the current monthnumber is the same as the desired monthnumber:
           If useTodayFlag == True:
                   return the current month
           else:
                   return the month one year in the future.
    
Returns: Time
a new Time object in which the month has been moved (forward or backward) to the closest month with month number <month>.
Notes:
  • If the NEXT month with monthnumber <month> and the PREVIOUS month with monthnumber <month> are both exactly six months from the current month, then return the NEXT month with monthnumber <month>.
  • Example: t = Time().__gotoNearestMonth(JULY)

__gotoNearestWeekday(self, weekday, useTodayFlag)

source code 

Return a new Time object in which the weekday has been moved (forward or backward) to the closest weekday with weekday number <weekday>.

Returns: Time
Notes:
  • If the current weekday is already <weekday>:
           if useToday == False
                   return the NEXT <weekday>
           else
                   return a clone of the current Time object.
    
  • <weekday> should be specified by means of one of pyfdate's weekday number constants.
  • Example:
           t = Time().movetoNearestWeekday(THURSDAY)
    

gotoWeekday(self, argWeekday, direction='NEXT', **kwargs)

source code 

Return a new Time object in which the date has been moved to the specified argWeekday.

Parameters:
  • argWeekday (int) - The argWeekday number should be specified by means of one of pyfdate's weekday number constants (MONDAY, TUESDAY, etc.)
  • direction (string) - 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
    
  • useToday (boolean) - 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.
Returns: Time
a new Time object in which the time has been moved to the specified weekday.

isLeapYear(self)

source code 

Return a boolean indicating whether the year is or is not a leap year.

Returns: boolean
True if a <year> is a leap year; otherwise return False.

subtract(self, **kwargs)

source code 

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.

Returns: Time
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)

minus(self, **kwargs)

source code 

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.

Returns: Time
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)

Property Details [hide private]

civildate

Return a string containing the civildate.

Get Method:
get_civildate(self) - Return a string containing the civildate.
Type:
string

civiltimebase

A utility method for other civiltime methods.

Get Method:
__getCiviltimeBase(self, **kwargs) - A utility method for other civiltime methods.
Type:
tuple

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.

Get Method:
get_civiltime(self, **kwargs) - Return a string containing the civil time.
Type:
string

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

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.

Get Method:
get_civiltime(self, **kwargs) - Return a string containing the civil time.
Type:
string

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

civiltime2

Return a string containing the civil time (including seconds.)

Get Method:
get_civiltime2(self) - Return a string containing the civil time (including seconds.)
Type:
string

t2

Return a string containing the civil time (including seconds.)

Get Method:
get_civiltime2(self) - Return a string containing the civil time (including seconds.)
Type:
string

d

Return a string containing the civildate.

Get Method:
get_d(self) - Return a string containing the civildate.
Type:
string

dostime

Return the datetime in the format used by Microsoft's MS-DOS.

Get Method:
get_dostime(self) - Return the datetime in the format used by Microsoft's MS-DOS.
Type:
string

day

Return the day part of the datetime.

Get Method:
get_day(self) - Return the day part of the datetime.
Type:
int

dt

Return a string containing the civildate and the time, e.g. "April 30, 2007 6:30pm".

Get Method:
get_dt(self) - Return a string containing the civildate and the time, e.g.
Type:
string

dt2

Return a string containing the civildate and the time (including seconds) e.g. "April 30, 2007 6:30:45pm".

Get Method:
get_dt2(self) - Return a string containing the civildate and the time (including seconds) e.g.
Type:
string

hour

Return the hour portion of the Time, as an int.

Get Method:
get_hour(self) - Return the hour portion of the Time, as an int.
Type:
int

isodate

Return a string containing an ISO date in format yyyy-mm-dd, e.g. "2007-10-09"

Get Method:
get_isodate(self, sep='-') - Return a string containing an ISO date in format yyyy-mm-dd, e.g.
Type:
string

isotime

Return a string containing ISO time in format hh:mm:ss, e.g. "11:15:00".

Get Method:
get_isotime(self, sep=':') - Return a string containing ISO time in format hh:mm:ss, e.g.
Type:
string

isodatetime

Return a string containing an ISO datetime in format yyyy-mm-ddThh:mm:ss.

Get Method:
get_isodatetime(self, sep='T', datesep='-', timesep=':', seps=None) - Return a string containing an ISO datetime in format yyyy-mm-ddThh:mm:ss.
Type:
string

isofilename

Return a string containing the ISO datetime in a format suitable for making a filename.

Get Method:
get_isofilename(self, sep='-') - Return a string containing the ISO datetime in a format suitable for making a filename.
Type:
string
Notes:
  • All parts of the datetime will be separated by dashes.
  • A collection of these strings, sorted using a standard string sort, will sort in temporal order.

isoweekday

Return the ISO weekday number as an int, where Monday=1 .. Sunday=7

Get Method:
get_isoweekday(self) - Return the ISO weekday number as an int, where Monday=1 ..
Type:
int

weekday

Return the ISO weekday number as an int, where Monday=1 .. Sunday=7

Get Method:
get_isoweekday(self) - Return the ISO weekday number as an int, where Monday=1 ..
Type:
int

weeknumber

Return the ISO week number, as an int.

Get Method:
get_isoweeknumber(self) - Return the ISO week number, as an int.
Type:
int

isoweeknumber

Return the ISO week number, as an int.

Get Method:
get_isoweeknumber(self) - Return the ISO week number, as an int.
Type:
int

minute

Return the minute portion of a Time, as an int.

Get Method:
get_minute(self) - Return the minute portion of a Time, as an int.
Type:
int

month

Return the month portion of a Time, as an int.

Get Method:
get_month(self) - Return the month portion of a Time, as an int.
Type:
int

monthname

Return a string containing the natural language name of the month.

Get Method:
get_monthname(self) - Return a string containing the natural language name of the month.
Type:
string

m

Return a string containing the natural language name of the month.

Get Method:
get_monthname(self) - Return a string containing the natural language name of the month.
Type:
string

second

Return the second portion of a Time, as an int.

Get Method:
get_second(self) - Return the second portion of a Time, as an int.
Type:
int

td

Return a string containing the time and the civil date.

Get Method:
get_td(self) - Return a string containing the time and the civil date.
Type:
string

t2d

Return a string containing the time and the civil date (including seconds).

Get Method:
get_t2d(self) - Return a string containing the time and the civil date (including seconds).
Type:
string

twd

Return a string containing the time, the weekday name, and the civildate.

Get Method:
get_twd(self) - Return a string containing the time, the weekday name, and the civildate.
Type:
string

t2wd

Return a string containing the time (including seconds), the weekday name, and the civildate.

Get Method:
get_t2wd(self) - Return a string containing the time (including seconds), the weekday name, and the civildate.
Type:
string

unixdate

Return a string containing a Unix date, e.g. "07-DEC-2006".

Get Method:
get_unixdate(self, sep='-') - Return a string containing a Unix date, e.g.
Type:
string

weekdayname

Returns the natural language name of the day of the week.

Get Method:
get_weekdayname(self, weekday=None) - Returns the natural language name of the day of the week.
Type:
string

w

Returns the natural language name of the day of the week.

Get Method:
get_weekdayname(self, weekday=None) - Returns the natural language name of the day of the week.
Type:
string

wd

Returns a string containing the weekday name and the civildate.

Get Method:
get_wd(self) - Returns a string containing the weekday name and the civildate.
Type:
string

wdt

Returns a string containing the weekday name, the civildate, and the time.

Get Method:
get_wdt(self) - Returns a string containing the weekday name, the civildate, and the time.
Type:
string

wdt2

Returns a string containing the weekday name, the civildate, and the time (including seconds).

Get Method:
get_wdt2(self) - Returns a string containing the weekday name, the civildate, and the time (including seconds).
Type:
string

year

Return the year as an int, e.g. 2007

Get Method:
get_year(self) - Return the year as an int, e.g.
Type:
int

y

Return the year as a string, e.g. "2007"

Get Method:
get_yearstring(self) - Return the year as a string, e.g.
Type:
string