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
andduration
. These attributes will be used in TaskJuggler. Becauseeffort
is only meaningful if there are someresources
this attribute has been left special forTask
class. Thelength
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 theend
will be used and theduration
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. Theduration
attribute is the direct difference of the thestart
andend
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 thecomputed_start
and for end there is thecomputed_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
ordatetime.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.timedelta
instance. The default value is read from theConfig
class. 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_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
- start (