stalker.models.mixins.DateRangeMixin¶
-
class
stalker.models.mixins.DateRangeMixin(start=None, end=None, duration=None, **kwargs)[source]¶ Bases:
objectAdds date range info to the mixed in class.
Adds date range information like
start,endandduration. These attributes will be used in TaskJuggler. Becauseeffortis only meaningful if there are someresourcesthis attribute has been left special forTaskclass. Thelengthhas 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
startand theendwill be used and thedurationwill 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,endwill be stored. Thedurationattribute is the direct difference of the thestartandendattributes, 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
computedcompanion. Which are the return values from TaskJuggler. so for start there is thecomputed_startand for end there is thecomputed_endattributes. 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.datetimeordatetime.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 adatetime.timedeltainstance. The default value is read from theConfigclass. See the table above for the initialization rules.
Methods
__init__([start, end, duration])round_time(dt)Round the given datetime object to the defaults.timing_resolution. Attributes
computed_durationreturns the computed_duration as the difference of computed_start computed_endcomputed_startcomputed_total_secondsreturns the duration as seconds durationendstarttotal_secondsreturns 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_resolutionas 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
- start (