Path: utzoo!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uunet!mcsun!unido!laura!huba From: huba@ls5.informatik.uni-dortmund.de (Hubert Baumeister) Newsgroups: comp.lang.smalltalk Subject: Re: PP ST R4 - Date dayOfWeek: neverOnASunday!! Keywords: bug Message-ID: <3097@laura.UUCP> Date: 18 Mar 91 13:06:29 GMT References: <4992@goanna.cs.rmit.oz.au> Sender: news@laura.UUCP Reply-To: huba@ls5.informatik.uni-dortmund.de (Hubert Baumeister) Organization: University of Dortmund, Germany Lines: 35 In article <4992@goanna.cs.rmit.oz.au>, pnm@goanna.cs.rmit.oz.au (Paul Menon) writes: |> hi, |> A nasty with PPOWST R4 - Beware of converting #Sunday into a day of |> week index. It gives you 0, not 7. Maybe because Sunday isn't a |> weekday? :-) And we *should* be working on Saturday, right? |> |> Here's Date's method for dayOfWeek (class protocol: general inquiries).. |> |> --------------------------- |> dayOfWeek: dayName |> "Answer the index in a week, 1 - 7, of the day named dayName. |> Provide an error notification if no such day exists." |> |> 1 to: 7 do: [:index | (WeekDayNames at: index) |> = dayName ifTrue: [^index \\ 7]]. |> self error: dayName asString , ' is not a day of the week' |> -------------------------- |> |> The "^index \\ 7" above is the trap. 7 mod 7 is 0, not 7. |> |> Should I change this method? I suppose you should do so and return index instead of index \\ 7. The only place where dayOfWeek: is used is in Date>previous: previous: dayName "Answer the previous date whose weekday name is dayName." ^self subtractDays: 7 + self weekdayIndex - (Date dayOfWeek: dayName) \\ 7 This method works for both the wrong and the correct week index of #Sunday due to the use of \\ 7 in Date>previous. Hubert Baumeister (huba@ls5.informatik.uni-dortmund.de)