diff --git a/lib/postgrex/extensions/date.ex b/lib/postgrex/extensions/date.ex index 8cd91c4b..e71bc29f 100644 --- a/lib/postgrex/extensions/date.ex +++ b/lib/postgrex/extensions/date.ex @@ -4,11 +4,6 @@ defmodule Postgrex.Extensions.Date do use Postgrex.BinaryExtension, send: "date_send" @gd_epoch Date.to_gregorian_days(~D[2000-01-01]) - @max_year 9999 - - # Latest date supported by Elixir. Postgresql - # supports later dates. - @max_days Date.to_gregorian_days(~D[9999-12-31]) # Elixir supports earlier dates but this is the # earliest supported in Postgresql. @@ -33,23 +28,18 @@ defmodule Postgrex.Extensions.Date do ## Helpers - def encode_elixir(%Date{year: year} = date) when year <= @max_year do + def encode_elixir(date) do <<4::int32(), Date.to_gregorian_days(date) - @gd_epoch::int32()>> end - def encode_elixir(%Date{} = date) do - raise ArgumentError, "#{inspect(date)} is beyond the maximum year #{@max_year}" - end - def day_to_elixir(days) do days = days + @gd_epoch - if days in @min_days..@max_days do + if days > @min_days do Date.from_gregorian_days(days) else raise ArgumentError, - "Postgrex can only decode dates with days between #{@min_days} and #{@max_days}, " <> - "got: #{inspect(days)}" + "Postgrex can only decode dates with days after #{@min_days}, got: #{inspect(days)}" end end end diff --git a/test/calendar_test.exs b/test/calendar_test.exs index 274c3363..2be2b6fe 100644 --- a/test/calendar_test.exs +++ b/test/calendar_test.exs @@ -74,12 +74,6 @@ defmodule CalendarTest do assert [[~D[-0001-01-01]]] = query("SELECT date 'January 1, 2 BC'", []) end - test "decode date upper bound error", context do - assert_raise ArgumentError, fn -> - query("SELECT date '10000-01-01'", []) - end - end - test "decode timestamp", context do assert [[~N[2001-01-01 00:00:00.000000]]] = query("SELECT timestamp '2001-01-01 00:00:00'", [])