File tree Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -34,3 +34,9 @@ exports.dateMethodEff = function (method, date) {
34
34
return date [ method ] ( ) ;
35
35
} ;
36
36
} ;
37
+
38
+ exports . parse = function ( dateString ) {
39
+ return function ( ) {
40
+ return new Date ( dateString ) ;
41
+ } ;
42
+ } ;
Original file line number Diff line number Diff line change @@ -102,6 +102,16 @@ foreign import jsdateLocal
102
102
foreign import dateMethodEff :: forall eff a . Fn2 String JSDate (Eff eff a )
103
103
foreign import dateMethod :: forall a . Fn2 String JSDate a
104
104
105
+ -- | Attempts to parse a date from a string. The behaviour of this function is
106
+ -- | implementation specific until ES5, so may not always have the same
107
+ -- | behaviour for a given string. The RFC2822 and ISO8601 date string formats
108
+ -- | should parse consistently.
109
+ -- |
110
+ -- | The `LOCALE` effect is present here as if no time zone is specified in the
111
+ -- | string the current locale's time zone will be used instead.
112
+ foreign import parse
113
+ :: forall eff . String -> Eff (locale :: LOCALE | eff ) JSDate
114
+
105
115
-- | The effect type used when indicating the current machine's date/time locale
106
116
-- | is used in computing a value.
107
117
foreign import data LOCALE :: !
Original file line number Diff line number Diff line change @@ -38,6 +38,10 @@ main = do
38
38
assert $ not $ JSD .isValid $ JSD .jsdate defaultDateRecord { second = nan }
39
39
assert $ not $ JSD .isValid $ JSD .jsdate defaultDateRecord { millisecond = nan }
40
40
41
+ log " Checking that a date constructed from a string with sensible values is valid..."
42
+ assert <<< JSD .isValid =<< JSD .parse " 2011-10-10T14:48:00"
43
+ assert <<< JSD .isValid =<< JSD .parse " Thu, 01 Jan 1970 00:00:00 GMT-0400"
44
+
41
45
log " Checking that a local date constructed with sensible values is valid..."
42
46
assert <<< JSD .isValid =<< JSD .jsdateLocal defaultDateRecord
43
47
You can’t perform that action at this time.
0 commit comments