Re: [Pharo-users] Week number from a date
On Thu, May 12, 2016 at 9:47 PM, Davide Varvello via Pharo-users <pharo-users@lists.pharo.org> wrote:
---------- Forwarded message ---------- From: Davide Varvello <varvello@yahoo.com> To: pharo-users@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@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 preferences? [1] http://wiki.squeak.org/squeak/5699 cheers -ben
Thanks Ben Davide -- View this message in context: http://forum.world.st/Week-number-from-a-date-tp4894486p4894576.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
Yes I agree. We may have a preference to set the week day start ( fistDayOfWeek ?) . After that we could agree on the fact the first week is the first complete week (otherwise it can be a preference). Then we need to find the first day index of the first fistDayOfWeek. (Date year: self year day: 1) weekdayIndex -> gives the index according to the preference (for now Sunday -> 1) Then itâs quite straightforward to get the week number. Just have to check if the current date is in the last week of the previous year (returns 52 or 53). I did something but not sure yet (but no preference). There are been some works on time representation (Chronos if I remember well ? but cannot load in Pharo 5, depends on OSProcess). An interesting read [1]. Cheers, Cédrik ps: http://stephane.ducasse.free.fr/Teaching/CoursAnnecy/0506-M1-COO/A%20New%20O... 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 preferences?
Chalten might help, i remember it had representations for months of years (January of 1990), it might have something similar for weeks. On 13 May 2016 at 05:40, Cédrick Béler <cdrick65@gmail.com> wrote:
Yes I agree. We may have a preference to set the week day start (fistDayOfWeek ?).
After that we could agree on the fact the first week is the first complete week (otherwise it can be a preference).
Then we need to find the first day index of the first fistDayOfWeek. (Date year: self year day: 1) weekdayIndex -> gives the index according to the preference (for now Sunday -> 1)
Then itâs quite straightforward to get the week number.
Just have to check if the current date is in the last week of the previous year (returns 52 or 53). I did something but not sure yet (but no preference).
There are been some works on time representation (Chronos if I remember well ? but cannot load in Pharo 5, depends on OSProcess).
An interesting read [1].
Cheers,
Cédrik
ps: http://stephane.ducasse.free.fr/Teaching/CoursAnnecy/0506-M1-COO/A%20New%20O...
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 preferences?
participants (4)
-
Ben Coman -
Cédrick Béler -
Davide Varvello -
Julián Maestri