Published at Oct 09 2019
·
0 comments

Instructions

Test suite

Solution

Calculate the date of meetups.

Typically meetups happen on the same day of the week. In this exercise, you will take a description of a meetup date, and return the actual meetup date.

Examples of general descriptions are:

- The first Monday of January 2017
- The third Tuesday of January 2017
- The wednesteenth of January 2017
- The last Thursday of January 2017

The descriptors you are expected to parse are: first, second, third, fourth, fifth, last, monteenth, tuesteenth, wednesteenth, thursteenth, friteenth, saturteenth, sunteenth

Note that "monteenth", "tuesteenth", etc are all made up words. There was a meetup whose members realized that there are exactly 7 numbered days in a month that end in '-teenth'. Therefore, one is guaranteed that each day of the week (Monday, Tuesday, ...) will have exactly one date that is named with '-teenth' in every month.

Given examples of a meetup dates, each containing a month, day, year, and descriptor calculate the date of the actual meetup. For example, if given "The first Monday of January 2017", the correct meetup date is 2017/1/2.

Go through the setup instructions for Kotlin to install the necessary dependencies:

https://exercism.io/tracks/kotlin/installation

Execute the tests with:

```
$ gradlew test
```

Use

`gradlew.bat`

if you're on Windows

In the test suites all tests but the first have been skipped.

Once you get a test passing, you can enable the next one by removing the
`@Ignore`

annotation.

Jeremy Hinegardner mentioned a Boulder meetup that happens on the Wednesteenth of every month https://twitter.com/copiousfreetime

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

```
import org.junit.Ignore
import org.junit.Test
import java.time.DayOfWeek
import java.time.LocalDate
import kotlin.test.assertEquals
class MeetupTest {
@Test
fun testMonteenthOfMay2013() {
val expected = LocalDate.of(2013, 5, 13)
val meetup = Meetup(5, 2013)
assertEquals(expected, meetup.day(DayOfWeek.MONDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testMonteenthOfAugust2013() {
val expected = LocalDate.of(2013, 8, 19)
val meetup = Meetup(8, 2013)
assertEquals(expected, meetup.day(DayOfWeek.MONDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testMonteenthOfSeptember2013() {
val expected = LocalDate.of(2013, 9, 16)
val meetup = Meetup(9, 2013)
assertEquals(expected, meetup.day(DayOfWeek.MONDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testTuesteenthOfMarch2013() {
val expected = LocalDate.of(2013, 3, 19)
val meetup = Meetup(3, 2013)
assertEquals(expected, meetup.day(DayOfWeek.TUESDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testTuesteenthOfApril2013() {
val expected = LocalDate.of(2013, 4, 16)
val meetup = Meetup(4, 2013)
assertEquals(expected, meetup.day(DayOfWeek.TUESDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testTuesteenthOfAugust2013() {
val expected = LocalDate.of(2013, 8, 13)
val meetup = Meetup(8, 2013)
assertEquals(expected, meetup.day(DayOfWeek.TUESDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testWednesteenthOfJanuary2013() {
val expected = LocalDate.of(2013, 1, 16)
val meetup = Meetup(1, 2013)
assertEquals(expected, meetup.day(DayOfWeek.WEDNESDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testWednesteenthOfFebruary2013() {
val expected = LocalDate.of(2013, 2, 13)
val meetup = Meetup(2, 2013)
assertEquals(expected, meetup.day(DayOfWeek.WEDNESDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testWednesteenthOfJune2013() {
val expected = LocalDate.of(2013, 6, 19)
val meetup = Meetup(6, 2013)
assertEquals(expected, meetup.day(DayOfWeek.WEDNESDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testThursteenthOfMay2013() {
val expected = LocalDate.of(2013, 5, 16)
val meetup = Meetup(5, 2013)
assertEquals(expected, meetup.day(DayOfWeek.THURSDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testThursteenthOfJune2013() {
val expected = LocalDate.of(2013, 6, 13)
val meetup = Meetup(6, 2013)
assertEquals(expected, meetup.day(DayOfWeek.THURSDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testThursteenthOfSeptember2013() {
val expected = LocalDate.of(2013, 9, 19)
val meetup = Meetup(9, 2013)
assertEquals(expected, meetup.day(DayOfWeek.THURSDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testFriteenthOfApril2013() {
val expected = LocalDate.of(2013, 4, 19)
val meetup = Meetup(4, 2013)
assertEquals(expected, meetup.day(DayOfWeek.FRIDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testFriteenthOfAugust2013() {
val expected = LocalDate.of(2013, 8, 16)
val meetup = Meetup(8, 2013)
assertEquals(expected, meetup.day(DayOfWeek.FRIDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testFriteenthOfSeptember2013() {
val expected = LocalDate.of(2013, 9, 13)
val meetup = Meetup(9, 2013)
assertEquals(expected, meetup.day(DayOfWeek.FRIDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testSaturteenthOfFebruary2013() {
val expected = LocalDate.of(2013, 2, 16)
val meetup = Meetup(2, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SATURDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testSaturteenthOfApril2013() {
val expected = LocalDate.of(2013, 4, 13)
val meetup = Meetup(4, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SATURDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testSaturteenthOfOctober2013() {
val expected = LocalDate.of(2013, 10, 19)
val meetup = Meetup(10, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SATURDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testSunteenthOfMay2013() {
val expected = LocalDate.of(2013, 5, 19)
val meetup = Meetup(5, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SUNDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testSunteenthOfJune2013() {
val expected = LocalDate.of(2013, 6, 16)
val meetup = Meetup(6, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SUNDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testSunteenthOfOctober2013() {
val expected = LocalDate.of(2013, 10, 13)
val meetup = Meetup(10, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SUNDAY, MeetupSchedule.TEENTH))
}
@Ignore
@Test
fun testFirstMondayOfMarch2013() {
val expected = LocalDate.of(2013, 3, 4)
val meetup = Meetup(3, 2013)
assertEquals(expected, meetup.day(DayOfWeek.MONDAY, MeetupSchedule.FIRST))
}
@Ignore
@Test
fun testFirstMondayOfApril2013() {
val expected = LocalDate.of(2013, 4, 1)
val meetup = Meetup(4, 2013)
assertEquals(expected, meetup.day(DayOfWeek.MONDAY, MeetupSchedule.FIRST))
}
@Ignore
@Test
fun testFirstTuesdayOfMay2013() {
val expected = LocalDate.of(2013, 5, 7)
val meetup = Meetup(5, 2013)
assertEquals(expected, meetup.day(DayOfWeek.TUESDAY, MeetupSchedule.FIRST))
}
@Ignore
@Test
fun testFirstTuesdayOfJune2013() {
val expected = LocalDate.of(2013, 6, 4)
val meetup = Meetup(6, 2013)
assertEquals(expected, meetup.day(DayOfWeek.TUESDAY, MeetupSchedule.FIRST))
}
@Ignore
@Test
fun testFirstWednesdayOfJuly2013() {
val expected = LocalDate.of(2013, 7, 3)
val meetup = Meetup(7, 2013)
assertEquals(expected, meetup.day(DayOfWeek.WEDNESDAY, MeetupSchedule.FIRST))
}
@Ignore
@Test
fun testFirstWednesdayOfAugust2013() {
val expected = LocalDate.of(2013, 8, 7)
val meetup = Meetup(8, 2013)
assertEquals(expected, meetup.day(DayOfWeek.WEDNESDAY, MeetupSchedule.FIRST))
}
@Ignore
@Test
fun testFirstThursdayOfSeptember2013() {
val expected = LocalDate.of(2013, 9, 5)
val meetup = Meetup(9, 2013)
assertEquals(expected, meetup.day(DayOfWeek.THURSDAY, MeetupSchedule.FIRST))
}
@Ignore
@Test
fun testFirstThursdayOfOctober2013() {
val expected = LocalDate.of(2013, 10, 3)
val meetup = Meetup(10, 2013)
assertEquals(expected, meetup.day(DayOfWeek.THURSDAY, MeetupSchedule.FIRST))
}
@Ignore
@Test
fun testFirstFridayOfNovember2013() {
val expected = LocalDate.of(2013, 11, 1)
val meetup = Meetup(11, 2013)
assertEquals(expected, meetup.day(DayOfWeek.FRIDAY, MeetupSchedule.FIRST))
}
@Ignore
@Test
fun testFirstFridayOfDecember2013() {
val expected = LocalDate.of(2013, 12, 6)
val meetup = Meetup(12, 2013)
assertEquals(expected, meetup.day(DayOfWeek.FRIDAY, MeetupSchedule.FIRST))
}
@Ignore
@Test
fun testFirstSaturdayOfJanuary2013() {
val expected = LocalDate.of(2013, 1, 5)
val meetup = Meetup(1, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SATURDAY, MeetupSchedule.FIRST))
}
@Ignore
@Test
fun testFirstSaturdayOfFebruary2013() {
val expected = LocalDate.of(2013, 2, 2)
val meetup = Meetup(2, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SATURDAY, MeetupSchedule.FIRST))
}
@Ignore
@Test
fun testFirstSundayOfMarch2013() {
val expected = LocalDate.of(2013, 3, 3)
val meetup = Meetup(3, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SUNDAY, MeetupSchedule.FIRST))
}
@Ignore
@Test
fun testFirstSundayOfApril2013() {
val expected = LocalDate.of(2013, 4, 7)
val meetup = Meetup(4, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SUNDAY, MeetupSchedule.FIRST))
}
@Ignore
@Test
fun testSecondMondayOfMarch2013() {
val expected = LocalDate.of(2013, 3, 11)
val meetup = Meetup(3, 2013)
assertEquals(expected, meetup.day(DayOfWeek.MONDAY, MeetupSchedule.SECOND))
}
@Ignore
@Test
fun testSecondMondayOfApril2013() {
val expected = LocalDate.of(2013, 4, 8)
val meetup = Meetup(4, 2013)
assertEquals(expected, meetup.day(DayOfWeek.MONDAY, MeetupSchedule.SECOND))
}
@Ignore
@Test
fun testSecondTuesdayOfMay2013() {
val expected = LocalDate.of(2013, 5, 14)
val meetup = Meetup(5, 2013)
assertEquals(expected, meetup.day(DayOfWeek.TUESDAY, MeetupSchedule.SECOND))
}
@Ignore
@Test
fun testSecondTuesdayOfJune2013() {
val expected = LocalDate.of(2013, 6, 11)
val meetup = Meetup(6, 2013)
assertEquals(expected, meetup.day(DayOfWeek.TUESDAY, MeetupSchedule.SECOND))
}
@Ignore
@Test
fun testSecondWednesdayOfJuly2013() {
val expected = LocalDate.of(2013, 7, 10)
val meetup = Meetup(7, 2013)
assertEquals(expected, meetup.day(DayOfWeek.WEDNESDAY, MeetupSchedule.SECOND))
}
@Ignore
@Test
fun testSecondWednesdayOfAugust2013() {
val expected = LocalDate.of(2013, 8, 14)
val meetup = Meetup(8, 2013)
assertEquals(expected, meetup.day(DayOfWeek.WEDNESDAY, MeetupSchedule.SECOND))
}
@Ignore
@Test
fun testSecondThursdayOfSeptember2013() {
val expected = LocalDate.of(2013, 9, 12)
val meetup = Meetup(9, 2013)
assertEquals(expected, meetup.day(DayOfWeek.THURSDAY, MeetupSchedule.SECOND))
}
@Ignore
@Test
fun testSecondThursdayOfOctober2013() {
val expected = LocalDate.of(2013, 10, 10)
val meetup = Meetup(10, 2013)
assertEquals(expected, meetup.day(DayOfWeek.THURSDAY, MeetupSchedule.SECOND))
}
@Ignore
@Test
fun testSecondFridayOfNovember2013() {
val expected = LocalDate.of(2013, 11, 8)
val meetup = Meetup(11, 2013)
assertEquals(expected, meetup.day(DayOfWeek.FRIDAY, MeetupSchedule.SECOND))
}
@Ignore
@Test
fun testSecondFridayOfDecember2013() {
val expected = LocalDate.of(2013, 12, 13)
val meetup = Meetup(12, 2013)
assertEquals(expected, meetup.day(DayOfWeek.FRIDAY, MeetupSchedule.SECOND))
}
@Ignore
@Test
fun testSecondSaturdayOfJanuary2013() {
val expected = LocalDate.of(2013, 1, 12)
val meetup = Meetup(1, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SATURDAY, MeetupSchedule.SECOND))
}
@Ignore
@Test
fun testSecondSaturdayOfFebruary2013() {
val expected = LocalDate.of(2013, 2, 9)
val meetup = Meetup(2, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SATURDAY, MeetupSchedule.SECOND))
}
@Ignore
@Test
fun testSecondSundayOfMarch2013() {
val expected = LocalDate.of(2013, 3, 10)
val meetup = Meetup(3, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SUNDAY, MeetupSchedule.SECOND))
}
@Ignore
@Test
fun testSecondSundayOfApril2013() {
val expected = LocalDate.of(2013, 4, 14)
val meetup = Meetup(4, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SUNDAY, MeetupSchedule.SECOND))
}
@Ignore
@Test
fun testThirdMondayOfMarch2013() {
val expected = LocalDate.of(2013, 3, 18)
val meetup = Meetup(3, 2013)
assertEquals(expected, meetup.day(DayOfWeek.MONDAY, MeetupSchedule.THIRD))
}
@Ignore
@Test
fun testThirdMondayOfApril2013() {
val expected = LocalDate.of(2013, 4, 15)
val meetup = Meetup(4, 2013)
assertEquals(expected, meetup.day(DayOfWeek.MONDAY, MeetupSchedule.THIRD))
}
@Ignore
@Test
fun testThirdTuesdayOfMay2013() {
val expected = LocalDate.of(2013, 5, 21)
val meetup = Meetup(5, 2013)
assertEquals(expected, meetup.day(DayOfWeek.TUESDAY, MeetupSchedule.THIRD))
}
@Ignore
@Test
fun testThirdTuesdayOfJune2013() {
val expected = LocalDate.of(2013, 6, 18)
val meetup = Meetup(6, 2013)
assertEquals(expected, meetup.day(DayOfWeek.TUESDAY, MeetupSchedule.THIRD))
}
@Ignore
@Test
fun testThirdWednesdayOfJuly2013() {
val expected = LocalDate.of(2013, 7, 17)
val meetup = Meetup(7, 2013)
assertEquals(expected, meetup.day(DayOfWeek.WEDNESDAY, MeetupSchedule.THIRD))
}
@Ignore
@Test
fun testThirdWednesdayOfAugust2013() {
val expected = LocalDate.of(2013, 8, 21)
val meetup = Meetup(8, 2013)
assertEquals(expected, meetup.day(DayOfWeek.WEDNESDAY, MeetupSchedule.THIRD))
}
@Ignore
@Test
fun testThirdThursdayOfSeptember2013() {
val expected = LocalDate.of(2013, 9, 19)
val meetup = Meetup(9, 2013)
assertEquals(expected, meetup.day(DayOfWeek.THURSDAY, MeetupSchedule.THIRD))
}
@Ignore
@Test
fun testThirdThursdayOfOctober2013() {
val expected = LocalDate.of(2013, 10, 17)
val meetup = Meetup(10, 2013)
assertEquals(expected, meetup.day(DayOfWeek.THURSDAY, MeetupSchedule.THIRD))
}
@Ignore
@Test
fun testThirdFridayOfNovember2013() {
val expected = LocalDate.of(2013, 11, 15)
val meetup = Meetup(11, 2013)
assertEquals(expected, meetup.day(DayOfWeek.FRIDAY, MeetupSchedule.THIRD))
}
@Ignore
@Test
fun testThirdFridayOfDecember2013() {
val expected = LocalDate.of(2013, 12, 20)
val meetup = Meetup(12, 2013)
assertEquals(expected, meetup.day(DayOfWeek.FRIDAY, MeetupSchedule.THIRD))
}
@Ignore
@Test
fun testThirdSaturdayOfJanuary2013() {
val expected = LocalDate.of(2013, 1, 19)
val meetup = Meetup(1, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SATURDAY, MeetupSchedule.THIRD))
}
@Ignore
@Test
fun testThirdSaturdayOfFebruary2013() {
val expected = LocalDate.of(2013, 2, 16)
val meetup = Meetup(2, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SATURDAY, MeetupSchedule.THIRD))
}
@Ignore
@Test
fun testThirdSundayOfMarch2013() {
val expected = LocalDate.of(2013, 3, 17)
val meetup = Meetup(3, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SUNDAY, MeetupSchedule.THIRD))
}
@Ignore
@Test
fun testThirdSundayOfApril2013() {
val expected = LocalDate.of(2013, 4, 21)
val meetup = Meetup(4, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SUNDAY, MeetupSchedule.THIRD))
}
@Ignore
@Test
fun testFourthMondayOfMarch2013() {
val expected = LocalDate.of(2013, 3, 25)
val meetup = Meetup(3, 2013)
assertEquals(expected, meetup.day(DayOfWeek.MONDAY, MeetupSchedule.FOURTH))
}
@Ignore
@Test
fun testFourthMondayOfApril2013() {
val expected = LocalDate.of(2013, 4, 22)
val meetup = Meetup(4, 2013)
assertEquals(expected, meetup.day(DayOfWeek.MONDAY, MeetupSchedule.FOURTH))
}
@Ignore
@Test
fun testFourthTuesdayOfMay2013() {
val expected = LocalDate.of(2013, 5, 28)
val meetup = Meetup(5, 2013)
assertEquals(expected, meetup.day(DayOfWeek.TUESDAY, MeetupSchedule.FOURTH))
}
@Ignore
@Test
fun testFourthTuesdayOfJune2013() {
val expected = LocalDate.of(2013, 6, 25)
val meetup = Meetup(6, 2013)
assertEquals(expected, meetup.day(DayOfWeek.TUESDAY, MeetupSchedule.FOURTH))
}
@Ignore
@Test
fun testFourthWednesdayOfJuly2013() {
val expected = LocalDate.of(2013, 7, 24)
val meetup = Meetup(7, 2013)
assertEquals(expected, meetup.day(DayOfWeek.WEDNESDAY, MeetupSchedule.FOURTH))
}
@Ignore
@Test
fun testFourthWednesdayOfAugust2013() {
val expected = LocalDate.of(2013, 8, 28)
val meetup = Meetup(8, 2013)
assertEquals(expected, meetup.day(DayOfWeek.WEDNESDAY, MeetupSchedule.FOURTH))
}
@Ignore
@Test
fun testFourthThursdayOfSeptember2013() {
val expected = LocalDate.of(2013, 9, 26)
val meetup = Meetup(9, 2013)
assertEquals(expected, meetup.day(DayOfWeek.THURSDAY, MeetupSchedule.FOURTH))
}
@Ignore
@Test
fun testFourthThursdayOfOctober2013() {
val expected = LocalDate.of(2013, 10, 24)
val meetup = Meetup(10, 2013)
assertEquals(expected, meetup.day(DayOfWeek.THURSDAY, MeetupSchedule.FOURTH))
}
@Ignore
@Test
fun testFourthFridayOfNovember2013() {
val expected = LocalDate.of(2013, 11, 22)
val meetup = Meetup(11, 2013)
assertEquals(expected, meetup.day(DayOfWeek.FRIDAY, MeetupSchedule.FOURTH))
}
@Ignore
@Test
fun testFourthFridayOfDecember2013() {
val expected = LocalDate.of(2013, 12, 27)
val meetup = Meetup(12, 2013)
assertEquals(expected, meetup.day(DayOfWeek.FRIDAY, MeetupSchedule.FOURTH))
}
@Ignore
@Test
fun testFourthSaturdayOfJanuary2013() {
val expected = LocalDate.of(2013, 1, 26)
val meetup = Meetup(1, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SATURDAY, MeetupSchedule.FOURTH))
}
@Ignore
@Test
fun testFourthSaturdayOfFebruary2013() {
val expected = LocalDate.of(2013, 2, 23)
val meetup = Meetup(2, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SATURDAY, MeetupSchedule.FOURTH))
}
@Ignore
@Test
fun testFourthSundayOfMarch2013() {
val expected = LocalDate.of(2013, 3, 24)
val meetup = Meetup(3, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SUNDAY, MeetupSchedule.FOURTH))
}
@Ignore
@Test
fun testFourthSundayOfApril2013() {
val expected = LocalDate.of(2013, 4, 28)
val meetup = Meetup(4, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SUNDAY, MeetupSchedule.FOURTH))
}
@Ignore
@Test
fun testLastMondayOfMarch2013() {
val expected = LocalDate.of(2013, 3, 25)
val meetup = Meetup(3, 2013)
assertEquals(expected, meetup.day(DayOfWeek.MONDAY, MeetupSchedule.LAST))
}
@Ignore
@Test
fun testLastMondayOfApril2013() {
val expected = LocalDate.of(2013, 4, 29)
val meetup = Meetup(4, 2013)
assertEquals(expected, meetup.day(DayOfWeek.MONDAY, MeetupSchedule.LAST))
}
@Ignore
@Test
fun testLastTuesdayOfMay2013() {
val expected = LocalDate.of(2013, 5, 28)
val meetup = Meetup(5, 2013)
assertEquals(expected, meetup.day(DayOfWeek.TUESDAY, MeetupSchedule.LAST))
}
@Ignore
@Test
fun testLastTuesdayOfJune2013() {
val expected = LocalDate.of(2013, 6, 25)
val meetup = Meetup(6, 2013)
assertEquals(expected, meetup.day(DayOfWeek.TUESDAY, MeetupSchedule.LAST))
}
@Ignore
@Test
fun testLastWednesdayOfJuly2013() {
val expected = LocalDate.of(2013, 7, 31)
val meetup = Meetup(7, 2013)
assertEquals(expected, meetup.day(DayOfWeek.WEDNESDAY, MeetupSchedule.LAST))
}
@Ignore
@Test
fun testLastWednesdayOfAugust2013() {
val expected = LocalDate.of(2013, 8, 28)
val meetup = Meetup(8, 2013)
assertEquals(expected, meetup.day(DayOfWeek.WEDNESDAY, MeetupSchedule.LAST))
}
@Ignore
@Test
fun testLastThursdayOfSeptember2013() {
val expected = LocalDate.of(2013, 9, 26)
val meetup = Meetup(9, 2013)
assertEquals(expected, meetup.day(DayOfWeek.THURSDAY, MeetupSchedule.LAST))
}
@Ignore
@Test
fun testLastThursdayOfOctober2013() {
val expected = LocalDate.of(2013, 10, 31)
val meetup = Meetup(10, 2013)
assertEquals(expected, meetup.day(DayOfWeek.THURSDAY, MeetupSchedule.LAST))
}
@Ignore
@Test
fun testLastFridayOfNovember2013() {
val expected = LocalDate.of(2013, 11, 29)
val meetup = Meetup(11, 2013)
assertEquals(expected, meetup.day(DayOfWeek.FRIDAY, MeetupSchedule.LAST))
}
@Ignore
@Test
fun testLastFridayOfDecember2013() {
val expected = LocalDate.of(2013, 12, 27)
val meetup = Meetup(12, 2013)
assertEquals(expected, meetup.day(DayOfWeek.FRIDAY, MeetupSchedule.LAST))
}
@Ignore
@Test
fun testLastSaturdayOfJanuary2013() {
val expected = LocalDate.of(2013, 1, 26)
val meetup = Meetup(1, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SATURDAY, MeetupSchedule.LAST))
}
@Ignore
@Test
fun testLastSaturdayOfFebruary2013() {
val expected = LocalDate.of(2013, 2, 23)
val meetup = Meetup(2, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SATURDAY, MeetupSchedule.LAST))
}
@Ignore
@Test
fun testLastSundayOfMarch2013() {
val expected = LocalDate.of(2013, 3, 31)
val meetup = Meetup(3, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SUNDAY, MeetupSchedule.LAST))
}
@Ignore
@Test
fun testLastSundayOfApril2013() {
val expected = LocalDate.of(2013, 4, 28)
val meetup = Meetup(4, 2013)
assertEquals(expected, meetup.day(DayOfWeek.SUNDAY, MeetupSchedule.LAST))
}
@Ignore
@Test
fun testLastWednesdayOfFebruary2012() {
val expected = LocalDate.of(2012, 2, 29)
val meetup = Meetup(2, 2012)
assertEquals(expected, meetup.day(DayOfWeek.WEDNESDAY, MeetupSchedule.LAST))
}
@Ignore
@Test
fun testLastWednesdayOfDecember2014() {
val expected = LocalDate.of(2014, 12, 31)
val meetup = Meetup(12, 2014)
assertEquals(expected, meetup.day(DayOfWeek.WEDNESDAY, MeetupSchedule.LAST))
}
@Ignore
@Test
fun testLastSundayOfFebruary2015() {
val expected = LocalDate.of(2015, 2, 22)
val meetup = Meetup(2, 2015)
assertEquals(expected, meetup.day(DayOfWeek.SUNDAY, MeetupSchedule.LAST))
}
@Ignore
@Test
fun testFirstFridayOfDecember2012() {
val expected = LocalDate.of(2012, 12, 7)
val meetup = Meetup(12, 2012)
assertEquals(expected, meetup.day(DayOfWeek.FRIDAY, MeetupSchedule.FIRST))
}
}
```

```
import java.time.DayOfWeek
import java.time.LocalDate
import java.time.YearMonth
class Meetup(val month: Int, val year: Int) {
fun day(dayOfWeek: DayOfWeek, schedule: MeetupSchedule): LocalDate? {
val lastDayOfMonth = YearMonth.of(year, month).lengthOfMonth()
val range = if (schedule == MeetupSchedule.TEENTH) {
13..19 } else { 1..lastDayOfMonth }
val candidates = range.map { dayOfMonth ->
LocalDate.of(year, month, dayOfMonth)
}.filter { date -> date.dayOfWeek == dayOfWeek }
return when (schedule) {
MeetupSchedule.TEENTH -> candidates.first()
MeetupSchedule.LAST -> candidates.last()
else -> candidates[schedule.ordinal]
}
}
}
```

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

- What compromises have been made?
- Are there new concepts here that you could read more about to improve your understanding?

Level up your programming skills with 3,092 exercises across 52 languages, and insightful discussion with our volunteer team of welcoming mentors.
Exercism is
**100% free forever**.

## Community comments