Sha256: 3cec43ec8e44559cbb0565057c52b0dea04ed5f98a00f2066e6c42df2a118c25

Contents?: true

Size: 1.19 KB

Versions: 310

Compression:

Stored size: 1.19 KB

Contents

-module(example).
-export([schedule/4, test_version/0]).

-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}.

test_version() ->
    1.



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

310 entries across 310 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/erlang/exercises/meetup/src/example.erl
trackler-2.2.1.179 tracks/erlang/exercises/meetup/src/example.erl
trackler-2.2.1.178 tracks/erlang/exercises/meetup/src/example.erl
trackler-2.2.1.177 tracks/erlang/exercises/meetup/src/example.erl
trackler-2.2.1.176 tracks/erlang/exercises/meetup/src/example.erl
trackler-2.2.1.175 tracks/erlang/exercises/meetup/src/example.erl
trackler-2.2.1.174 tracks/erlang/exercises/meetup/src/example.erl
trackler-2.2.1.173 tracks/erlang/exercises/meetup/src/example.erl
trackler-2.2.1.172 tracks/erlang/exercises/meetup/src/example.erl
trackler-2.2.1.171 tracks/erlang/exercises/meetup/src/example.erl
trackler-2.2.1.170 tracks/erlang/exercises/meetup/src/example.erl
trackler-2.2.1.169 tracks/erlang/exercises/meetup/src/example.erl
trackler-2.2.1.167 tracks/erlang/exercises/meetup/src/example.erl
trackler-2.2.1.166 tracks/erlang/exercises/meetup/src/example.erl
trackler-2.2.1.165 tracks/erlang/exercises/meetup/src/example.erl
trackler-2.2.1.164 tracks/erlang/exercises/meetup/src/example.erl
trackler-2.2.1.163 tracks/erlang/exercises/meetup/src/example.erl
trackler-2.2.1.162 tracks/erlang/exercises/meetup/src/example.erl
trackler-2.2.1.161 tracks/erlang/exercises/meetup/src/example.erl
trackler-2.2.1.160 tracks/erlang/exercises/meetup/src/example.erl