# Adding up blocks of time - project with tasks

**URL:** <https://www.ruby-forum.com/t/adding-up-blocks-of-time-project-with-tasks/139306>\
**Category:** Rails\
**Created:** [June 2, 2008, 8:31pm UTC](https://www.ruby-forum.com/t/adding-up-blocks-of-time-project-with-tasks/139306 "2008-06-02T20:31:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gorgeoussoul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6f9a4e/32.png) [@gorgeoussoul](https://www.ruby-forum.com/u/gorgeoussoul)\
**Post date:** [June 2, 2008, 8:31pm UTC](https://www.ruby-forum.com/t/adding-up-blocks-of-time-project-with-tasks/139306/1 "2008-06-02T20:31:40Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![gorgeoussoul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6f9a4e/32.png) [@gorgeoussoul](https://www.ruby-forum.com/u/gorgeoussoul)\
**Post date:** [June 3, 2008, 3:15am UTC](https://www.ruby-forum.com/t/adding-up-blocks-of-time-project-with-tasks/139306/2 "2008-06-03T03:15:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gorgeoussoul](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6f9a4e/32.png) [@gorgeoussoul](https://www.ruby-forum.com/u/gorgeoussoul)\
**Post date:** [June 4, 2008, 12:17pm UTC](https://www.ruby-forum.com/t/adding-up-blocks-of-time-project-with-tasks/139306/3 "2008-06-04T12:17:03Z")

</div>

-----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-----
