Denise R. wrote:
I’m building a collection of project management screens.
I want to be able to set up time estimates for each task in a project.
And then I want to be able to sum all the estimates, so that I can give
an expected completion date for the entire project.
Some tasks are short (1/2 hour), but some are days long.
How should I storing them in the db and how do I sum them?
Thanks!
Well, you could have a field for each time value:
tasktime_weeks
tasktime_days
tasktime_hours
tasktime_minutes
sum the fields up from the records in your collection…, say the totals
you get are:
w = tasktime_weeks = 4
d = tasktime_days = 3
h = tasktime_hours = 2
m = tasktime_minutes = 30
you can add those up:
duration = w.weeks + d.days + h.hours + m.minutes
which in this case is the same as:
duration = 4.weeks + 3.days + 2.hours + 30.minutes
now…
duration
produces “31 days and 9000 seconds” which I’ll admit is not very useful,
But…
duration / 1.day
produces 31
duration.to_f / 1.day
produces 31.10416
duration += duration + 12.hours
31 days and 52200 seconds
duration / 1.day
31
duration.to_f / 1.day
31.60416667
(duration.to_f / 1.day).round
32
(duration.to_f / 1.day).round(1)
31.6
you get the idea - play around with all this in the console and you’ll
have it in no time.