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

Class Period

source code

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.

Instance Methods [hide private]
Period
__init__(self, arg1=0, hours=0, minutes=0, seconds=0)
Thhe constructor of a Period object.
source code
Period
__abs__(self)
Returns a clone of myself, with my absolute value.
source code
Period
__add__(self, arg)
Add one period to another.
source code
boolean
__eq__(self, arg)
Compare two Period objects for equality.
source code
boolean
__ge__(self, arg)
Compares two Period objects to determine if one is greater than, or equal to, the other.
source code
boolean
__gt__(self, arg)
Compares two Period objects to determine if one is greater than the other.
source code
boolean
__le__(self, arg)
Compares two Period objects to determine if one is less than, or equal to, the other.
source code
boolean
__lt__(self, arg)
Compares two Period objects to determine if one is less than the other.
source code
boolean
__neq__(self, arg)
Compare two Period objects for inequality.
source code
string
__str__(self)
Returns a string representation of a Period.
source code
Period
__sub__(self, arg)
Subtract one period from another.
source code
Period
subtract(self, **kwargs)
A general method for subtracting time from a Period object.
source code
Period
minus(self, **kwargs)
A general method for subtracting time from a Period object.
source code
Period
add(self, **kwargs)
A general method for adding time to a Period object.
source code
Period
plus(self, **kwargs)
A general method for adding time to a Period object.
source code
Period
clone(self)
Return a clone of myself.
source code
int
get_days(self)
Return the days portion of the period, as an int.
source code
int
get_hours(self)
Return the hours portion of the Period, as an int.
source code
int
get_minutes(self)
Return the minutes portion of the Period, as an int.
source code
int
get_seconds(self)
Return the seconds portion of the Period, as an int.
source code
string
get_p(self, **kwargs)
Return myself in a nicely-formatted string.
source code
string
get_short(self)
Return myself as a nicely formatted string: suppress components whose value is zero.
source code
string
get_shortest(self)
Return myself as a nicely formatted string: suppress components whose value is zero.
source code
timedelta
get_timedelta(self)
Returns a Period expressed as a datetime.timedelta object
source code
tuple
get_tuple(self)
Returns myself formatted as a 4-tuple of ints (days, hours, minutes, seconds).
source code
int
get_asDays(self)
Returns this Period, expressed in units of days.
source code
int
get_asHours(self)
Returns this Period, expressed in units of hours.
source code
int
get_asMinutes(self)
Returns this Period, expressed in units of minutes.
source code
int
get_asSeconds(self)
Returns this Period, expressed in units of seconds.
source code
Properties [hide private]
int days
Return the days portion of the period, as an int.
int hours
Return the hours portion of the Period, as an int.
int minutes
Return the minutes portion of the Period, as an int.
int seconds
Return the seconds portion of the Period, as an int.
string p
Return myself in a nicely-formatted string.
string short
Return myself as a nicely formatted string: suppress components whose value is zero.
string shortest
Return myself as a nicely formatted string: suppress components whose value is zero.
timedelta timedelta
Returns a Period expressed as a datetime.timedelta object
tuple tuple
Returns myself formatted as a 4-tuple of ints (days, hours, minutes, seconds).
int asDays
Returns this Period, expressed in units of days.
int asHours
Returns this Period, expressed in units of hours.
int asMinutes
Returns this Period, expressed in units of minutes.
int asSeconds
Returns this Period, expressed in units of seconds.
Method Details [hide private]

__init__(self, arg1=0, hours=0, minutes=0, seconds=0)
(Constructor)

source code 

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
Returns: Period

__abs__(self)

source code 

Returns a clone of myself, with my absolute value.

Returns: Period
a clone of myself, with my absolute value

__add__(self, arg)
(Addition operator)

source code 

Add one period to another.

Returns: Period
a new Period object

__str__(self)
(Informal representation operator)

source code 

Returns a string representation of a Period.

Returns: string
a string representation of a Period. e.g.:
       "4 days 3 hours 20 minutes 45 seconds"

__sub__(self, arg)
(Subtraction operator)

source code 

Subtract one period from another.

Returns: Period
a new Period object

subtract(self, **kwargs)

source code 

A general method for subtracting time from a Period object.

Returns: Period

Note: Example: :

       p1 = Period()
       p2 = p1.plus(weeks=2,days=3,hours=4,minutes=99, seconds=1)

minus(self, **kwargs)

source code 

A general method for subtracting time from a Period object.

Returns: Period

Note: Example: :

       p1 = Period()
       p2 = p1.plus(weeks=2,days=3,hours=4,minutes=99, seconds=1)

add(self, **kwargs)

source code 

A general method for adding time to a Period object. To subtract time, add time in negative increments or use the subtract() method.

Returns: Period

Note: Example:

       p1 = Period()
       p2 = p1.plus(weeks=2,days=3,hours=4,minutes=99, seconds=1)

plus(self, **kwargs)

source code 

A general method for adding time to a Period object. To subtract time, add time in negative increments or use the subtract() method.

Returns: Period

Note: Example:

       p1 = Period()
       p2 = p1.plus(weeks=2,days=3,hours=4,minutes=99, seconds=1)

clone(self)

source code 

Return a clone of myself.

Returns: Period
a clone of myself

get_days(self)

source code 

Return the days portion of the period, as an int.

Returns: int
days, e.g.:
       3

get_hours(self)

source code 

Return the hours portion of the Period, as an int.

Returns: int
hours, e.g.:
       15

get_minutes(self)

source code 

Return the minutes portion of the Period, as an int.

Returns: int
minutes, e.g.:
       45

get_seconds(self)

source code 

Return the seconds portion of the Period, as an int.

Returns: int
seconds, e.g.:
       45

get_p(self, **kwargs)

source code 

Return myself in a nicely-formatted string.

Returns: string
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_short(self)

source code 

Return myself as a nicely formatted string: suppress components whose value is zero.

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

source code 

Return myself as a nicely formatted string: suppress components whose value is zero.

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

source code 

Returns a Period expressed as a datetime.timedelta object

Returns: timedelta
a Period expressed as a datetime.timedelta object

get_tuple(self)

source code 

Returns myself formatted as a 4-tuple of ints (days, hours, minutes, seconds).

Returns: tuple
myself formatted as a 4-tuple of ints (days, hours, minutes, seconds)

get_asDays(self)

source code 

Returns this Period, expressed in units of days.

Returns: int
myself, expressed in units of days

get_asHours(self)

source code 

Returns this Period, expressed in units of hours.

Returns: int
myself, expressed in units of hours

get_asMinutes(self)

source code 

Returns this Period, expressed in units of minutes.

Returns: int
myself, expressed in units of minutes

get_asSeconds(self)

source code 

Returns this Period, expressed in units of seconds.

Returns: int
myself, expressed in units of seconds

Property Details [hide private]

days

Return the days portion of the period, as an int.

Get Method:
get_days(self) - Return the days portion of the period, as an int.
Type:
int

hours

Return the hours portion of the Period, as an int.

Get Method:
get_hours(self) - Return the hours portion of the Period, as an int.
Type:
int

minutes

Return the minutes portion of the Period, as an int.

Get Method:
get_minutes(self) - Return the minutes portion of the Period, as an int.
Type:
int

seconds

Return the seconds portion of the Period, as an int.

Get Method:
get_seconds(self) - Return the seconds portion of the Period, as an int.
Type:
int

p

Return myself in a nicely-formatted string.

Get Method:
get_p(self, **kwargs) - Return myself in a nicely-formatted string.
Type:
string

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

short

Return myself as a nicely formatted string: suppress components whose value is zero.

Get Method:
get_short(self) - Return myself as a nicely formatted string: suppress components whose value is zero.
Type:
string

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.

Get Method:
get_shortest(self) - Return myself as a nicely formatted string: suppress components whose value is zero.
Type:
string

Note: If my duration is 0, this method will return an empty string.

timedelta

Returns a Period expressed as a datetime.timedelta object

Get Method:
get_timedelta(self) - Returns a Period expressed as a datetime.timedelta object
Type:
timedelta

tuple

Returns myself formatted as a 4-tuple of ints (days, hours, minutes, seconds).

Get Method:
get_tuple(self) - Returns myself formatted as a 4-tuple of ints (days, hours, minutes, seconds).
Type:
tuple

asDays

Returns this Period, expressed in units of days.

Get Method:
get_asDays(self) - Returns this Period, expressed in units of days.
Type:
int

asHours

Returns this Period, expressed in units of hours.

Get Method:
get_asHours(self) - Returns this Period, expressed in units of hours.
Type:
int

asMinutes

Returns this Period, expressed in units of minutes.

Get Method:
get_asMinutes(self) - Returns this Period, expressed in units of minutes.
Type:
int

asSeconds

Returns this Period, expressed in units of seconds.

Get Method:
get_asSeconds(self) - Returns this Period, expressed in units of seconds.
Type:
int