Sha256: 6da6073f25036f861473d7fd438b9a8b2b2d3974687fc07546db5e11388826c4

Contents?: true

Size: 1.15 KB

Versions: 84

Compression:

Stored size: 1.15 KB

Contents

-module(meetup).
-export([schedule/4]).

-type year() :: non_neg_integer().
-type month() :: 1..12.
-type day() :: 1..31.
-type date() :: {year(), month(), day()}.
-type day_of_week() :: monday | tuesday | wednesday | thursday | friday | saturday | sunday.
-type period() :: first | second | third | fourth | teenth | last.

-define (DAY_MAP, #{monday => 1, tuesday => 2, wednesday => 3, thursday => 4,
                    friday => 5, saturday => 6, sunday => 7}).

-spec schedule(year(), month(), day_of_week(), period()) -> date().
schedule(Year, Month, DayOfWeek, Period) ->
  DoW = maps:get(DayOfWeek, ?DAY_MAP),
  [Day] = [Day || Day <- day_range(Period, Year, Month),
                  calendar:day_of_the_week({Year, Month, Day}) =:= DoW],
  {Year, Month, Day}.

day_range(first, _Year, _Month) ->
  lists:seq(1, 7);
day_range(second, _Year, _Month) ->
  lists:seq(8, 14);
day_range(third, _Year, _Month) ->
  lists:seq(15, 21);
day_range(fourth, _Year, _Month) ->
  lists:seq(22, 28);
day_range(teenth, _Year, _Month) ->
  lists:seq(13, 19);
day_range(last, Year, Month) ->
  LastDay = calendar:last_day_of_the_month(Year, Month),
  lists:seq(LastDay - 6, LastDay).

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
trackler-2.0.6.28 tracks/erlang/exercises/meetup/example.erl
trackler-2.0.6.27 tracks/erlang/exercises/meetup/example.erl
trackler-2.0.6.26 tracks/erlang/exercises/meetup/example.erl
trackler-2.0.6.25 tracks/erlang/exercises/meetup/example.erl
trackler-2.0.6.24 tracks/erlang/exercises/meetup/example.erl
trackler-2.0.6.23 tracks/erlang/exercises/meetup/example.erl
trackler-2.0.6.22 tracks/erlang/exercises/meetup/example.erl
trackler-2.0.6.21 tracks/erlang/exercises/meetup/example.erl
trackler-2.0.6.20 tracks/erlang/exercises/meetup/example.erl
trackler-2.0.6.19 tracks/erlang/exercises/meetup/example.erl
trackler-2.0.6.18 tracks/erlang/exercises/meetup/example.erl
trackler-2.0.6.17 tracks/erlang/exercises/meetup/example.erl
trackler-2.0.6.16 tracks/erlang/exercises/meetup/example.erl
trackler-2.0.6.15 tracks/erlang/exercises/meetup/example.erl
trackler-2.0.6.14 tracks/erlang/exercises/meetup/example.erl
trackler-2.0.6.13 tracks/erlang/exercises/meetup/example.erl
trackler-2.0.6.12 tracks/erlang/exercises/meetup/example.erl
trackler-2.0.6.11 tracks/erlang/exercises/meetup/example.erl
trackler-2.0.6.10 tracks/erlang/exercises/meetup/example.erl
trackler-2.0.6.9 tracks/erlang/exercises/meetup/example.erl