assume all datetimes are UTC time and add timezone designator to
generated iso8601 strings
This commit is contained in:
parent
2824e56d44
commit
84f4b7fb40
3 changed files with 6 additions and 4 deletions
|
@ -257,8 +257,7 @@ see below | `datetime()`
|
|||
|
||||
erlang datetime tuples (`{{Year, Month, Day}, {Hour, Min, Sec}}`) as returned
|
||||
from `erlang:localtime/0` are automatically encoded as [iso8601][iso8601]
|
||||
strings. no conversion is attempted of json [iso8601][iso8601] strings in
|
||||
decoded json
|
||||
strings and are assumed to be UTC time. no conversion is attempted of json [iso8601][iso8601] strings in decoded json
|
||||
|
||||
|
||||
### incomplete input ###
|
||||
|
|
|
@ -54,6 +54,9 @@ encode(Term, EntryPoint) -> encode_(Term, EntryPoint).
|
|||
encode_([], _EntryPoint) -> [start_array, end_array];
|
||||
encode_([{}], _EntryPoint) -> [start_object, end_object];
|
||||
|
||||
%% datetime special case
|
||||
encode_([{{_,_,_},{_,_,_}} = DateTime|Rest], EntryPoint) ->
|
||||
[start_array] ++ [DateTime] ++ unhitch(Rest, EntryPoint);
|
||||
encode_([{_, _}|_] = Term, EntryPoint) ->
|
||||
[start_object] ++ unzip(Term, EntryPoint);
|
||||
encode_(Term, EntryPoint) when is_list(Term) ->
|
||||
|
|
|
@ -112,7 +112,7 @@ value([{raw, Raw}|Tokens], Handler, Stack, Config) when is_binary(Raw) ->
|
|||
value([{{Year, Month, Day}, {Hour, Min, Sec}}|Tokens], Handler, Stack, Config)
|
||||
when is_integer(Year), is_integer(Month), is_integer(Day), is_integer(Hour), is_integer(Min), is_integer(Sec) ->
|
||||
value([{string, unicode:characters_to_binary(io_lib:format(
|
||||
"~4.10.0B-~2.10.0B-~2.10.0BT~2.10.0B:~2.10.0B:~2.10.0B",
|
||||
"~4.10.0B-~2.10.0B-~2.10.0BT~2.10.0B:~2.10.0B:~2.10.0BZ",
|
||||
[Year, Month, Day, Hour, Min, Sec]
|
||||
))}|Tokens],
|
||||
Handler,
|
||||
|
@ -1145,7 +1145,7 @@ fix_key_test_() ->
|
|||
datetime_test_() ->
|
||||
[
|
||||
{"datetime", ?_assertEqual(
|
||||
[start_array, {string, <<"2014-08-13T23:12:34">>}, end_array, end_json],
|
||||
[start_array, {string, <<"2014-08-13T23:12:34Z">>}, end_array, end_json],
|
||||
parse([start_array, {{2014,08,13},{23,12,34}}, end_array, end_json], [])
|
||||
)}
|
||||
].
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue