# 4d47's solution

## to Meetup in the Perl 6 Track

Published at Jul 13 2018 · 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.

## Resources

Remember to check out the Perl 6 documentation and resources pages for information, tips, and examples if you get stuck.

## Running the tests

There is a test suite and module included with the exercise. The test suite (a file with the extension `.t`) will attempt to run routines from the module (a file with the extension `.pm6`). Add/modify routines in the module so that the tests will pass! You can view the test data by executing the command `perl6 --doc *.t` (* being the name of the test suite), and run the test suite for the exercise by executing the command `prove6 .` in the exercise directory.

## Source

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

## Submitting Incomplete Solutions

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

### meetup.t

``````#!/usr/bin/env perl6
use v6;
use Test;
use JSON::Fast;
use lib \$?FILE.IO.dirname;
use Meetup;
plan 95;

my \$c-data = from-json \$=pod.pop.contents;
is meetup-date(.<description>), Date.new(|.<year month dayofmonth>), .<description> for @(\$c-data<cases>);

=begin code
{
"exercise": "meetup",
"version": "1.0.0",
"cases": [
{
"description": "monteenth of May 2013",
"property": "meetup",
"year": 2013,
"month": 5,
"week": "teenth",
"dayofweek": "Monday",
"dayofmonth": 13
},
{
"description": "monteenth of August 2013",
"property": "meetup",
"year": 2013,
"month": 8,
"week": "teenth",
"dayofweek": "Monday",
"dayofmonth": 19
},
{
"description": "monteenth of September 2013",
"property": "meetup",
"year": 2013,
"month": 9,
"week": "teenth",
"dayofweek": "Monday",
"dayofmonth": 16
},
{
"description": "tuesteenth of March 2013",
"property": "meetup",
"year": 2013,
"month": 3,
"week": "teenth",
"dayofweek": "Tuesday",
"dayofmonth": 19
},
{
"description": "tuesteenth of April 2013",
"property": "meetup",
"year": 2013,
"month": 4,
"week": "teenth",
"dayofweek": "Tuesday",
"dayofmonth": 16
},
{
"description": "tuesteenth of August 2013",
"property": "meetup",
"year": 2013,
"month": 8,
"week": "teenth",
"dayofweek": "Tuesday",
"dayofmonth": 13
},
{
"description": "wednesteenth of January 2013",
"property": "meetup",
"year": 2013,
"month": 1,
"week": "teenth",
"dayofweek": "Wednesday",
"dayofmonth": 16
},
{
"description": "wednesteenth of February 2013",
"property": "meetup",
"year": 2013,
"month": 2,
"week": "teenth",
"dayofweek": "Wednesday",
"dayofmonth": 13
},
{
"description": "wednesteenth of June 2013",
"property": "meetup",
"year": 2013,
"month": 6,
"week": "teenth",
"dayofweek": "Wednesday",
"dayofmonth": 19
},
{
"description": "thursteenth of May 2013",
"property": "meetup",
"year": 2013,
"month": 5,
"week": "teenth",
"dayofweek": "Thursday",
"dayofmonth": 16
},
{
"description": "thursteenth of June 2013",
"property": "meetup",
"year": 2013,
"month": 6,
"week": "teenth",
"dayofweek": "Thursday",
"dayofmonth": 13
},
{
"description": "thursteenth of September 2013",
"property": "meetup",
"year": 2013,
"month": 9,
"week": "teenth",
"dayofweek": "Thursday",
"dayofmonth": 19
},
{
"description": "friteenth of April 2013",
"property": "meetup",
"year": 2013,
"month": 4,
"week": "teenth",
"dayofweek": "Friday",
"dayofmonth": 19
},
{
"description": "friteenth of August 2013",
"property": "meetup",
"year": 2013,
"month": 8,
"week": "teenth",
"dayofweek": "Friday",
"dayofmonth": 16
},
{
"description": "friteenth of September 2013",
"property": "meetup",
"year": 2013,
"month": 9,
"week": "teenth",
"dayofweek": "Friday",
"dayofmonth": 13
},
{
"description": "saturteenth of February 2013",
"property": "meetup",
"year": 2013,
"month": 2,
"week": "teenth",
"dayofweek": "Saturday",
"dayofmonth": 16
},
{
"description": "saturteenth of April 2013",
"property": "meetup",
"year": 2013,
"month": 4,
"week": "teenth",
"dayofweek": "Saturday",
"dayofmonth": 13
},
{
"description": "saturteenth of October 2013",
"property": "meetup",
"year": 2013,
"month": 10,
"week": "teenth",
"dayofweek": "Saturday",
"dayofmonth": 19
},
{
"description": "sunteenth of May 2013",
"property": "meetup",
"year": 2013,
"month": 5,
"week": "teenth",
"dayofweek": "Sunday",
"dayofmonth": 19
},
{
"description": "sunteenth of June 2013",
"property": "meetup",
"year": 2013,
"month": 6,
"week": "teenth",
"dayofweek": "Sunday",
"dayofmonth": 16
},
{
"description": "sunteenth of October 2013",
"property": "meetup",
"year": 2013,
"month": 10,
"week": "teenth",
"dayofweek": "Sunday",
"dayofmonth": 13
},
{
"description": "first Monday of March 2013",
"property": "meetup",
"year": 2013,
"month": 3,
"week": "first",
"dayofweek": "Monday",
"dayofmonth": 4
},
{
"description": "first Monday of April 2013",
"property": "meetup",
"year": 2013,
"month": 4,
"week": "first",
"dayofweek": "Monday",
"dayofmonth": 1
},
{
"description": "first Tuesday of May 2013",
"property": "meetup",
"year": 2013,
"month": 5,
"week": "first",
"dayofweek": "Tuesday",
"dayofmonth": 7
},
{
"description": "first Tuesday of June 2013",
"property": "meetup",
"year": 2013,
"month": 6,
"week": "first",
"dayofweek": "Tuesday",
"dayofmonth": 4
},
{
"description": "first Wednesday of July 2013",
"property": "meetup",
"year": 2013,
"month": 7,
"week": "first",
"dayofweek": "Wednesday",
"dayofmonth": 3
},
{
"description": "first Wednesday of August 2013",
"property": "meetup",
"year": 2013,
"month": 8,
"week": "first",
"dayofweek": "Wednesday",
"dayofmonth": 7
},
{
"description": "first Thursday of September 2013",
"property": "meetup",
"year": 2013,
"month": 9,
"week": "first",
"dayofweek": "Thursday",
"dayofmonth": 5
},
{
"description": "first Thursday of October 2013",
"property": "meetup",
"year": 2013,
"month": 10,
"week": "first",
"dayofweek": "Thursday",
"dayofmonth": 3
},
{
"description": "first Friday of November 2013",
"property": "meetup",
"year": 2013,
"month": 11,
"week": "first",
"dayofweek": "Friday",
"dayofmonth": 1
},
{
"description": "first Friday of December 2013",
"property": "meetup",
"year": 2013,
"month": 12,
"week": "first",
"dayofweek": "Friday",
"dayofmonth": 6
},
{
"description": "first Saturday of January 2013",
"property": "meetup",
"year": 2013,
"month": 1,
"week": "first",
"dayofweek": "Saturday",
"dayofmonth": 5
},
{
"description": "first Saturday of February 2013",
"property": "meetup",
"year": 2013,
"month": 2,
"week": "first",
"dayofweek": "Saturday",
"dayofmonth": 2
},
{
"description": "first Sunday of March 2013",
"property": "meetup",
"year": 2013,
"month": 3,
"week": "first",
"dayofweek": "Sunday",
"dayofmonth": 3
},
{
"description": "first Sunday of April 2013",
"property": "meetup",
"year": 2013,
"month": 4,
"week": "first",
"dayofweek": "Sunday",
"dayofmonth": 7
},
{
"description": "second Monday of March 2013",
"property": "meetup",
"year": 2013,
"month": 3,
"week": "second",
"dayofweek": "Monday",
"dayofmonth": 11
},
{
"description": "second Monday of April 2013",
"property": "meetup",
"year": 2013,
"month": 4,
"week": "second",
"dayofweek": "Monday",
"dayofmonth": 8
},
{
"description": "second Tuesday of May 2013",
"property": "meetup",
"year": 2013,
"month": 5,
"week": "second",
"dayofweek": "Tuesday",
"dayofmonth": 14
},
{
"description": "second Tuesday of June 2013",
"property": "meetup",
"year": 2013,
"month": 6,
"week": "second",
"dayofweek": "Tuesday",
"dayofmonth": 11
},
{
"description": "second Wednesday of July 2013",
"property": "meetup",
"year": 2013,
"month": 7,
"week": "second",
"dayofweek": "Wednesday",
"dayofmonth": 10
},
{
"description": "second Wednesday of August 2013",
"property": "meetup",
"year": 2013,
"month": 8,
"week": "second",
"dayofweek": "Wednesday",
"dayofmonth": 14
},
{
"description": "second Thursday of September 2013",
"property": "meetup",
"year": 2013,
"month": 9,
"week": "second",
"dayofweek": "Thursday",
"dayofmonth": 12
},
{
"description": "second Thursday of October 2013",
"property": "meetup",
"year": 2013,
"month": 10,
"week": "second",
"dayofweek": "Thursday",
"dayofmonth": 10
},
{
"description": "second Friday of November 2013",
"property": "meetup",
"year": 2013,
"month": 11,
"week": "second",
"dayofweek": "Friday",
"dayofmonth": 8
},
{
"description": "second Friday of December 2013",
"property": "meetup",
"year": 2013,
"month": 12,
"week": "second",
"dayofweek": "Friday",
"dayofmonth": 13
},
{
"description": "second Saturday of January 2013",
"property": "meetup",
"year": 2013,
"month": 1,
"week": "second",
"dayofweek": "Saturday",
"dayofmonth": 12
},
{
"description": "second Saturday of February 2013",
"property": "meetup",
"year": 2013,
"month": 2,
"week": "second",
"dayofweek": "Saturday",
"dayofmonth": 9
},
{
"description": "second Sunday of March 2013",
"property": "meetup",
"year": 2013,
"month": 3,
"week": "second",
"dayofweek": "Sunday",
"dayofmonth": 10
},
{
"description": "second Sunday of April 2013",
"property": "meetup",
"year": 2013,
"month": 4,
"week": "second",
"dayofweek": "Sunday",
"dayofmonth": 14
},
{
"description": "third Monday of March 2013",
"property": "meetup",
"year": 2013,
"month": 3,
"week": "third",
"dayofweek": "Monday",
"dayofmonth": 18
},
{
"description": "third Monday of April 2013",
"property": "meetup",
"year": 2013,
"month": 4,
"week": "third",
"dayofweek": "Monday",
"dayofmonth": 15
},
{
"description": "third Tuesday of May 2013",
"property": "meetup",
"year": 2013,
"month": 5,
"week": "third",
"dayofweek": "Tuesday",
"dayofmonth": 21
},
{
"description": "third Tuesday of June 2013",
"property": "meetup",
"year": 2013,
"month": 6,
"week": "third",
"dayofweek": "Tuesday",
"dayofmonth": 18
},
{
"description": "third Wednesday of July 2013",
"property": "meetup",
"year": 2013,
"month": 7,
"week": "third",
"dayofweek": "Wednesday",
"dayofmonth": 17
},
{
"description": "third Wednesday of August 2013",
"property": "meetup",
"year": 2013,
"month": 8,
"week": "third",
"dayofweek": "Wednesday",
"dayofmonth": 21
},
{
"description": "third Thursday of September 2013",
"property": "meetup",
"year": 2013,
"month": 9,
"week": "third",
"dayofweek": "Thursday",
"dayofmonth": 19
},
{
"description": "third Thursday of October 2013",
"property": "meetup",
"year": 2013,
"month": 10,
"week": "third",
"dayofweek": "Thursday",
"dayofmonth": 17
},
{
"description": "third Friday of November 2013",
"property": "meetup",
"year": 2013,
"month": 11,
"week": "third",
"dayofweek": "Friday",
"dayofmonth": 15
},
{
"description": "third Friday of December 2013",
"property": "meetup",
"year": 2013,
"month": 12,
"week": "third",
"dayofweek": "Friday",
"dayofmonth": 20
},
{
"description": "third Saturday of January 2013",
"property": "meetup",
"year": 2013,
"month": 1,
"week": "third",
"dayofweek": "Saturday",
"dayofmonth": 19
},
{
"description": "third Saturday of February 2013",
"property": "meetup",
"year": 2013,
"month": 2,
"week": "third",
"dayofweek": "Saturday",
"dayofmonth": 16
},
{
"description": "third Sunday of March 2013",
"property": "meetup",
"year": 2013,
"month": 3,
"week": "third",
"dayofweek": "Sunday",
"dayofmonth": 17
},
{
"description": "third Sunday of April 2013",
"property": "meetup",
"year": 2013,
"month": 4,
"week": "third",
"dayofweek": "Sunday",
"dayofmonth": 21
},
{
"description": "fourth Monday of March 2013",
"property": "meetup",
"year": 2013,
"month": 3,
"week": "fourth",
"dayofweek": "Monday",
"dayofmonth": 25
},
{
"description": "fourth Monday of April 2013",
"property": "meetup",
"year": 2013,
"month": 4,
"week": "fourth",
"dayofweek": "Monday",
"dayofmonth": 22
},
{
"description": "fourth Tuesday of May 2013",
"property": "meetup",
"year": 2013,
"month": 5,
"week": "fourth",
"dayofweek": "Tuesday",
"dayofmonth": 28
},
{
"description": "fourth Tuesday of June 2013",
"property": "meetup",
"year": 2013,
"month": 6,
"week": "fourth",
"dayofweek": "Tuesday",
"dayofmonth": 25
},
{
"description": "fourth Wednesday of July 2013",
"property": "meetup",
"year": 2013,
"month": 7,
"week": "fourth",
"dayofweek": "Wednesday",
"dayofmonth": 24
},
{
"description": "fourth Wednesday of August 2013",
"property": "meetup",
"year": 2013,
"month": 8,
"week": "fourth",
"dayofweek": "Wednesday",
"dayofmonth": 28
},
{
"description": "fourth Thursday of September 2013",
"property": "meetup",
"year": 2013,
"month": 9,
"week": "fourth",
"dayofweek": "Thursday",
"dayofmonth": 26
},
{
"description": "fourth Thursday of October 2013",
"property": "meetup",
"year": 2013,
"month": 10,
"week": "fourth",
"dayofweek": "Thursday",
"dayofmonth": 24
},
{
"description": "fourth Friday of November 2013",
"property": "meetup",
"year": 2013,
"month": 11,
"week": "fourth",
"dayofweek": "Friday",
"dayofmonth": 22
},
{
"description": "fourth Friday of December 2013",
"property": "meetup",
"year": 2013,
"month": 12,
"week": "fourth",
"dayofweek": "Friday",
"dayofmonth": 27
},
{
"description": "fourth Saturday of January 2013",
"property": "meetup",
"year": 2013,
"month": 1,
"week": "fourth",
"dayofweek": "Saturday",
"dayofmonth": 26
},
{
"description": "fourth Saturday of February 2013",
"property": "meetup",
"year": 2013,
"month": 2,
"week": "fourth",
"dayofweek": "Saturday",
"dayofmonth": 23
},
{
"description": "fourth Sunday of March 2013",
"property": "meetup",
"year": 2013,
"month": 3,
"week": "fourth",
"dayofweek": "Sunday",
"dayofmonth": 24
},
{
"description": "fourth Sunday of April 2013",
"property": "meetup",
"year": 2013,
"month": 4,
"week": "fourth",
"dayofweek": "Sunday",
"dayofmonth": 28
},
{
"description": "last Monday of March 2013",
"property": "meetup",
"year": 2013,
"month": 3,
"week": "last",
"dayofweek": "Monday",
"dayofmonth": 25
},
{
"description": "last Monday of April 2013",
"property": "meetup",
"year": 2013,
"month": 4,
"week": "last",
"dayofweek": "Monday",
"dayofmonth": 29
},
{
"description": "last Tuesday of May 2013",
"property": "meetup",
"year": 2013,
"month": 5,
"week": "last",
"dayofweek": "Tuesday",
"dayofmonth": 28
},
{
"description": "last Tuesday of June 2013",
"property": "meetup",
"year": 2013,
"month": 6,
"week": "last",
"dayofweek": "Tuesday",
"dayofmonth": 25
},
{
"description": "last Wednesday of July 2013",
"property": "meetup",
"year": 2013,
"month": 7,
"week": "last",
"dayofweek": "Wednesday",
"dayofmonth": 31
},
{
"description": "last Wednesday of August 2013",
"property": "meetup",
"year": 2013,
"month": 8,
"week": "last",
"dayofweek": "Wednesday",
"dayofmonth": 28
},
{
"description": "last Thursday of September 2013",
"property": "meetup",
"year": 2013,
"month": 9,
"week": "last",
"dayofweek": "Thursday",
"dayofmonth": 26
},
{
"description": "last Thursday of October 2013",
"property": "meetup",
"year": 2013,
"month": 10,
"week": "last",
"dayofweek": "Thursday",
"dayofmonth": 31
},
{
"description": "last Friday of November 2013",
"property": "meetup",
"year": 2013,
"month": 11,
"week": "last",
"dayofweek": "Friday",
"dayofmonth": 29
},
{
"description": "last Friday of December 2013",
"property": "meetup",
"year": 2013,
"month": 12,
"week": "last",
"dayofweek": "Friday",
"dayofmonth": 27
},
{
"description": "last Saturday of January 2013",
"property": "meetup",
"year": 2013,
"month": 1,
"week": "last",
"dayofweek": "Saturday",
"dayofmonth": 26
},
{
"description": "last Saturday of February 2013",
"property": "meetup",
"year": 2013,
"month": 2,
"week": "last",
"dayofweek": "Saturday",
"dayofmonth": 23
},
{
"description": "last Sunday of March 2013",
"property": "meetup",
"year": 2013,
"month": 3,
"week": "last",
"dayofweek": "Sunday",
"dayofmonth": 31
},
{
"description": "last Sunday of April 2013",
"property": "meetup",
"year": 2013,
"month": 4,
"week": "last",
"dayofweek": "Sunday",
"dayofmonth": 28
},
{
"description": "last Wednesday of February 2012",
"property": "meetup",
"year": 2012,
"month": 2,
"week": "last",
"dayofweek": "Wednesday",
"dayofmonth": 29
},
{
"description": "last Wednesday of December 2014",
"property": "meetup",
"year": 2014,
"month": 12,
"week": "last",
"dayofweek": "Wednesday",
"dayofmonth": 31
},
{
"description": "last Sunday of February 2015",
"property": "meetup",
"year": 2015,
"month": 2,
"week": "last",
"dayofweek": "Sunday",
"dayofmonth": 22
},
{
"description": "first Friday of December 2012",
"property": "meetup",
"year": 2012,
"month": 12,
"week": "first",
"dayofweek": "Friday",
"dayofmonth": 7
}
]
}
=end code``````
``````unit module Meetup:ver<1>;

enum Months « :January(1) February March April May June July August September October November December »;
enum Days « :Mon(1) Tues Wednes Thurs Fri Satur Sun »;

sub meetup-date(\$desc) is export {
my @w = \$desc.words;
my \$date = Date.new(year => @w[*-1], month => Months.enums{@w[*-2]});
my \$day = S/day// given @w[1].lc;
given @w[0] {
when 'first' { \$date .= later(:0days) }
when 'second' { \$date .= later(:1week) }
when 'third' { \$date .= later(:2weeks) }
when 'fourth' { \$date .= later(:3weeks) }
when 'last' { \$date = \$date.later(:1month).earlier(:1week) }
when /teenth\$/ {
\$day = S/teenth// given \$_;
\$date .= later(:12days);
}
}
while \$date.day-of-week != Days.enums{\$day.tc} {
\$date .= succ;
}
return \$date;
}``````