File tree Expand file tree Collapse file tree 4 files changed +18
-1
lines changed Expand file tree Collapse file tree 4 files changed +18
-1
lines changed Original file line number Diff line number Diff line change 18
18
"dependencies" : {
19
19
"purescript-datetime" : " ^1.0.0" ,
20
20
"purescript-exceptions" : " ^1.0.0" ,
21
+ "purescript-foreign" : " ^1.0.0" ,
21
22
"purescript-integers" : " ^1.0.0"
22
23
},
23
24
"devDependencies" : {
Original file line number Diff line number Diff line change @@ -19,6 +19,8 @@ import Data.DateTime as DateTime
19
19
import Data.DateTime.Instant (Instant )
20
20
import Data.DateTime.Instant as Instant
21
21
import Data.Enum (fromEnum )
22
+ import Data.Foreign (unsafeReadTagged )
23
+ import Data.Foreign.Class (class IsForeign )
22
24
import Data.Function.Uncurried (Fn2 , runFn2 )
23
25
import Data.Int (toNumber )
24
26
import Data.Maybe (Maybe (..))
@@ -28,6 +30,9 @@ import Data.Time.Duration (Milliseconds(..))
28
30
-- | The type of JavaScript `Date` objects.
29
31
foreign import data JSDate :: *
30
32
33
+ instance isForeignJSDate :: IsForeign JSDate where
34
+ read = unsafeReadTagged " Date"
35
+
31
36
-- | Checks whether a date value is valid. When a date is invalid, the majority
32
37
-- | of the functions return `NaN`, `"Invalid Date"`, or throw an exception.
33
38
foreign import isValid :: JSDate -> Boolean
Original file line number Diff line number Diff line change
1
+ "use strict" ;
2
+
3
+ exports . myDate = new Date ( ) ;
Original file line number Diff line number Diff line change @@ -5,19 +5,27 @@ import Prelude
5
5
import Control.Monad.Eff (Eff )
6
6
import Control.Monad.Eff.Console (CONSOLE , log )
7
7
8
+ import Data.DateTime as DT
8
9
import Data.Enum (toEnum )
10
+ import Data.Either (isRight )
11
+ import Data.Foreign (F , Foreign )
12
+ import Data.Foreign.Class (read )
9
13
import Data.JSDate as JSD
10
- import Data.DateTime as DT
11
14
import Data.Maybe (Maybe (..), fromJust )
12
15
import Partial.Unsafe (unsafePartial )
13
16
14
17
import Global (nan )
15
18
16
19
import Test.Assert (ASSERT , assert )
17
20
21
+ foreign import myDate :: Foreign
22
+
18
23
main :: forall eff . Eff (console :: CONSOLE , assert :: ASSERT , locale :: JSD.LOCALE | eff ) Unit
19
24
main = do
20
25
26
+ log " Check IsForeign intance will read JS date values..."
27
+ assert $ isRight $ read myDate :: F JSD.JSDate
28
+
21
29
log " Checking that a UTC date constructed with sensible values is valid..."
22
30
assert $ JSD .isValid $ JSD .jsdate defaultDateRecord
23
31
You can’t perform that action at this time.
0 commit comments