stalker.models.mixins.DateRangeMixin

Inheritance diagram of stalker.models.mixins.DateRangeMixin
class stalker.models.mixins.DateRangeMixin(start=None, end=None, duration=None, **kwargs)[source]

Bases: object

Adds date range info to the mixed in class.

Adds date range information like start, end and duration. These attributes will be used in TaskJuggler. Because effort is only meaningful if there are some resources this attribute has been left special for Task class. The length has not been implemented because of its rare use.

The preceding order for the attributes is as follows:

start > end > duration

So if all of the parameters are given only the start and the end will be used and the duration will be calculated accordingly. In any other conditions the missing parameter will be calculated from the following table:

start end duration DEFAULTS
     

start = datetime.datetime.now(pytz.utc)

duration = datetime.timedelta(days=10)

end = start + duration

X    

duration = datetime.timedelta(days=10)

end = start + duration

X X   duration = end - start
X   X end = start + duration
X X X duration = end - start
  X X start = end - duration
  X  

duration = datetime.timedelta(days=10)

start = end - duration

    X

start = datetime.datetime.now(pytz.utc)

end = start + duration

Only the start, end will be stored. The duration attribute is the direct difference of the the start and end attributes, so there is no need to store it. But if will be used in calculation of the start and end values.

The start and end attributes have a computed companion. Which are the return values from TaskJuggler. so for start there is the computed_start and for end there is the computed_end attributes. These values are going to be used in Gantt Charts.

The date attributes can be managed with timezones. Follow the Python idioms shown in the documentation of datetime

Parameters:
  • start (datetime.datetime) – the start date of the entity, should be a datetime.datetime instance, the start is the pin point for the date calculation. In any condition if the start is available then the value will be preserved. If start passes the end the end is also changed to a date to keep the timedelta between dates. The default value is datetime.datetime.now(pytz.utc)
  • end (datetime.datetime or datetime.timedelta) – the end of the entity, should be a datetime.datetime instance, when the start is changed to a date passing the end, then the end is also changed to a later date so the timedelta between the dates is kept.
  • duration (datetime.timedelta) – The duration of the entity. It is a datetime.timedelta instance. The default value is read from the Config class. See the table above for the initialization rules.
__init__(start=None, end=None, duration=None, **kwargs)[source]

Methods

__init__([start, end, duration])
round_time(dt) Round the given datetime object to the defaults.timing_resolution.

Attributes

computed_duration returns the computed_duration as the difference of computed_start
computed_end
computed_start
computed_total_seconds returns the duration as seconds
duration
end
start
total_seconds returns the duration as seconds
computed_duration

returns the computed_duration as the difference of computed_start and computed_end if there are computed_start and computed_end otherwise returns None

classmethod round_time(dt)[source]

Round the given datetime object to the defaults.timing_resolution.

Uses stalker.defaults.timing_resolution as the closest number of seconds to round to.

Parameters:dt (datetime.datetime) – datetime.datetime object, defaults to now.

Based on Thierry Husson’s answer in Stackoverflow

Stackoverflow : http://stackoverflow.com/a/10854034/1431079

total_seconds

returns the duration as seconds

computed_total_seconds

returns the duration as seconds