brianmaissy/WSMA — Issue #43: time utility methods
Author: brianmaissy
Created: 2011-12-27 19:00:16+00:00
State: open

So I'm thinking that both the Shift and Assignment models would have methods "start_date" and "end_date", and each would return a DateTime object.

For Shift, "start_date" would return the date and time the shift starts in the current week. This will only be called if the shift is unassigned.
"end_date" would also return a DateTime for the current week, but would have the time the shift will end (can be calculated based on number of hours a chore has).

The way I've dealt with DateTimes in the view is like this:
<% start_time = TimeProvider.now %>
<% start_time = start_time.change(:hour => shift.time.hour) %>
<% start_time = start_time.change(:minute => shift.time.min) %>
<% start_time = start_time.change(:day => base-1+shift.day_of_week) %> // base is the mday for the sunday at the beginning of the week.
<% end_time = start_time.change(:hour => shift.time.hour + chore.hours) %>
<% end_time = end_time.change(:minute => shift.time.min) %>

I've found the "change" method to be useful in manipulating DateTimes. It may or may not be useful, but I'd just like to point it out.

Assignment "start_date" and "end_date", would be similar to shift.start_date/end_date, but except of dealing with the current week, the Assignments week variable will be used
to get the exact date the assignment occurs on.