Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Begin a parser for ISO8601 dates.

  • Loading branch information...
commit 9f788e008385657d886d51d7579b928c51200437 1 parent 7638115
@jlouis authored
Showing with 51 additions and 0 deletions.
  1. +1 −0  ebin/webstuff.app
  2. +50 −0 src/inet_time.erl
View
1  ebin/webstuff.app
@@ -9,4 +9,5 @@
{modules,
[odata,odata_app,odata_sup,
atom,
+ inet_time,
uri,iri]}]}.
View
50 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.
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.