Last active
October 14, 2019 04:34
-
-
Save melriffe/cfa53b8f6cd12f75f03d32075c49b82c to your computer and use it in GitHub Desktop.
GNU Smalltalk script exploring dates and "2nd Saturday of the Month"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/local/bin/gst -f | |
" | |
This script is a way for me to get back into Smalltalk doing odd little tasks. | |
$ gst /Users/mriffe/dev/play/dnd_games/dates.st | |
$ gist -u https://gist.github.com/cfa53b8f6cd12f75f03d32075c49b82c dates.st | |
" | |
| today nextDate isSaturday saturday oneWeek | | |
saturday := 6. | |
oneWeek := 7. | |
isSaturday := false. | |
today := Date today. | |
nextDate := today firstDayOfMonth. | |
1 to: oneWeek do: [:x | | |
isSaturday := nextDate dayOfWeek = saturday. | |
isSaturday | |
ifTrue: [ ^ nextDate ]. | |
nextDate := nextDate addDays: 1. | |
]. | |
nextDate printNl. | |
(nextDate addDays: (1 * oneWeek)) printNl | |
(nextDate addDays: (2 * oneWeek)) printNl | |
(nextDate addDays: (3 * oneWeek)) printNl | |
'Fin' printNl. |
Goal: to extend Date so I can send messages like .secondSaturdayOfMonth or .thirdMondayOfMonth
This script gives me a way to collect up the desired days. I can put them in an Array and answer the message with an index selection.
At least, that's the plan.
Change of plans. Now the script can/will do the following: from the first of the month, find the first occurrence of the target day of the week. After that, add the number of days that would coincide with the desired answer. For 2d Saturday add 7 days (the script will have found the first before adding more days).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.gnu.org/software/smalltalk/manual-base/html_node/index.html
https://www.gnu.org/software/smalltalk/manual/html_node/index.html