Current section

Files

Jump to
gtempo src tempo@month.erl
Raw

src/tempo@month.erl

-module(tempo@month).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([to_short_string/1, to_long_string/1, from_short_string/1, from_long_string/1, from_string/1, to_int/1, from_int/1, days/2]).
-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(" Functions to use with the `Month` type in Tempo.\n").
-file("src/tempo/month.gleam", 17).
?DOC(
" Returns a month's short name.\n"
" \n"
" ## Example\n"
" \n"
" ```gleam\n"
" date.literal(\"2024-06-13\")\n"
" |> date.get_month\n"
" |> month.to_short_string\n"
" // -> \"Jun\"\n"
" ```\n"
).
-spec to_short_string(gleam@time@calendar:month()) -> binary().
to_short_string(Month) ->
tempo:month_to_short_string(Month).
-file("src/tempo/month.gleam", 31).
?DOC(
" Returns a month's long name.\n"
" \n"
" ## Example\n"
" \n"
" ```gleam\n"
" date.literal(\"2024-06-13\")\n"
" |> date.get_month\n"
" |> month.to_short_string\n"
" // -> \"June\"\n"
" ```\n"
).
-spec to_long_string(gleam@time@calendar:month()) -> binary().
to_long_string(Month) ->
tempo:month_to_long_string(Month).
-file("src/tempo/month.gleam", 71).
?DOC(
" Gets a month from a short month string.\n"
" \n"
" ## Example\n"
" \n"
" ```gleam\n"
" month.from_short_string(\"Jun\")\n"
" // -> Ok(tempo.Jun)\n"
" ```\n"
" \n"
" ```gleam\n"
" month.from_short_string(\"June\")\n"
" // -> Error(Nil)\n"
" ```\n"
).
-spec from_short_string(binary()) -> {ok, gleam@time@calendar:month()} |
{error, nil}.
from_short_string(Month) ->
tempo:month_from_short_string(Month).
-file("src/tempo/month.gleam", 88).
?DOC(
" Gets a month from a long month string.\n"
" \n"
" ## Example\n"
" \n"
" ```gleam\n"
" month.from_long_string(\"June\")\n"
" // -> Ok(tempo.Jun)\n"
" ```\n"
" \n"
" ```gleam\n"
" month.from_long_string(\"Jun\")\n"
" // -> Error(Nil)\n"
" ```\n"
).
-spec from_long_string(binary()) -> {ok, gleam@time@calendar:month()} |
{error, nil}.
from_long_string(Month) ->
tempo:month_from_long_string(Month).
-file("src/tempo/month.gleam", 53).
?DOC(
" Gets a month from a month string.\n"
" \n"
" ## Example\n"
" \n"
" ```gleam\n"
" month.from_string(\"Jun\")\n"
" // -> Ok(tempo.Jun)\n"
" ```\n"
" \n"
" ```gleam\n"
" month.from_string(\"June\")\n"
" // -> Ok(tempo.Jun)\n"
" ```\n"
" \n"
" ```gleam\n"
" month.from_string(\"Hello\")\n"
" // -> Error(Nil)\n"
" ```\n"
).
-spec from_string(binary()) -> {ok, gleam@time@calendar:month()} | {error, nil}.
from_string(Month) ->
_pipe = from_short_string(Month),
gleam@result:try_recover(_pipe, fun(_) -> from_long_string(Month) end).
-file("src/tempo/month.gleam", 102).
?DOC(
" Returns a month's number on the civil calendar.\n"
" \n"
" ## Example\n"
" \n"
" ```gleam\n"
" date.literal(\"2024-06-13\")\n"
" |> date.get_month\n"
" |> month.to_int\n"
" // -> 6\n"
" ```\n"
).
-spec to_int(gleam@time@calendar:month()) -> integer().
to_int(Month) ->
tempo:month_to_int(Month).
-file("src/tempo/month.gleam", 120).
?DOC(
" Gets a month from an integer representing the order of the month on the \n"
" civil calendar.\n"
" \n"
" ## Example\n"
" \n"
" ```gleam\n"
" month.from_int(6)\n"
" // -> Ok(tempo.Jun)\n"
" ```\n"
" \n"
" ```gleam\n"
" month.from_int(13)\n"
" // -> Error(Nil)\n"
" ```\n"
).
-spec from_int(integer()) -> {ok, gleam@time@calendar:month()} | {error, nil}.
from_int(Month) ->
tempo:month_from_int(Month).
-file("src/tempo/month.gleam", 141).
?DOC(
" Returns the number of days in a month.\n"
" \n"
" ## Example\n"
" \n"
" ```gleam\n"
" date.literal(\"2024-06-13\")\n"
" |> date.get_month\n"
" |> month.days\n"
" // -> 30\n"
" ```\n"
" \n"
" ```gleam\n"
" date.literal(\"2024-12-03\")\n"
" |> date.get_month\n"
" |> month.days\n"
" // -> 31\n"
" ```\n"
).
-spec days(gleam@time@calendar:month(), integer()) -> integer().
days(Month, Year) ->
tempo:month_days_of(Month, Year).