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

Add integer => date_time caster #22

Merged
merged 1 commit into from
Sep 21, 2023
Merged

Conversation

solnic
Copy link
Owner

@solnic solnic commented Sep 21, 2023

Using the default :second unit:

defmodule TestContract do
  use Drops.Contract
  
  schema do
    %{required(:test) => from(:integer) |> type(:date_time)}
  end
end

TestContract.conform(%{test: 1695277470})
# {:ok, %{test: ~U[2023-09-21 06:24:30Z]}}

Providing time unit as an argument for the casting function:

defmodule TestContract do
  use Drops.Contract
  
  schema do
    %{required(:test) => from(:integer, [:millisecond]) |> type(:date_time)}
  end
end

TestContract.conform(%{test: 1695277723355})
# {:ok, %{test: ~U[2023-09-21 06:28:43.355Z]}}

Closes #10

@solnic solnic linked an issue Sep 21, 2023 that may be closed by this pull request
@solnic solnic added this to the v0.1.0 milestone Sep 21, 2023
@solnic solnic added the feature label Sep 21, 2023
@solnic solnic marked this pull request as ready for review September 21, 2023 06:53
@solnic solnic merged commit 68987d1 into main Sep 21, 2023
1 check passed
@solnic solnic deleted the 10-support-for-datetime-coercions branch September 21, 2023 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Support for DateTime coercions
1 participant