Skip to content

Instantly share code, notes, and snippets.

@brackendev
Last active July 11, 2019 04:54
Show Gist options
  • Select an option

  • Save brackendev/aff5d7c9901cf347638889c33f6522c8 to your computer and use it in GitHub Desktop.

Select an option

Save brackendev/aff5d7c9901cf347638889c33f6522c8 to your computer and use it in GitHub Desktop.
[Pharo] Last Friday of each month
"https://rosettacode.org/wiki/Last_Friday_of_each_month"
| lastFriday |
lastFriday := [ :yr | | firstDay firstFriday |
firstDay := Date year: yr month: 1 day: 1.
firstFriday := firstDay addDays: (6 - firstDay dayOfWeek).
(0 to: 53)
collect: [ :each | firstFriday addDays: (each * 7) ]
thenSelect: [ :each |
(((Date daysInMonth: each monthIndex forYear: yr) - each dayOfMonth) <= 6) and: [ each year = yr ] ] ].
lastFriday value: 2019.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment