diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cowboy_clock.erl | 26 | ||||
-rw-r--r-- | src/cowboy_cookies.erl | 7 | ||||
-rw-r--r-- | src/cowboy_http_rest.erl | 4 |
3 files changed, 11 insertions, 26 deletions
diff --git a/src/cowboy_clock.erl b/src/cowboy_clock.erl index 3597bdd..c699f4f 100644 --- a/src/cowboy_clock.erl +++ b/src/cowboy_clock.erl @@ -25,23 +25,8 @@ -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). %% gen_server. -%% @todo Use calendar types whenever they get exported. --type year() :: non_neg_integer(). --type month() :: 1..12. --type day() :: 1..31. --type hour() :: 0..23. --type minute() :: 0..59. --type second() :: 0..59. --type daynum() :: 1..7. - --type date() :: {year(), month(), day()}. --type time() :: {hour(), minute(), second()}. - --type datetime() :: {date(), time()}. --export_type([date/0, time/0, datetime/0]). - -record(state, { - universaltime = undefined :: undefined | datetime(), + universaltime = undefined :: undefined | calendar:datetime(), rfc1123 = <<>> :: binary(), tref = undefined :: undefined | timer:tref() }). @@ -74,7 +59,7 @@ rfc1123() -> %% %% This format is used in the <em>'Set-Cookie'</em> header sent with %% HTTP responses. --spec rfc2109(datetime()) -> binary(). +-spec rfc2109(calendar:datetime()) -> binary(). rfc2109(LocalTime) -> {{YYYY,MM,DD},{Hour,Min,Sec}} = case calendar:local_time_to_universal_time_dst(LocalTime) of @@ -145,7 +130,8 @@ code_change(_OldVsn, State, _Extra) -> %% Internal. --spec update_rfc1123(binary(), undefined | datetime(), datetime()) -> binary(). +-spec update_rfc1123(binary(), undefined | calendar:datetime(), + calendar:datetime()) -> binary(). update_rfc1123(Bin, Now, Now) -> Bin; update_rfc1123(<< Keep:23/binary, _/bits >>, @@ -184,7 +170,7 @@ pad_int(X) when X < 10 -> pad_int(X) -> list_to_binary(integer_to_list(X)). --spec weekday(daynum()) -> <<_:24>>. +-spec weekday(1..7) -> <<_:24>>. weekday(1) -> <<"Mon">>; weekday(2) -> <<"Tue">>; weekday(3) -> <<"Wed">>; @@ -193,7 +179,7 @@ weekday(5) -> <<"Fri">>; weekday(6) -> <<"Sat">>; weekday(7) -> <<"Sun">>. --spec month(month()) -> <<_:24>>. +-spec month(1..12) -> <<_:24>>. month( 1) -> <<"Jan">>; month( 2) -> <<"Feb">>; month( 3) -> <<"Mar">>; diff --git a/src/cowboy_cookies.erl b/src/cowboy_cookies.erl index 9c6c4c3..6818a86 100644 --- a/src/cowboy_cookies.erl +++ b/src/cowboy_cookies.erl @@ -23,7 +23,7 @@ -type kv() :: {Name::binary(), Value::binary()}. -type kvlist() :: [kv()]. -type cookie_option() :: {max_age, integer()} - | {local_time, {cowboy_clock:date(), cowboy_clock:time()}} + | {local_time, calendar:datetime()} | {domain, binary()} | {path, binary()} | {secure, true | false} | {http_only, true | false}. -export_type([kv/0, kvlist/0, cookie_option/0]). @@ -171,13 +171,12 @@ quote(V0) -> V end. --spec add_seconds(integer(), cowboy_clock:datetime()) - -> cowboy_clock:datetime(). +-spec add_seconds(integer(), calendar:datetime()) -> calendar:datetime(). add_seconds(Secs, LocalTime) -> Greg = calendar:datetime_to_gregorian_seconds(LocalTime), calendar:gregorian_seconds_to_datetime(Greg + Secs). --spec age_to_cookie_date(integer(), cowboy_clock:datetime()) -> binary(). +-spec age_to_cookie_date(integer(), calendar:datetime()) -> binary(). age_to_cookie_date(Age, LocalTime) -> cowboy_clock:rfc2109(add_seconds(Age, LocalTime)). diff --git a/src/cowboy_http_rest.erl b/src/cowboy_http_rest.erl index 60fd762..e825a98 100644 --- a/src/cowboy_http_rest.erl +++ b/src/cowboy_http_rest.erl @@ -42,8 +42,8 @@ %% Cached resource calls. etag :: undefined | no_call | binary(), - last_modified :: undefined | no_call | cowboy_clock:datetime(), - expires :: undefined | no_call | cowboy_clock:datetime() + last_modified :: undefined | no_call | calendar:datetime(), + expires :: undefined | no_call | calendar:datetime() }). -include("include/http.hrl"). |