MSPF-532: fix check for UTC in RFC 3339 date and time (#132)

This commit is contained in:
Sergei Shuvatov 2020-02-18 19:35:33 +03:00 committed by GitHub
parent 3ddd842a33
commit 8b8c0e2779
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -91,9 +91,15 @@ from_unixtime_ms(DeadlineMillisec) ->
-spec assert_is_utc(binary()) ->
ok | no_return().
assert_is_utc(Bin) ->
Size = erlang:byte_size(Bin) - 1,
Size0 = erlang:byte_size(Bin),
Size1 = Size0 - 1,
Size6 = Size0 - 6,
case Bin of
<<_:Size/bytes, "Z">> ->
<<_:Size1/bytes, "Z">> ->
ok;
<<_:Size6/bytes, "+00:00">> ->
ok;
<<_:Size6/bytes, "-00:00">> ->
ok;
_ ->
erlang:error({bad_deadline, not_utc}, [Bin])

View File

@ -621,6 +621,8 @@ deadline_to_from_binary_test(_) ->
error:{bad_deadline, not_utc} ->
ok
end,
_ = woody_deadline:from_binary(<<"2010-04-11T22:35:41+00:00">>),
_ = woody_deadline:from_binary(<<"2010-04-11T22:35:41-00:00">>),
try woody_deadline:to_binary({{baddate, {22, 35, 41}}, 29})
catch