[Seaside-dev] finding out the number of days in a month

Paolo Bonzini bonzini at gnu.org
Thu Feb 14 08:50:04 UTC 2008


> What we can't do:
> - Month class >> #daysInMonth:forYear: (GST)

Note that it's not that we "can't use this".  It's just that I don't 
want to port Squeak's date classes just for Seaside.

> Does anybody have a better idea than or problems with:
> 
> Date class>>#daysInMonthNumber:forYear:

If you don't need it very often, you can do something like

     d := Date newDay: 28 monthNumber: m year: y.
     d := d addDays: 4.
     d := d subtractDays: d dayOfMonth.
     ^d dayOfMonth

or maybe even

     d := Date newDay: 32 monthNumber: m year: y.
     d := d subtractDays: d dayOfMonth.
     ^d dayOfMonth

though I'm not sure of the portability of the latter.
Finally, the extension method could be #daysInMonth on the instance 
side, to be used like this:

     (Date newDay: 1 monthNumber: m year: y) daysInMonth


Paolo


More information about the seaside-dev mailing list