module Rel8.Expr.Time
(
today
, toDay
, fromDay
, addDays
, diffDays
, subtractDays
, now
, addTime
, diffTime
, subtractTime
, scaleInterval
, second, seconds
, minute, minutes
, hour, hours
, day, days
, week, weeks
, month, months
, year, years
) where
import Data.Int ( Int32 )
import Prelude
import Rel8.Expr ( Expr )
import Rel8.Expr.Function ( binaryOperator, nullaryFunction )
import Rel8.Expr.Opaleye ( unsafeCastExpr, unsafeLiteral )
import Data.Time.Calendar ( Day )
import Data.Time.Clock ( UTCTime )
import Data.Time.LocalTime ( CalendarDiffTime )
today :: Expr Day
today :: Expr Day
today = Expr UTCTime -> Expr Day
toDay Expr UTCTime
now
toDay :: Expr UTCTime -> Expr Day
toDay :: Expr UTCTime -> Expr Day
toDay = Expr UTCTime -> Expr Day
forall b a. Sql DBType b => Expr a -> Expr b
unsafeCastExpr
fromDay :: Expr Day -> Expr UTCTime
fromDay :: Expr Day -> Expr UTCTime
fromDay = Expr Day -> Expr UTCTime
forall b a. Sql DBType b => Expr a -> Expr b
unsafeCastExpr
addDays :: Expr Int32 -> Expr Day -> Expr Day
addDays :: Expr Int32 -> Expr Day -> Expr Day
addDays = (Expr Day -> Expr Int32 -> Expr Day)
-> Expr Int32 -> Expr Day -> Expr Day
forall a b c. (a -> b -> c) -> b -> a -> c
flip (String -> Expr Day -> Expr Int32 -> Expr Day
forall c a b. Sql DBType c => String -> Expr a -> Expr b -> Expr c
binaryOperator String
"+")
diffDays :: Expr Day -> Expr Day -> Expr Int32
diffDays :: Expr Day -> Expr Day -> Expr Int32
diffDays = String -> Expr Day -> Expr Day -> Expr Int32
forall c a b. Sql DBType c => String -> Expr a -> Expr b -> Expr c
binaryOperator String
"-"
subtractDays :: Expr Int32 -> Expr Day -> Expr Day
subtractDays :: Expr Int32 -> Expr Day -> Expr Day
subtractDays = (Expr Day -> Expr Int32 -> Expr Day)
-> Expr Int32 -> Expr Day -> Expr Day
forall a b c. (a -> b -> c) -> b -> a -> c
flip (String -> Expr Day -> Expr Int32 -> Expr Day
forall c a b. Sql DBType c => String -> Expr a -> Expr b -> Expr c
binaryOperator String
"-")
now :: Expr UTCTime
now :: Expr UTCTime
now = String -> Expr UTCTime
forall a. Sql DBType a => String -> Expr a
nullaryFunction String
"now"
addTime :: Expr CalendarDiffTime -> Expr UTCTime -> Expr UTCTime
addTime :: Expr CalendarDiffTime -> Expr UTCTime -> Expr UTCTime
addTime = (Expr UTCTime -> Expr CalendarDiffTime -> Expr UTCTime)
-> Expr CalendarDiffTime -> Expr UTCTime -> Expr UTCTime
forall a b c. (a -> b -> c) -> b -> a -> c
flip (String -> Expr UTCTime -> Expr CalendarDiffTime -> Expr UTCTime
forall c a b. Sql DBType c => String -> Expr a -> Expr b -> Expr c
binaryOperator String
"+")
diffTime :: Expr UTCTime -> Expr UTCTime -> Expr CalendarDiffTime
diffTime :: Expr UTCTime -> Expr UTCTime -> Expr CalendarDiffTime
diffTime = String -> Expr UTCTime -> Expr UTCTime -> Expr CalendarDiffTime
forall c a b. Sql DBType c => String -> Expr a -> Expr b -> Expr c
binaryOperator String
"-"
subtractTime :: Expr CalendarDiffTime -> Expr UTCTime -> Expr UTCTime
subtractTime :: Expr CalendarDiffTime -> Expr UTCTime -> Expr UTCTime
subtractTime = (Expr UTCTime -> Expr CalendarDiffTime -> Expr UTCTime)
-> Expr CalendarDiffTime -> Expr UTCTime -> Expr UTCTime
forall a b c. (a -> b -> c) -> b -> a -> c
flip (String -> Expr UTCTime -> Expr CalendarDiffTime -> Expr UTCTime
forall c a b. Sql DBType c => String -> Expr a -> Expr b -> Expr c
binaryOperator String
"-")
scaleInterval :: Expr Double -> Expr CalendarDiffTime -> Expr CalendarDiffTime
scaleInterval :: Expr Double -> Expr CalendarDiffTime -> Expr CalendarDiffTime
scaleInterval = String
-> Expr Double -> Expr CalendarDiffTime -> Expr CalendarDiffTime
forall c a b. Sql DBType c => String -> Expr a -> Expr b -> Expr c
binaryOperator String
"*"
second :: Expr CalendarDiffTime
second :: Expr CalendarDiffTime
second = String -> Expr CalendarDiffTime
singleton String
"second"
seconds :: Expr Double -> Expr CalendarDiffTime
seconds :: Expr Double -> Expr CalendarDiffTime
seconds = (Expr Double -> Expr CalendarDiffTime -> Expr CalendarDiffTime
`scaleInterval` Expr CalendarDiffTime
second)
minute :: Expr CalendarDiffTime
minute :: Expr CalendarDiffTime
minute = String -> Expr CalendarDiffTime
singleton String
"minute"
minutes :: Expr Double -> Expr CalendarDiffTime
minutes :: Expr Double -> Expr CalendarDiffTime
minutes = (Expr Double -> Expr CalendarDiffTime -> Expr CalendarDiffTime
`scaleInterval` Expr CalendarDiffTime
minute)
hour :: Expr CalendarDiffTime
hour :: Expr CalendarDiffTime
hour = String -> Expr CalendarDiffTime
singleton String
"hour"
hours :: Expr Double -> Expr CalendarDiffTime
hours :: Expr Double -> Expr CalendarDiffTime
hours = (Expr Double -> Expr CalendarDiffTime -> Expr CalendarDiffTime
`scaleInterval` Expr CalendarDiffTime
hour)
day :: Expr CalendarDiffTime
day :: Expr CalendarDiffTime
day = String -> Expr CalendarDiffTime
singleton String
"day"
days :: Expr Double -> Expr CalendarDiffTime
days :: Expr Double -> Expr CalendarDiffTime
days = (Expr Double -> Expr CalendarDiffTime -> Expr CalendarDiffTime
`scaleInterval` Expr CalendarDiffTime
day)
week :: Expr CalendarDiffTime
week :: Expr CalendarDiffTime
week = String -> Expr CalendarDiffTime
singleton String
"week"
weeks :: Expr Double -> Expr CalendarDiffTime
weeks :: Expr Double -> Expr CalendarDiffTime
weeks = (Expr Double -> Expr CalendarDiffTime -> Expr CalendarDiffTime
`scaleInterval` Expr CalendarDiffTime
week)
month :: Expr CalendarDiffTime
month :: Expr CalendarDiffTime
month = String -> Expr CalendarDiffTime
singleton String
"month"
months :: Expr Double -> Expr CalendarDiffTime
months :: Expr Double -> Expr CalendarDiffTime
months = (Expr Double -> Expr CalendarDiffTime -> Expr CalendarDiffTime
`scaleInterval` Expr CalendarDiffTime
month)
year :: Expr CalendarDiffTime
year :: Expr CalendarDiffTime
year = String -> Expr CalendarDiffTime
singleton String
"year"
years :: Expr Double -> Expr CalendarDiffTime
years :: Expr Double -> Expr CalendarDiffTime
years = (Expr Double -> Expr CalendarDiffTime -> Expr CalendarDiffTime
`scaleInterval` Expr CalendarDiffTime
year)
singleton :: String -> Expr CalendarDiffTime
singleton :: String -> Expr CalendarDiffTime
singleton String
unit = String -> Expr CalendarDiffTime
forall a. Sql DBType a => String -> Expr a
unsafeLiteral (String -> Expr CalendarDiffTime)
-> String -> Expr CalendarDiffTime
forall a b. (a -> b) -> a -> b
$ String
"'1 " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
unit String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"'"