Dates, Times, Durations

Jason Rogers jacaetevha at fast-mail.org
Thu Jan 20 19:43:58 UTC 2005


On Thursday 20 January 2005 13:13, Jason Rogers 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.  Before reinventing the wheel,
> I wanted to check to see if anyone has already done this before and if
> there is (by some great chance) support for it a base 3.8 image.

This is what I came up with.  It seems to work with my tests, but it's not the 
most elegant.  Any suggestions?

asNumberOfWorkDays
    | hours |
    hours := 0.
    start
        to: end
        by: (Duration hours: 1.0)
        do: [:hour | 
            (hour asDuration hours > 8 and: [hour asDuration hours < 17])
                ifTrue: [hours := hours + 1.]
        ].
    ^ hours / 8

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