| Safe Haskell | None | 
|---|---|
| Language | Haskell2010 | 
Database.PostgreSQL.Simple.Interval.Unstable
Synopsis
- data Interval = MkInterval {}
- zero :: Interval
- fromMicroseconds :: Int64 -> Interval
- fromMilliseconds :: Int64 -> Maybe Interval
- fromSeconds :: Int64 -> Maybe Interval
- fromMinutes :: Int64 -> Maybe Interval
- fromHours :: Int64 -> Maybe Interval
- fromDays :: Int32 -> Interval
- fromWeeks :: Int32 -> Maybe Interval
- fromMonths :: Int32 -> Interval
- fromYears :: Int32 -> Maybe Interval
- add :: Interval -> Interval -> Maybe Interval
- render :: Interval -> Builder
- parse :: Parser Interval
- parseInfinities :: Parser Interval
- parseIso8601 :: Parser [Component]
- parsePostgresVerbose :: Parser [Component]
- parsePostgres :: Parser [Component]
- parseSqlStandard :: Parser [Component]
- parseTime :: Parser [Component]
- parseSign :: Parser ByteString
- maybePlural :: ByteString -> Parser ByteString
- data Component
- fromComponent :: Component -> Maybe Interval
- fromComponents :: (Alternative f, Traversable t) => t Component -> f Interval
- negateComponent :: Component -> Component
- negateComponentsWhen :: Functor f => Bool -> f Component -> f Component
Documentation
This type represents a PostgreSQL interval. Intervals can have month, day, and microsecond components. Each component is bounded, so they are not arbitrary precision. For more information about intervals, consult the PostgreSQL documentation: https://www.postgresql.org/docs/17/datatype-datetime.html#DATATYPE-INTERVAL-INPUT.
Note that the time library provides several duration types that are not
 appropriate to use as PostgreSQL intervals:
- NominalDiffTime: Does not handle days or months. Allows up to picosecond precision. Is not bounded.
- CalendarDiffTime: Does not handle days. Embeds a- NominalDiffTime. Is not bounded.
- CalendarDiffDays: Does not handle seconds. Is not bounded.
Constructors
| MkInterval | |
Instances
| Show Interval Source # | |
| Eq Interval Source # | |
| PersistField Interval Source # | |
| Defined in Database.PostgreSQL.Simple.Interval.Unstable Methods toPersistValue :: Interval -> PersistValue # | |
| PersistFieldSql Interval Source # |  | 
| FromField Interval Source # | Uses  | 
| Defined in Database.PostgreSQL.Simple.Interval.Unstable Methods | |
| ToField Interval Source # | Uses  | 
| Defined in Database.PostgreSQL.Simple.Interval.Unstable | |
The empty interval, representing no time at all.
>>>zeroMkInterval {months = 0, days = 0, microseconds = 0}
fromMicroseconds :: Int64 -> Interval Source #
Creates an interval from a number of microseconds.
>>>fromMicroseconds 1MkInterval {months = 0, days = 0, microseconds = 1}
fromMilliseconds :: Int64 -> Maybe Interval Source #
Creates an interval from a number of milliseconds. Returns Nothing if
 the interval would overflow.
>>>fromMilliseconds 1Just (MkInterval {months = 0, days = 0, microseconds = 1000})>>>fromMilliseconds 9223372036854776Nothing
fromSeconds :: Int64 -> Maybe Interval Source #
Creates an interval from a number of seconds. Returns Nothing if the
 interval would overflow.
>>>fromSeconds 1Just (MkInterval {months = 0, days = 0, microseconds = 1000000})>>>fromSeconds 9223372036855Nothing
fromMinutes :: Int64 -> Maybe Interval Source #
Creates an interval from a number of minutes. Returns Nothing if the
 interval would overflow.
>>>fromMinutes 1Just (MkInterval {months = 0, days = 0, microseconds = 60000000})>>>fromMinutes 153722867281Nothing
fromHours :: Int64 -> Maybe Interval Source #
Creates an interval from a number of hours. Returns Nothing if the
 interval would overflow.
>>>fromHours 1Just (MkInterval {months = 0, days = 0, microseconds = 3600000000})>>>fromHours 2562047789Nothing
fromDays :: Int32 -> Interval Source #
Creates an interval from a number of days.
>>>fromDays 1MkInterval {months = 0, days = 1, microseconds = 0}
fromWeeks :: Int32 -> Maybe Interval Source #
Creates an interval from a number of weeks. Returns Nothing if the
 interval would overflow.
>>>fromWeeks 1Just (MkInterval {months = 0, days = 7, microseconds = 0})>>>fromWeeks 306783379Nothing
fromMonths :: Int32 -> Interval Source #
Creates an interval from a number of months.
>>>fromMonths 1MkInterval {months = 1, days = 0, microseconds = 0}
fromYears :: Int32 -> Maybe Interval Source #
Creates an interval from a number of years. Returns Nothing if the
 interval would overflow.
>>>fromYears 1Just (MkInterval {months = 12, days = 0, microseconds = 0})>>>fromYears 178956971Nothing
add :: Interval -> Interval -> Maybe Interval Source #
Adds two intervals. Returns Nothing if the result would overflow.
>>>add (fromMonths 1) (fromDays 2)Just (MkInterval {months = 1, days = 2, microseconds = 0})>>>add (fromDays 2147483647) (fromDays 1)Nothing
render :: Interval -> Builder Source #
Renders an interval to a Builder. This always has the same format:
 "@ X mon Y day Z us", where X, Y, and Z are signed integers.
This is not the most compact format, but it is very easy to interpret and does not require dealing with decimals (which could introduce precision problems).
>>>render MkInterval { months = 0, days = -1, microseconds = 2 }"@ 0 mon -1 day +2 us"
parse :: Parser Interval Source #
Parses an interval. This is not a general purpose parser. It only supports
 the formats that PostgreSQL generates. For example, it will fail to parse an
 interval like "1 week" because PostgreSQL never uses weeks when rendering
 intervals.
parseIso8601 :: Parser [Component] Source #
parsePostgres :: Parser [Component] Source #
maybePlural :: ByteString -> Parser ByteString Source #
One component of an interval. This is used to retain arbitrary precision for as long as possible before converting. It also shows which components are accepted, like years and months.
Constructors
| Years !Integer | |
| Months !Integer | |
| Days !Integer | |
| Hours !Integer | |
| Minutes !Integer | |
| Seconds !Scientific | |
| Microseconds !Integer | 
fromComponents :: (Alternative f, Traversable t) => t Component -> f Interval Source #
negateComponent :: Component -> Component Source #