%% Duration string parser

duration <- duration_segment+ `lists:sum(Node)`;

duration_segment <- (float / integer) unit `
    [Amount, Span] = Node,
    {Span, Multiplier} = lists:keyfind(Span, 1, ?MULTIPLIERS),
    Amount * Multiplier
`;

integer <- [1-9] [0-9]* `list_to_integer(?FLATTEN(Node))`;

unit <- "f" / "w" / "d" / "h" / "ms" / "m" / "s"  `binary_to_atom(Node, utf8)`;

float <- ( [0-9]+ "." [0-9]+ ) / ( "." [0-9]+ ) `
   case Node of 
       [<<".">>, Mantissa] ->
           list_to_float(?FLATTEN(["0.", Mantissa]));
       _ ->
           list_to_float(?FLATTEN(Node))
   end
`;

`

%% -------------------------------------------------------------------
%%
%% cuttlefish_duration_parse: parses duration strings
%%
%% Copyright (c) 2014 Basho Technologies, Inc.  All Rights Reserved.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License.  You may obtain
%% a copy of the License at
%%
%%   http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied.  See the License for the
%% specific language governing permissions and limitations
%% under the License.
%%
%% -------------------------------------------------------------------

-include("cuttlefish_duration.hrl").

-define(FLATTEN(S), binary_to_list(iolist_to_binary(S))).
`
