Skip to content

Commit 371b666

Browse files
committed
Allow Elixir date types for start_datetime
Allow the presigned_url option "start_datetime" to accept Elixir style dates (DateTime and NaiveDateTime), in addition to the original Erlang style :calendar.datetime().
1 parent 8e2fbd6 commit 371b666

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lib/ex_aws/s3.ex

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ defmodule ExAws.S3 do
5858
| {:query_params, [{binary, binary}]}
5959
| {:headers, [{binary, binary}]}
6060
| {:bucket_as_host, boolean}
61-
| {:start_datetime, DateTime.t()}
61+
| {:start_datetime, Calendar.naive_datetime() | :calendar.datetime()}
6262
]
6363

6464
@type presigned_post_opts :: [
@@ -1322,7 +1322,17 @@ defmodule ExAws.S3 do
13221322

13231323
false ->
13241324
url = url_to_sign(bucket, object, config, virtual_host, bucket_as_host)
1325-
datetime = Keyword.get(opts, :start_datetime, :calendar.universal_time())
1325+
1326+
datetime =
1327+
Keyword.get(opts, :start_datetime, NaiveDateTime.utc_now())
1328+
|> case do
1329+
dt when is_struct(dt, DateTime) or is_struct(dt, NaiveDateTime) ->
1330+
NaiveDateTime.to_erl(dt)
1331+
1332+
# assume :calendar.datetime()
1333+
dt ->
1334+
dt
1335+
end
13261336

13271337
ExAws.Auth.presigned_url(
13281338
http_method,

0 commit comments

Comments
 (0)