Sha256: 31b393280a2ee9067f43a89078fed0df302ddd5861ec99bc3191476b12a3ce95

Contents?: true

Size: 835 Bytes

Versions: 84

Compression:

Stored size: 835 Bytes

Contents

-module('clock').

-export([create/2,
  is_equal/2,
  minutes_add/2,
  to_string/1]).

-record(?MODULE, {normalized}).

-define(HOURS_PER_DAY, 24).
-define(MINUTES_PER_HOUR, 60).
-define(MINUTES_PER_DAY, (?HOURS_PER_DAY * ?MINUTES_PER_HOUR)).


create(Hour, Minutes) ->
  #?MODULE{normalized = mod(Hour * ?MINUTES_PER_HOUR + Minutes, ?MINUTES_PER_DAY)}.

is_equal(C, C) ->
  true;
is_equal(_, _) ->
  false.

minutes_add(#?MODULE{normalized = Mins}, Minutes) ->
  TotalMinutes = mod(Mins + Minutes, ?MINUTES_PER_DAY),
  #?MODULE{normalized = TotalMinutes}.

to_string(#?MODULE{normalized = Mins}) ->
  Hour = Mins div ?MINUTES_PER_HOUR,
  Minutes = Mins rem ?MINUTES_PER_HOUR,
  lists:flatten(io_lib:format("~2.10.0b:~2.10.0b", [Hour, Minutes])).

mod(X, Y) when X > 0 -> X rem Y;
mod(X, Y) when X < 0 -> Y + X rem Y;
mod(0, _Y) -> 0.

Version data entries

84 entries across 84 versions & 1 rubygems

Version Path
trackler-2.0.6.28 tracks/erlang/exercises/clock/example.erl
trackler-2.0.6.27 tracks/erlang/exercises/clock/example.erl
trackler-2.0.6.26 tracks/erlang/exercises/clock/example.erl
trackler-2.0.6.25 tracks/erlang/exercises/clock/example.erl
trackler-2.0.6.24 tracks/erlang/exercises/clock/example.erl
trackler-2.0.6.23 tracks/erlang/exercises/clock/example.erl
trackler-2.0.6.22 tracks/erlang/exercises/clock/example.erl
trackler-2.0.6.21 tracks/erlang/exercises/clock/example.erl
trackler-2.0.6.20 tracks/erlang/exercises/clock/example.erl
trackler-2.0.6.19 tracks/erlang/exercises/clock/example.erl
trackler-2.0.6.18 tracks/erlang/exercises/clock/example.erl
trackler-2.0.6.17 tracks/erlang/exercises/clock/example.erl
trackler-2.0.6.16 tracks/erlang/exercises/clock/example.erl
trackler-2.0.6.15 tracks/erlang/exercises/clock/example.erl
trackler-2.0.6.14 tracks/erlang/exercises/clock/example.erl
trackler-2.0.6.13 tracks/erlang/exercises/clock/example.erl
trackler-2.0.6.12 tracks/erlang/exercises/clock/example.erl
trackler-2.0.6.11 tracks/erlang/exercises/clock/example.erl
trackler-2.0.6.10 tracks/erlang/exercises/clock/example.erl
trackler-2.0.6.9 tracks/erlang/exercises/clock/example.erl