Skip to content

Commit

Permalink
Begin a parser for ISO8601 dates.
Browse files Browse the repository at this point in the history
  • Loading branch information
jlouis committed Oct 19, 2010
1 parent 7638115 commit 9f788e0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions ebin/webstuff.app
Expand Up @@ -9,4 +9,5 @@
{modules,
[odata,odata_app,odata_sup,
atom,
inet_time,
uri,iri]}]}.
50 changes: 50 additions & 0 deletions src/inet_time.erl
@@ -0,0 +1,50 @@
%%%-------------------------------------------------------------------
%%% File : inet_time.erl
%%% Author : Jesper Louis Andersen <jesper.louis.andersen@gmail.com>
%%% Description : "Internet Time", RFC 3339
%%%
%%% Created : 19 Oct 2010 by Jesper Louis Andersen <jesper.louis.andersen@gmail.com>
%%%-------------------------------------------------------------------
-module(inet_time).

%% API
-export([parse/1]).

%%====================================================================
%% API
%%====================================================================
parse(String) ->
try parse_iso_date_time(String) of
{Ast, []} -> {ok, Ast};
{Ast, NoFull} -> {error, {spurious_trailing_chars, Ast, NoFull}}
catch
{no_parse, Reason} ->
{error, Reason}
end.



%%====================================================================
%% Internal functions
%%====================================================================
parse_iso_date_time(S) ->
{Date, R1} = parse_iso_date(S),
{_, R2} = expect("T", R1),
{Time, []} = parse_iso_time(R2),
{iso_8601, Date, Time}.

parse_iso_date(S) ->
{todo, S}.

parse_iso_time(S) ->
{todo, S}.

expect(Prefix, S) ->
case lists:prefix(Prefix, S) of
true ->
lists:split(length(Prefix), S);
false ->
throw({no_parse, {wrong_prefix, Prefix}})
end.


0 comments on commit 9f788e0

Please sign in to comment.