Skip to content

Commit

Permalink
migrate to explicit exported types
Browse files Browse the repository at this point in the history
  • Loading branch information
ericbmerritt authored and tsloughter committed Oct 16, 2010
1 parent b413c25 commit 4c771ba
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 29 deletions.
2 changes: 1 addition & 1 deletion ebin/erlcron.app
Expand Up @@ -5,7 +5,7 @@
[{description,
"Erlang Implementation of cron"},

{vsn, "0.1"},
{vsn, "0.2"},

{modules,
[erlcron,
Expand Down
19 changes: 0 additions & 19 deletions include/erlcron.hrl

This file was deleted.

15 changes: 7 additions & 8 deletions src/ecrn_agent.erl
Expand Up @@ -20,7 +20,6 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).

-include_lib("erlcron/include/erlcron.hrl").
-include("erlcron-internal.hrl").

-record(state, {job,
Expand All @@ -42,19 +41,19 @@
%% Starts the server with the apropriate job and the appropriate ref
%% @end
%%--------------------------------------------------------------------
-spec start_link(job_ref(), job()) -> ok.
-spec start_link(erlcron:job_ref(), erlcron:job()) -> ok.
start_link(JobRef, Job) ->
gen_server:start_link(?MODULE, [JobRef, Job], []).

-spec get_datetime(pid()) -> datetime().
-spec get_datetime(pid()) -> erlcron:datetime().
get_datetime(Pid) ->
gen_server:call(Pid, get_datetime).

-spec cancel(pid()) -> ok.
cancel(Pid) ->
gen_server:cast(Pid, shutdown).

-spec set_datetime(pid(), datetime(), datetime()) -> ok.
-spec set_datetime(pid(), erlcron:datetime(), erlcron:datetime()) -> ok.
set_datetime(Pid, DateTime, Actual) ->
gen_server:cast(Pid, {set_datetime, DateTime, Actual}).

Expand All @@ -67,7 +66,7 @@ recalculate(Pid) ->
%% Validate that a run_when spec specified is correct.
%% @end
%%--------------------------------------------------------------------
-spec validate(run_when()) -> valid | invalid.
-spec validate(erlcron:run_when()) -> valid | invalid.
validate(Spec) ->
State = #state{job=undefined,
alarm_ref=undefined},
Expand Down Expand Up @@ -226,7 +225,7 @@ do_job_run(State, {_, {M, F, A}}) when is_record(State, state) ->
proc_lib:spawn(M, F, A).

%% @doc Returns the current time, in seconds past midnight.
-spec current_time(record(state)) -> seconds().
-spec current_time(record(state)) -> erlcron:seconds().
current_time(State) ->
{_, {H,M,S}} = current_date(State),
S + M * 60 + H * 3600.
Expand All @@ -242,7 +241,7 @@ current_date(State) ->

%% @doc Calculates the duration in milliseconds until the next time
%% a job is to be run.
-spec until_next_milliseconds(record(state), job()) -> seconds().
-spec until_next_milliseconds(record(state), erlcron:job()) -> erlcron:seconds().
until_next_milliseconds(State, Job) ->
try
Millis = until_next_time(State, Job) * ?MILLISECONDS,
Expand All @@ -263,7 +262,7 @@ normalize_seconds(State, Seconds) ->

%% @doc Calculates the duration in seconds until the next time
%% a job is to be run.
-spec until_next_time(record(state), job()) -> seconds().
-spec until_next_time(record(state), erlcron:job()) -> erlcron:seconds().
until_next_time(_State, {{once, Seconds}, _What}) when is_integer(Seconds) ->
Seconds;
until_next_time(State, {{once, {H, M, S}}, _What})
Expand Down
36 changes: 35 additions & 1 deletion src/erlcron.erl
Expand Up @@ -14,7 +14,41 @@
multi_set_datetime/1,
multi_set_datetime/2]).

-include_lib("erlcron/include/erlcron.hrl").
-export_type([job/0,
job_ref/0,
run_when/0,
callable/0,
dow/0,
dom/0,
period/0,
duration/0,
constraint/0,
cron_time/0,
datetime/0,
time/0,
date/0,
seconds/0]).

-type seconds() :: integer().
-type date() :: {integer(), integer(), integer()}.
-type time() :: {integer(), integer(), integer()}.
-type datetime() :: {date(), time()}.

-type cron_time() :: {integer(), am | pm} | {integer(), integer(), am | pm}.
-type constraint() :: {between, cron_time(), cron_time()}.
-type duration() :: {integer(), hr | min | sec}.
-type period() :: cron_time() | [cron_time()] | {every, duration(), constraint()}.
-type dom() :: integer().
-type dow() :: mon | tue | wed | thu | fri | sat | sun.
-type callable() :: mfa() | function().
-type run_when() :: {once, seconds()}
| {daily, period()}
| {weekly, dow(), period()}
| {monthly, dom(), period()}.

-type job() :: {run_when(), callable()}.
-opaque job_ref() :: {integer(), reference()}.


%%%===================================================================
%%% API
Expand Down

0 comments on commit 4c771ba

Please sign in to comment.