Packages

Extensions to gleam/time to work with weekdays, months, and dates

Current section

Files

Jump to
datebook src datebook@month.erl
Raw

src/datebook@month.erl

-module(datebook@month).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/datebook/month.gleam").
-export([last_day/2, next/1, previous/1]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(" Utility functions for `gleam/time`'s `calendar.Month`.\n").
-file("src/datebook/month.gleam", 23).
?DOC(
" Returns the last day of the month in a given year.\n"
"\n"
" # Examples\n"
"\n"
" ```gleam\n"
" last_day(March, 2005)\n"
" // -> 31\n"
" ```\n"
"\n"
" ```gleam\n"
" last_day(February, 2024)\n"
" // -> 29\n"
" ```\n"
" \n"
" ```gleam\n"
" last_day(February, 2025)\n"
" // -> 28\n"
" ```\n"
).
-spec last_day(gleam@time@calendar:month(), integer()) -> integer().
last_day(Month, Year) ->
case Month of
february ->
case gleam@time@calendar:is_leap_year(Year) of
true ->
29;
false ->
28
end;
april ->
30;
june ->
30;
september ->
30;
november ->
30;
january ->
31;
march ->
31;
may ->
31;
july ->
31;
august ->
31;
october ->
31;
december ->
31
end.
-file("src/datebook/month.gleam", 50).
?DOC(
" Returns the next month for a given `Month`.\n"
"\n"
" # Examples\n"
"\n"
" ```gleam\n"
" next(March)\n"
" // -> April\n"
" ```\n"
).
-spec next(gleam@time@calendar:month()) -> gleam@time@calendar:month().
next(Month) ->
case Month of
january ->
february;
february ->
march;
march ->
april;
april ->
may;
may ->
june;
june ->
july;
july ->
august;
august ->
september;
september ->
october;
october ->
november;
november ->
december;
december ->
january
end.
-file("src/datebook/month.gleam", 75).
?DOC(
" Returns the previous month for a given `Month`.\n"
"\n"
" # Examples\n"
"\n"
" ```gleam\n"
" previous(March)\n"
" // -> February\n"
" ```\n"
).
-spec previous(gleam@time@calendar:month()) -> gleam@time@calendar:month().
previous(Month) ->
case Month of
january ->
december;
february ->
january;
march ->
february;
april ->
march;
may ->
april;
june ->
may;
july ->
june;
august ->
july;
september ->
august;
october ->
september;
november ->
october;
december ->
november
end.