Skip to content

Instantly share code, notes, and snippets.

@melriffe
Last active October 14, 2019 04:34
Show Gist options
  • Save melriffe/cfa53b8f6cd12f75f03d32075c49b82c to your computer and use it in GitHub Desktop.
Save melriffe/cfa53b8f6cd12f75f03d32075c49b82c to your computer and use it in GitHub Desktop.
GNU Smalltalk script exploring dates and "2nd Saturday of the Month"
#! /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.
@melriffe
Copy link
Author

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.

@melriffe
Copy link
Author

melriffe commented Oct 14, 2019

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