Time-stamp generating function in Erlang (Required input parameters are Start Time-stamp, Times to shift the time)
-module(random_time_genarator).
-export([start/2]).
start(Times,StartDate) ->
generating_records(Times,StartDate).
generating_records(Times,StartDate) ->
Accept_time=generate_timestamp(StartDate,Times),
Accept_time.
generate_timestamp(Timestamp,Times) ->
{{Y,Mo,D},{H,Mi,S}}=Timestamp,
second_genaration(Y,Mo,D,H,Mi,S,Times,Times).
second_genaration(Y,Mo,D,H,Mi,S,Times,Counter) ->
timer:sleep(3),
if
S <59 , Counter>0 ->
second_genaration(Y,Mo,D,H,Mi,S+1,Times,Counter-1);
true ->
minute_genaration(Y,Mo,D,H,Mi,S,Times,Counter)
end.
minute_genaration(Y,Mo,D,H,Mi,S,Times,Counter) ->
if
Mi<59 , Counter>0 ->
second_genaration(Y,Mo,D,H,Mi+1,0,Times,Counter);
true ->
hour_genaration(Y,Mo,D,H,Mi,S,Times,Counter)
end.
hour_genaration(Y,Mo,D,H,Mi,S,Times,Counter) ->
if
H <23 , Counter>0->
minute_genaration(Y,Mo,D,H+1,0,S,Times,Counter);
true ->
day_genaration(Y,Mo,D,H,Mi,S,Times,Counter)
end.
day_genaration(Y,Mo,D,H,Mi,S,Times,Counter) ->
if
D<30 , Counter>0->
hour_genaration(Y,Mo,D+1,0,Mi,S,Times,Counter);
true ->
{{Y,Mo,D},{H,Mi,S}}
end.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home