Adding up blocks of time - project with tasks

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!

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.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Monday 02 June 2008 20:31:40 Denise R. wrote:

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?

I’d store them as integer minutes, and introduce helpers and
before_filters that deal with presentation and user input conversions.

Ciao,
Sheldon.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIRmtcpGJX8XSgas0RAhUvAJ9EMk4xnRvWVmeptVYG28v41wAyXQCfQ3Sn
frij4GSGeQHdbN5MRiKd0VY=
=gbLx
-----END PGP SIGNATURE-----