Dates, Times, Durations
Jason Rogers
jacaetevha at fast-mail.org
Mon Jan 24 14:37:02 UTC 2005
On Monday 24 January 2005 09:26, Brent Pinkney wrote:
> Sorry,
>
> Here it is again:
> > On Thu, 20 Jan 2005 13:13:45 -0500, Jason Rogers
> >
> > <jacaetevha at fast-mail.org> wrote:
> >> I would like to calculate the number of work hours between two dates
> >> with the basis of a workday being 9:00 to 17:00.
>
> hours := 0.
> (('1 January 2005' asDate) to: ('28 May 2005' asDate))
> datesDo: [ :d | (d dayOfWeek between: 2 and: 6) ifTrue: [ hours := hours
> + 8. ] ]
Thanks Brent for the concise answer. I did something like this for the first
round. All tests passed.
Now, I have to be able to deal with partial days, holidays, and weekends.
eg. December 24, 2004 was a holiday for us so a Timespan of '23 December 2004
13:00' to '28 December 2004 13:00' would result in 16 hours (4 on the 23rd
and 28th, 8 on the 27th).
So, I think Michael Latta's suggestion to use a Schedule is more feasible. I
just have to figure out how to use the Schedule API effectively.
--
Jason Rogers
"I am crucified with Christ: nevertheless I live; yet not I,
but Christ liveth in me: and the life which I now live in
the flesh I live by the faith of the Son of God, who loved
me, and gave himself for me."
Galatians 2:20
More information about the Squeak-dev
mailing list
|