Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Elixir date types for start_datetime #230

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/ex_aws/s3.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ defmodule ExAws.S3 do
| {:query_params, [{binary, binary}]}
| {:headers, [{binary, binary}]}
| {:bucket_as_host, boolean}
| {:start_datetime, DateTime.t()}
| {:start_datetime, Calendar.naive_datetime() | :calendar.datetime()}
]

@type presigned_post_opts :: [
Expand Down Expand Up @@ -1322,7 +1322,17 @@ defmodule ExAws.S3 do

false ->
url = url_to_sign(bucket, object, config, virtual_host, bucket_as_host)
datetime = Keyword.get(opts, :start_datetime, :calendar.universal_time())

datetime =
Keyword.get(opts, :start_datetime, NaiveDateTime.utc_now())
|> case do
dt when is_struct(dt, DateTime) or is_struct(dt, NaiveDateTime) ->
NaiveDateTime.to_erl(dt)

# assume :calendar.datetime()
dt ->
dt
end

ExAws.Auth.presigned_url(
http_method,
Expand Down
Loading