Last active
July 11, 2019 04:54
-
-
Save brackendev/aff5d7c9901cf347638889c33f6522c8 to your computer and use it in GitHub Desktop.
[Pharo] Last Friday of each month
This file contains hidden or 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
| "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