on master help sign in
add DateTime atom constructor function

resolves #104

commit31aa122894c6c6e3e35bae509f49c38f4f039117 authorAgentM <agentm@themactionfaction.com> dateFri 19 May 2017, 09:35 (9 years ago) parent448197c
5 files changed+24−2
project-m36.cabal+1 src/lib/ProjectM36/AtomFunctions/Basic.hs+2 src/lib/ProjectM36/DataTypes/Basic.hs+2−1 src/lib/ProjectM36/DataTypes/DateTime.hs+15 test/TutorialD/Interpreter.hs+4−1
project-m36.cabal+1
@@ -108,6 +108,7 @@ Library
108108 ProjectM36.DataConstructorDef,
109109 ProjectM36.DataTypes.Basic,
110110 ProjectM36.DataTypes.Day,
111+ ProjectM36.DataTypes.DateTime,
111112 ProjectM36.DataTypes.Either,
112113 ProjectM36.DataTypes.Maybe,
113114 ProjectM36.DataTypes.List,
src/lib/ProjectM36/AtomFunctions/Basic.hs+2
@@ -7,11 +7,13 @@ import ProjectM36.DataTypes.Maybe
77import ProjectM36.AtomFunctions.Primitive
88import ProjectM36.AtomFunction
99import ProjectM36.DataTypes.List
10+import ProjectM36.DataTypes.DateTime
1011import qualified Data.HashSet as HS
1112
1213basicAtomFunctions :: AtomFunctions
1314basicAtomFunctions = HS.unions [primitiveAtomFunctions,
1415 dayAtomFunctions,
16+ dateTimeAtomFunctions,
1517 eitherAtomFunctions,
1618 maybeAtomFunctions,
1719 listAtomFunctions]
src/lib/ProjectM36/DataTypes/Basic.hs+2−1
@@ -12,5 +12,6 @@ basicTypeConstructorMapping = (primitiveTypeConstructorMapping ++
1212 maybeTypeConstructorMapping ++
1313 eitherTypeConstructorMapping ++
1414 listTypeConstructorMapping ++
15− dayTypeConstructorMapping)
15+ dayTypeConstructorMapping
16+ )
1617
src/lib/ProjectM36/DataTypes/DateTime.hsnew file+15
@@ -0,0 +1,15 @@
1+module ProjectM36.DataTypes.DateTime where
2+import ProjectM36.Base
3+import ProjectM36.AtomFunctionBody
4+import qualified Data.HashSet as HS
5+import Data.Time.Clock.POSIX
6+import Data.Time.Clock
7+
8+dateTimeAtomFunctions :: AtomFunctions
9+dateTimeAtomFunctions = HS.fromList [ AtomFunction {
10+ atomFuncName = "dateTimeFromEpochSeconds",
11+ atomFuncType = [IntAtomType, DateTimeAtomType],
12+ atomFuncBody = compiledAtomFunctionBody $ \((IntAtom epoch):_) -> pure (DateTimeAtom (posixSecondsToUTCTime (realToFrac epoch)))
13+ }]
14+
15+
test/TutorialD/Interpreter.hs+4−1
@@ -26,6 +26,7 @@ import Control.Concurrent
2626import qualified Data.Set as S
2727import Data.Text hiding (map)
2828import qualified Data.Text as T
29+import Data.Time.Clock.POSIX
2930
3031main :: IO ()
3132main = do
@@ -123,7 +124,9 @@ main = do
123124 ("x:=relation{tuple{a Just 3}}", mkRelationFromList simpleMaybeIntAttributes [[ConstructedAtom "Just" maybeIntAtomType [IntAtom 3]]]),
124125 --test Either Int Text
125126 ("x:=relation{tuple{a Left 3}}", Left (TypeConstructorTypeVarsMismatch (S.fromList ["a","b"]) (S.fromList ["a"]))), -- Left 3, alone is not enough information to imply the type
126− ("x:=relation{a Either Int Text}{tuple{a Left 3}}", mkRelationFromList simpleEitherIntTextAttributes [[ConstructedAtom "Left" (eitherAtomType IntAtomType TextAtomType) [IntAtom 3]]])
127+ ("x:=relation{a Either Int Text}{tuple{a Left 3}}", mkRelationFromList simpleEitherIntTextAttributes [[ConstructedAtom "Left" (eitherAtomType IntAtomType TextAtomType) [IntAtom 3]]]),
128+ --test datetime constructor
129+ ("x:=relation{tuple{a dateTimeFromEpochSeconds(1495199790)}}", mkRelationFromList (A.attributesFromList [Attribute "a" DateTimeAtomType]) [[DateTimeAtom (posixSecondsToUTCTime(realToFrac 1495199790))]])
127130 ]
128131
129132assertTutdEqual :: DatabaseContext -> Either RelationalError Relation -> Text -> Assertion