diff --git a/test/calculation_test.exs b/test/calculation_test.exs index c38e1847..99cd6be5 100644 --- a/test/calculation_test.exs +++ b/test/calculation_test.exs @@ -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 diff --git a/test/support/resources/post.ex b/test/support/resources/post.ex index e945ac86..5a08ab26 100644 --- a/test/support/resources/post.ex +++ b/test/support/resources/post.ex @@ -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