Skip to content

Commit

Permalink
ADD: Generics
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-corumdigital committed Mar 19, 2018
1 parent 191d31b commit 357aeec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"purescript-exceptions": "^3.0.0",
"purescript-foreign": "^4.0.0",
"purescript-integers": "^3.0.0",
"purescript-now": "^3.0.0"
"purescript-now": "^3.0.0",
"purescript-generics-rep": "^5.4.0",
"purescript-foreign-generic": "^5.0.1"
},
"devDependencies": {
"purescript-assert": "^3.0.0",
Expand Down
13 changes: 13 additions & 0 deletions src/Data/JSDate.purs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ import Data.DateTime.Instant (Instant)
import Data.DateTime.Instant as Instant
import Data.Enum (fromEnum)
import Data.Foreign (F, Foreign, unsafeReadTagged)
import Data.Foreign.Class (class Encode, class Decode)
import Data.Foreign.Generic as Fgn
import Data.Function.Uncurried (Fn2, runFn2)
import Data.Generic.Rep (class Generic, Argument(..), Constructor(..))
import Data.Int (toNumber)
import Data.Maybe (Maybe(..))
import Data.Time as Time
Expand All @@ -76,6 +79,16 @@ instance ordJSDate :: Ord JSDate where
instance showJSDate :: Show JSDate where
show a = "(fromTime " <> show (getTime a) <> ")"

instance genericJSDate :: Generic JSDate (Constructor "JSDate" (Argument Number)) where
to (Constructor (Argument time)) = fromTime time
from x = Constructor (Argument (getTime x))

instance encodeJSDate :: Encode JSDate where
encode = Fgn.genericEncode Fgn.defaultOptions

instance decodeJSDate :: Decode JSDate where
decode = Fgn.genericDecode Fgn.defaultOptions

-- | The effect type used when indicating the current machine's date/time locale
-- | is used in computing a value.
foreign import data LOCALE :: Effect
Expand Down

0 comments on commit 357aeec

Please sign in to comment.