[comp.lang.smalltalk] PP ST R4 - Date dayOfWeek: neverOnASunday!!

pnm@goanna.cs.rmit.oz.au (Paul Menon) (03/18/91)

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?

Once again, apologies if this has already been thrashed...


    Paul Menon,
    Dept of Computer Science,
    Royal Melbourne Institute of Technology, 
    124 Latrobe Street,
    Melbourne 3001, 
    Victoria, Australia.

pnm@goanna.cs.rmit.oz.au
PH:	+61 3 660 3209

huba@ls5.informatik.uni-dortmund.de (Hubert Baumeister) (03/18/91)

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)

mario@cs.man.ac.uk (Mario Wolczko) (03/19/91)

In article <3097@laura.UUCP>, huba@ls5.informatik.uni-dortmund.de (Hubert Baumeister) writes:
> 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?

I remember this one well.  In fact, a goodie to fix it *for version
2.1* is in the Manchester Goodies Archive, c/o Trevor Hopkins, dated
*31 July 1986*.  

It was sent to PARC (this was before PPS was formed) *the same week*.
Sometimes I wonder why we bother...

Mario Wolczko

   ______      Dept. of Computer Science   Internet:      mario@cs.man.ac.uk
 /~      ~\    The University              uucp:      mcsun!ukc!man.cs!mario
(    __    )   Manchester M13 9PL          JANET:         mario@uk.ac.man.cs
 `-':  :`-'    U.K.                        Tel: +44-61-275 6146  (FAX: 6280)
____;  ;_____________the mushroom project___________________________________

khaw@parcplace.com (Mike Khaw) (03/22/91)

In <2313@m1.cs.man.ac.uk> mario@cs.man.ac.uk (Mario Wolczko) writes:

>It was sent to PARC (this was before PPS was formed) *the same week*.
>Sometimes I wonder why we bother...

PARC was before my time, so I can't comment on that, but I submitted
Paul Menon's posting as a bug report, and it has resulted in a fix that
will be incorporated into the next release.

So, please DO bother to report bugs.
--
Mike Khaw
ParcPlace Systems, Inc., 1550 Plymouth St., Mountain View, CA 94043
Domain=khaw@parcplace.com, UUCP=...!{uunet,sun,decwrl}!parcplace!khaw