[Pharo-users] Week number from a date

Ben Coman btc at openinworld.com
Thu May 12 22:25:28 EDT 2016

On Thu, May 12, 2016 at 9:47 PM, Davide Varvello via Pharo-users
<pharo-users at lists.pharo.org> wrote:
> ---------- Forwarded message ----------
> From: Davide Varvello <varvello at yahoo.com>
> To: pharo-users at lists.pharo.org
> Cc:
> Date: Thu, 12 May 2016 06:10:12 -0700 (PDT)
> Subject: Week number from a date
> Hi guys,
> Is there a way to have the week number when a date is given?
> Ex: 2016/01/13 gives 2, 2016/01/19 gives 3, and so on

It seems the answer is no.  But to expand on how I determined that, in
the interest of teaching how to fish...

1. Open World > Tools > Finder
2. Select examples
3. Enter....
          Date readFromString: '2016/01/13' . 2016
4. Click <Search>
This returns one result, the message #year.

5. Next trying....      Date readFromString: '2016/01/13' . 3
This returns no result.

Think of the search term as an array of two objects separated by the
period.  The first object is the receiver of the message.  The last
object is the result. Any additional objects in between are message
parameters.  Try this one....    #(5 6 7 8) . 2 . #(5 6)

On Fri, May 13, 2016 at 12:24 AM, Sven Van Caekenberghe <sven at stfx.eu> wrote:
> https://en.wikipedia.org/wiki/Week#Week_numbering
> of course, not all countries have the same definition of week.
> furthermore, week number does not seem to be so simple.

Interesting to know.  But I see this already seems hard coded...

Date nameOfDay: 1  "--> #Sunday"

Timespan subclass: #Date
    poolDictionaries: 'ChronologyConstants'

ChronologyConstants class >> initialize
     DayNames := #(Sunday Monday Tuesday Wednesday Thursday Friday Saturday).

Also seems to have changed at some point, with the historical
nameOfDay recorded in the Terse Guide [1] circa 2010 shown to be
different.  Perhaps this is something we should make a regional
preference.  Was there any ongoing works on other regional

[1] http://wiki.squeak.org/squeak/5699

cheers -ben

More information about the Pharo-users mailing list