2 ( -- * Working with @Day@
10 -- * Working with @UTCTime@
16 -- Working with @DiffTime@
27import Data.Int ( Int32 )
31import Rel8.Expr ( Expr )
32import Rel8.Expr.Function ( binaryOperator, nullaryFunction )
33import Rel8.Expr.Opaleye ( unsafeCastExpr, unsafeLiteral )
36import Data.Time.Calendar ( Day )
37import Data.Time.Clock ( DiffTime, UTCTime )
40-- | Corresponds to @date(now())@.
45-- | Corresponds to calling the @date@ function with a given time.
46toDay :: Expr UTCTime -> Expr Day
50-- | Corresponds to @x::timestamptz@.
51fromDay :: Expr Day -> Expr UTCTime
52fromDay = unsafeCastExpr
55-- | Move forward a given number of days from a particular day.
56addDays :: Expr Int32 -> Expr Day -> Expr Day
57addDays = flip (binaryOperator "+")
60-- | Find the number of days between two days. Corresponds to the @-@ operator.
61diffDays :: Expr Day -> Expr Day -> Expr Int32
62diffDays = binaryOperator "-"
65-- | Subtract a given number of days from a particular 'Day'.
66subtractDays :: Expr Int32 -> Expr Day -> Expr Day
67subtractDays = flip (binaryOperator "-")
70-- | Corresponds to @now()@.
72now = nullaryFunction "now"
75-- | Add a time interval to a point in time, yielding a new point in time.
76addTime :: Expr DiffTime -> Expr UTCTime -> Expr UTCTime
77addTime = flip (binaryOperator "+")
80-- | Find the duration between two times.
81diffTime :: Expr UTCTime -> Expr UTCTime -> Expr DiffTime
82diffTime = binaryOperator "-"
85-- | Subtract a time interval from a point in time, yielding a new point in time.
86subtractTime :: Expr DiffTime -> Expr UTCTime -> Expr UTCTime
87subtractTime = flip (binaryOperator "-")
90scaleInterval :: Expr Double -> Expr DiffTime -> Expr DiffTime
91scaleInterval = binaryOperator "*"
94-- | An interval of one second.
95second :: Expr DiffTime
96second = singleton "second"
99-- | Create a literal interval from an integral number of seconds.
100seconds :: Expr Double -> Expr DiffTime
101seconds = (`scaleInterval` second)
104-- | An interval of one minute.
105minute :: Expr DiffTime
106minute = singleton "minute"
109-- | Create a literal interval from an integral number of minutes.
110minutes :: Expr Double -> Expr DiffTime
111minutes = (`scaleInterval` minute)
114-- | An interval of one hour.
116hour = singleton "hour"
119-- | Create a literal interval from an integral number of hours.
120hours :: Expr Double -> Expr DiffTime
121hours = (`scaleInterval` hour)
124-- | An interval of one day.
129-- | Create a literal interval from a number of days.
130days :: Expr Double -> Expr DiffTime
131days = (`scaleInterval` day)
134-- | An interval of one month.
135month :: Expr DiffTime
136month = singleton "month"
139-- | Create a literal interval from a number of months.
140months :: Expr Double -> Expr DiffTime
141months = (`scaleInterval` month)
144-- | An interval of one year.
146year = singleton "year"
149-- | Create a literal interval from a number of years.
150years :: Expr Double -> Expr DiffTime
151years = (`scaleInterval` year)
154singleton :: String -> Expr DiffTime
155singleton 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