2 ( -- * Working with @Day@
10 -- * Working with @UTCTime@
16 -- * Working with @DiffTime@
28import Data.Int ( Int32 )
32import Rel8.Expr ( Expr )
33import Rel8.Expr.Function ( binaryOperator, nullaryFunction )
34import Rel8.Expr.Opaleye ( unsafeCastExpr, unsafeLiteral )
37import Data.Time.Calendar ( Day )
38import Data.Time.Clock ( DiffTime, UTCTime )
41-- | Corresponds to @date(now())@.
46-- | Corresponds to calling the @date@ function with a given time.
47toDay :: Expr UTCTime -> Expr Day
51-- | Corresponds to @x::timestamptz@.
52fromDay :: Expr Day -> Expr UTCTime
53fromDay = unsafeCastExpr
56-- | Move forward a given number of days from a particular day.
57addDays :: Expr Int32 -> Expr Day -> Expr Day
58addDays = flip (binaryOperator "+")
61-- | Find the number of days between two days. Corresponds to the @-@ operator.
62diffDays :: Expr Day -> Expr Day -> Expr Int32
63diffDays = binaryOperator "-"
66-- | Subtract a given number of days from a particular 'Day'.
67subtractDays :: Expr Int32 -> Expr Day -> Expr Day
68subtractDays = flip (binaryOperator "-")
71-- | Corresponds to @now()@.
73now = nullaryFunction "now"
76-- | Add a time interval to a point in time, yielding a new point in time.
77addTime :: Expr DiffTime -> Expr UTCTime -> Expr UTCTime
78addTime = flip (binaryOperator "+")
81-- | Find the duration between two times.
82diffTime :: Expr UTCTime -> Expr UTCTime -> Expr DiffTime
83diffTime = binaryOperator "-"
86-- | Subtract a time interval from a point in time, yielding a new point in time.
87subtractTime :: Expr DiffTime -> Expr UTCTime -> Expr UTCTime
88subtractTime = flip (binaryOperator "-")
91scaleInterval :: Expr Double -> Expr DiffTime -> Expr DiffTime
92scaleInterval = binaryOperator "*"
95-- | An interval of one second.
96second :: Expr DiffTime
97second = singleton "second"
100-- | Create a literal interval from a number of seconds.
101seconds :: Expr Double -> Expr DiffTime
102seconds = (`scaleInterval` second)
105-- | An interval of one minute.
106minute :: Expr DiffTime
107minute = singleton "minute"
110-- | Create a literal interval from a number of minutes.
111minutes :: Expr Double -> Expr DiffTime
112minutes = (`scaleInterval` minute)
115-- | An interval of one hour.
117hour = singleton "hour"
120-- | Create a literal interval from a number of hours.
121hours :: Expr Double -> Expr DiffTime
122hours = (`scaleInterval` hour)
125-- | An interval of one day.
130-- | Create a literal interval from a number of days.
131days :: Expr Double -> Expr DiffTime
132days = (`scaleInterval` day)
135-- | An interval of one week.
137week = singleton "week"
140-- | Create a literal interval from a number of weeks.
141weeks :: Expr Double -> Expr DiffTime
142weeks = (`scaleInterval` week)
145-- | An interval of one month.
146month :: Expr DiffTime
147month = singleton "month"
150-- | Create a literal interval from a number of months.
151months :: Expr Double -> Expr DiffTime
152months = (`scaleInterval` month)
155-- | An interval of one year.
157year = singleton "year"
160-- | Create a literal interval from a number of years.
161years :: Expr Double -> Expr DiffTime
162years = (`scaleInterval` year)
165singleton :: String -> Expr DiffTime
166singleton unit = unsafeLiteral $ "'1 " ++ unit ++ "'"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list