Skip to content

Commit

Permalink
Merge pull request #11 from tsloughter/master
Browse files Browse the repository at this point in the history
support decimal seconds
  • Loading branch information
seansawyer committed Aug 26, 2014
2 parents 132c440 + 504f377 commit 3f4f689
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/iso8601.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-type maybe(A) :: undefined | A.
-type timestamp() :: tuple(MegaSecs::integer(),
Secs::integer(),
MicroSecs::integer()).
MicroSecs::integer() | float()).

%% API

Expand All @@ -31,6 +31,10 @@ add_time(Datetime, H, M, S) ->
%% returns a string with no offset (i.e., ending in "Z").
format({_,_,_}=Timestamp) ->
format(calendar:now_to_datetime(Timestamp));
format({{Y,Mo,D}, {H,Mn,S}}) when is_float(S) ->
FmtStr = "~4.10.0B-~2.10.0B-~2.10.0BT~2.10.0B:~2.10.0B:~9.6.0fZ",
IsoStr = io_lib:format(FmtStr, [Y, Mo, D, H, Mn, S]),
list_to_binary(IsoStr);
format({{Y,Mo,D}, {H,Mn,S}}) ->
FmtStr = "~4.10.0B-~2.10.0B-~2.10.0BT~2.10.0B:~2.10.0B:~2.10.0BZ",
IsoStr = io_lib:format(FmtStr, [Y, Mo, D, H, Mn, S]),
Expand Down

0 comments on commit 3f4f689

Please sign in to comment.