Current section

Files

Jump to
gtempo src tempo@year.erl
Raw

src/tempo@year.erl

-module(tempo@year).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/tempo/year.gleam").
-export([is_leap_year/1, days/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(
" Functions to use with years in Tempo. Years are pretty simple thankfully.\n"
"\n"
" All functions in this module interpret years as\n"
" [proleptic Gregorian calendar](https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar)\n"
" years, meaning the Gregorian rules are applied to every year including\n"
" those before the calendar's 1582 adoption. They accept any year value, not\n"
" just the 1000 to 9999 range that the `tempo/date` constructors are limited\n"
" to.\n"
).
-file("src/tempo/year.gleam", 39).
?DOC(
" Checks if a year is a leap year, according to the proleptic Gregorian\n"
" calendar: a year is a leap year when it is divisible by 4, except for\n"
" century years, which must be divisible by 400.\n"
"\n"
" Any year value is accepted, including years before the Gregorian calendar\n"
" was adopted in 1582, for which the Gregorian rules are applied anyway.\n"
" This is not a historical claim about the Julian calendar those years were\n"
" actually recorded in, where every fourth year was a leap year with no\n"
" century exception.\n"
"\n"
" ## Examples\n"
"\n"
" ```gleam\n"
" year.is_leap_year(2024)\n"
" // -> True\n"
" ```\n"
"\n"
" ```gleam\n"
" year.is_leap_year(2025)\n"
" // -> False\n"
" ```\n"
"\n"
" ```gleam\n"
" // A century year not divisible by 400 is not a leap year\n"
" year.is_leap_year(1900)\n"
" // -> False\n"
" ```\n"
).
-spec is_leap_year(integer()) -> boolean().
is_leap_year(Year) ->
tempo:is_leap_year(Year).
-file("src/tempo/year.gleam", 61).
?DOC(
" Get the number of days in a proleptic Gregorian calendar year, so always\n"
" 365 or 366. Accounts for leap years using the Gregorian rules described in\n"
" `is_leap_year`.\n"
"\n"
" Any year value is accepted, not just the 1000 to 9999 range that the\n"
" `tempo/date` constructors are limited to.\n"
"\n"
" ## Examples\n"
"\n"
" ```gleam\n"
" year.days(2024)\n"
" // -> 366\n"
" ```\n"
"\n"
" ```gleam\n"
" year.days(2025)\n"
" // -> 365\n"
" ```\n"
).
-spec days(integer()) -> integer().
days(Year) ->
tempo:year_days(Year).