Skip to content
Open
Show file tree
Hide file tree
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
22 changes: 22 additions & 0 deletions test/calculation_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1647,4 +1647,26 @@ defmodule AshPostgres.CalculationTest do
assert loaded2.last_unread_message_formatted_fn == "FnMessage: Unread message"
assert loaded3.last_unread_message_formatted_fn == nil
end

test "can correctly compare timestamptz, regardless of database timezone" do
post =
Post
|> Ash.Changeset.for_create(:create, %{
title: "match",
price: 10_024,
datetime: DateTime.utc_now()
})
|> Ash.create!()

assert {:ok, %Postgrex.Result{}} =
Ecto.Adapters.SQL.query(
AshPostgres.TestRepo,
"""
set timezone = 'Europe/Copenhagen';
"""
)

assert Ash.calculate!(post, :past_datetime1?)
assert Ash.calculate!(post, :past_datetime2?)
end
end
3 changes: 3 additions & 0 deletions test/support/resources/post.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,9 @@ defmodule AshPostgres.Test.Post do
) do
public?(true)
end

calculate(:past_datetime1?, :boolean, expr(now() > datetime))
calculate(:past_datetime2?, :boolean, expr(datetime <= now()))
end

aggregates do
Expand Down