File tree Expand file tree Collapse file tree 3 files changed +27
-3
lines changed
library/Database/PostgreSQL/Simple Expand file tree Collapse file tree 3 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ module Database.PostgreSQL.Simple.Interval
33
44 -- * Construction
55 Unstable. zero ,
6+ Unstable. infinity ,
7+ Unstable. negativeInfinity ,
68 Unstable. fromMicroseconds ,
79 Unstable. fromMilliseconds ,
810 Unstable. fromSeconds ,
Original file line number Diff line number Diff line change @@ -98,6 +98,20 @@ instance Persist.PersistFieldSql Interval where
9898zero :: Interval
9999zero = MkInterval 0 0 0
100100
101+ -- | The biggest possible interval.
102+ --
103+ -- >>> infinity
104+ -- MkInterval {months = 2147483647, days = 2147483647, microseconds = 9223372036854775807}
105+ infinity :: Interval
106+ infinity = MkInterval maxBound maxBound maxBound
107+
108+ -- | The smallest possible interval.
109+ --
110+ -- >>> negativeInfinity
111+ -- MkInterval {months = -2147483648, days = -2147483648, microseconds = -9223372036854775808}
112+ negativeInfinity :: Interval
113+ negativeInfinity = MkInterval minBound minBound minBound
114+
101115-- | Creates an interval from a number of microseconds.
102116--
103117-- >>> fromMicroseconds 1
@@ -605,9 +619,9 @@ parseInfinities =
605619 -- `infinity` is new as of PostgreSQL 17.0.
606620 -- https://www.postgresql.org/message-id/E1r2rB1-005PHm-UL%40gemulon.postgresql.org
607621 A. choice
608- [ MkInterval minBound minBound minBound <$ " -infinity" ,
609- MkInterval maxBound maxBound maxBound <$ " +infinity" ,
610- MkInterval maxBound maxBound maxBound <$ " infinity"
622+ [ negativeInfinity <$ " -infinity" ,
623+ infinity <$ " +infinity" ,
624+ infinity <$ " infinity"
611625 ]
612626
613627parseIso8601 :: A. Parser [Component ]
Original file line number Diff line number Diff line change @@ -28,6 +28,14 @@ spec = H.describe "Database.PostgreSQL.Simple.Interval" $ do
2828 H. it " works" $ do
2929 I. zero `H.shouldBe` I. MkInterval 0 0 0
3030
31+ H. describe " infinity" $ do
32+ H. it " works" $ do
33+ I. infinity `H.shouldBe` I. MkInterval maxBound maxBound maxBound
34+
35+ H. describe " negativeInfinity" $ do
36+ H. it " works" $ do
37+ I. negativeInfinity `H.shouldBe` I. MkInterval minBound minBound minBound
38+
3139 H. describe " add" $ do
3240 H. it " succeeds with no overflow" $ do
3341 let actual = I. add (I. MkInterval 1 2 3 ) (I. MkInterval 4 5 6 )
You can’t perform that action at this time.
0 commit comments