Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Provide a simple unparser function.

This function only has partial support for the full date specification
as we have no fractional parts in there yet. Should be easy to add
though.
  • Loading branch information...
commit dcd80ba68ddaa7ab2195fbadf0a58d47d9b07798 1 parent e484134
@jlouis authored
Showing with 16 additions and 1 deletion.
  1. +16 −1 src/inet_time.erl
View
17 src/inet_time.erl
@@ -8,7 +8,8 @@
-module(inet_time).
%% API
--export([parse/1]).
+-export([parse/1,
+ to_string/2, to_string/3]).
%%====================================================================
%% API
@@ -39,6 +40,20 @@ parse(String) ->
{error, {invalid_date, {Date, Time, Offset}}}
end.
+to_string(Date, Time) ->
+ to_string(Date, Time, 'Z').
+
+to_string({Year, Month, Day}, {Hour, Minute, Second}, Offset) ->
+ OffStr = case Offset of
+ 'Z' -> "Z";
+ {Dir, H, M} ->
+ io_lib:format("~s~2.10.0B:~2.10.0B",
+ [case Dir of '+' -> "+"; '-' -> "-" end,
+ H, M])
+ end,
+ io_lib:format("~4.10.0B-~2.10.0B-~2.10.0BT~2.10.0B:~2.10.0B:~2.10.0B~s",
+ [Year, Month, Day, Hour, Minute, Second, OffStr]).
+
%%====================================================================
%% Internal functions
%%====================================================================
Please sign in to comment.
Something went wrong with that request. Please try again.