Просмотр исходного кода

Use calendar date and time types exported since R14B04

Removes the cowboy_clock:date/0, time/0 and datetime/0 exported types.
Loïc Hoguin 13 лет назад
Родитель
Сommit
156c84ff29
4 измененных файлов с 16 добавлено и 27 удалено
  1. 5 1
      CHANGELOG.md
  2. 6 20
      src/cowboy_clock.erl
  3. 3 4
      src/cowboy_cookies.erl
  4. 2 2
      src/cowboy_http_rest.erl

+ 5 - 1
CHANGELOG.md

@@ -53,7 +53,11 @@ CHANGELOG
 
     More specifically, /bits was replaced by /binary.
 
-*   Rename the type cowboy_dispatcher:path_tokens/0 to :tokens/0
+*   Rename the type cowboy_dispatcher:path_tokens/0 to tokens/0
+
+*   Remove the cowboy_clock:date/0, time/0 and datetime/0 types
+
+    The calendar module exports those same types properly since R14B04.
 
 *   Add cacertfile configuration option to cowboy_ssl_transport
 

+ 6 - 20
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">>;

+ 3 - 4
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)).
 

+ 2 - 2
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").