Revision 836ccf52
b/src/Ganeti/THH.hs | ||
---|---|---|
49 | 49 |
, Field (..) |
50 | 50 |
, simpleField |
51 | 51 |
, specialNumericalField |
52 |
, timeAsDoubleField |
|
52 | 53 |
, withDoc |
53 | 54 |
, defaultField |
54 | 55 |
, optionalField |
... | ... | |
78 | 79 |
import Data.Maybe |
79 | 80 |
import qualified Data.Set as Set |
80 | 81 |
import Language.Haskell.TH |
82 |
import System.Time (ClockTime(..)) |
|
81 | 83 |
|
82 | 84 |
import qualified Text.JSON as JSON |
83 | 85 |
import Text.JSON.Pretty (pp_value) |
... | ... | |
220 | 222 |
specialNumericalField f field = |
221 | 223 |
field { fieldRead = Just (appE (varE 'numericalReadFn) (varE f)) } |
222 | 224 |
|
225 |
-- | Creates a new mandatory field that reads time as the (floating point) |
|
226 |
-- number of seconds since the standard UNIX epoch, and represents it in |
|
227 |
-- Haskell as 'ClockTime'. |
|
228 |
timeAsDoubleField :: String -> Field |
|
229 |
timeAsDoubleField fname = |
|
230 |
(simpleField fname [t| ClockTime |]) |
|
231 |
{ fieldRead = Just $ [| \_ -> liftM unTimeAsDoubleJSON . JSON.readJSON |] |
|
232 |
, fieldShow = Just $ [| \c -> (JSON.showJSON $ TimeAsDoubleJSON c, []) |] |
|
233 |
} |
|
234 |
|
|
223 | 235 |
-- | Sets custom functions on a field. |
224 | 236 |
customField :: Name -- ^ The name of the read function |
225 | 237 |
-> Name -- ^ The name of the show function |
Also available in: Unified diff