Skip to content

Commit

Permalink
Merge pull request #18 from purescript-contrib/compiler/0.12
Browse files Browse the repository at this point in the history
Updates for 0.12
  • Loading branch information
garyb authored May 25, 2018
2 parents 8dea07e + dc2c350 commit f332c15
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 51 deletions.
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ language: node_js
dist: trusty
sudo: required
node_js: stable
env:
- PATH=$HOME/purescript:$PATH
install:
- TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p')
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
- chmod a+x $HOME/purescript
- npm install -g bower
- npm install
- bower install --production
script:
- npm run -s build
- bower install
- npm -s test
- npm run -s test
after_success:
- >-
test $TRAVIS_TAG &&
Expand Down
16 changes: 8 additions & 8 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
"package.json"
],
"dependencies": {
"purescript-datetime": "^3.0.0",
"purescript-exceptions": "^3.0.0",
"purescript-foreign": "^4.0.0",
"purescript-integers": "^3.0.0",
"purescript-now": "^3.0.0"
"purescript-datetime": "^4.0.0",
"purescript-exceptions": "^4.0.0",
"purescript-foreign": "^5.0.0",
"purescript-integers": "^4.0.0",
"purescript-now": "^4.0.0"
},
"devDependencies": {
"purescript-assert": "^3.0.0",
"purescript-console": "^3.0.0",
"purescript-globals": "^3.0.0"
"purescript-assert": "^4.0.0",
"purescript-console": "^4.1.0",
"purescript-globals": "^4.0.0"
}
}
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
"test": "pulp test"
},
"devDependencies": {
"eslint": "^3.19.0",
"pulp": "^11.0.0",
"purescript-psa": "^0.5.0",
"purescript": "^0.11.1",
"rimraf": "^2.6.1"
"eslint": "^4.19.1",
"pulp": "^12.2.0",
"purescript-psa": "^0.6.0",
"rimraf": "^2.6.2"
}
}
45 changes: 18 additions & 27 deletions src/Data/JSDate.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
-- | a `Generic` instance.
module Data.JSDate
( JSDate
, LOCALE
, readDate
, isValid
, fromDateTime
Expand Down Expand Up @@ -48,21 +47,19 @@ module Data.JSDate

import Prelude

import Control.Monad.Eff (kind Effect, Eff)
import Control.Monad.Eff.Exception (EXCEPTION)
import Control.Monad.Eff.Now (NOW)
import Data.Date as Date
import Data.DateTime (DateTime(..), Date)
import Data.DateTime as DateTime
import Data.DateTime.Instant (Instant)
import Data.DateTime.Instant as Instant
import Data.Enum (fromEnum)
import Data.Foreign (F, Foreign, unsafeReadTagged)
import Data.Function.Uncurried (Fn2, runFn2)
import Data.Int (toNumber)
import Data.Maybe (Maybe(..))
import Data.Time as Time
import Data.Time.Duration (Milliseconds(..))
import Effect (Effect)
import Foreign (F, Foreign, unsafeReadTagged)

-- | The type of JavaScript `Date` objects.
foreign import data JSDate :: Type
Expand All @@ -76,10 +73,6 @@ instance ordJSDate :: Ord JSDate where
instance showJSDate :: Show JSDate where
show a = "(fromTime " <> show (getTime a) <> ")"

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

-- | Attempts to read a `Foreign` value as a `JSDate`.
readDate :: Foreign -> F JSDate
readDate = unsafeReadTagged "Date"
Expand Down Expand Up @@ -142,18 +135,17 @@ foreign import jsdate
-- | Constructs a new `JSDate` from component values using the current machine's
-- | locale. If any of the values are `NaN` the resulting date will be invalid.
foreign import jsdateLocal
:: forall eff
. { year :: Number
:: { year :: Number
, month :: Number
, day :: Number
, hour :: Number
, minute :: Number
, second :: Number
, millisecond :: Number
}
-> Eff (locale :: LOCALE | eff) JSDate
-> Effect JSDate

foreign import dateMethodEff :: forall eff a. Fn2 String JSDate (Eff eff a)
foreign import dateMethodEff :: forall a. Fn2 String JSDate (Effect a)
foreign import dateMethod :: forall a. Fn2 String JSDate a

-- | Attempts to parse a date from a string. The behaviour of this function is
Expand All @@ -163,15 +155,14 @@ foreign import dateMethod :: forall a. Fn2 String JSDate a
-- |
-- | The `LOCALE` effect is present here as if no time zone is specified in the
-- | string the current locale's time zone will be used instead.
foreign import parse
:: forall eff. String -> Eff (locale :: LOCALE | eff) JSDate
foreign import parse :: String -> Effect JSDate

-- | Gets a `JSDate` value for the date and time according to the current
-- | machine's clock.
-- |
-- | Unless a `JSDate` is required specifically, consider using the functions in
-- | `Control.Monad.Eff.Now` instead.
foreign import now :: forall eff. Eff (now :: NOW | eff) JSDate
-- | `Effect.Now` instead.
foreign import now :: Effect JSDate

-- | Returns the date as a number of milliseconds since 1970-01-01 00:00:00 UTC.
getTime :: JSDate -> Number
Expand Down Expand Up @@ -211,55 +202,55 @@ getUTCSeconds dt = runFn2 dateMethod "getUTCSeconds" dt

-- | Returns the day of the month for a date, according to the current
-- | machine's date/time locale.
getDate :: forall eff. JSDate -> Eff (locale :: LOCALE | eff) Number
getDate :: JSDate -> Effect Number
getDate dt = runFn2 dateMethodEff "getDate" dt

-- | Returns the day of the week for a date, according to the current
-- | machine's date/time locale.
getDay :: forall eff. JSDate -> Eff (locale :: LOCALE | eff) Number
getDay :: JSDate -> Effect Number
getDay dt = runFn2 dateMethodEff "getDay" dt

-- | Returns the year for a date, according to the current machine's date/time
-- | locale.
getFullYear :: forall eff. JSDate -> Eff (locale :: LOCALE | eff) Number
getFullYear :: JSDate -> Effect Number
getFullYear dt = runFn2 dateMethodEff "getFullYear" dt

-- | Returns the hour for a date, according to the current machine's date/time
-- | locale.
getHours :: forall eff. JSDate -> Eff (locale :: LOCALE | eff) Number
getHours :: JSDate -> Effect Number
getHours dt = runFn2 dateMethodEff "getHours" dt

-- | Returns the milliseconds for a date, according to the current machine's
-- | date/time locale.
getMilliseconds :: forall eff. JSDate -> Eff (locale :: LOCALE | eff) Number
getMilliseconds :: JSDate -> Effect Number
getMilliseconds dt = runFn2 dateMethodEff "getMilliseconds" dt

-- | Returns the minutes for a date, according to the current machine's
-- | date/time locale.
getMinutes :: forall eff. JSDate -> Eff (locale :: LOCALE | eff) Number
getMinutes :: JSDate -> Effect Number
getMinutes dt = runFn2 dateMethodEff "getMinutes" dt

-- | Returns the month for a date, according to the current machine's
-- | date/time locale.
getMonth :: forall eff. JSDate -> Eff (locale :: LOCALE | eff) Number
getMonth :: JSDate -> Effect Number
getMonth dt = runFn2 dateMethodEff "getMonth" dt

-- | Returns the seconds for a date, according to the current machine's
-- | date/time locale.
getSeconds :: forall eff. JSDate -> Eff (locale :: LOCALE | eff) Number
getSeconds :: JSDate -> Effect Number
getSeconds dt = runFn2 dateMethodEff "getSeconds" dt

-- | Returns the time-zone offset for a date, according to the current machine's
-- | date/time locale.
getTimezoneOffset :: forall eff. JSDate -> Eff (locale :: LOCALE | eff) Number
getTimezoneOffset :: JSDate -> Effect Number
getTimezoneOffset dt = runFn2 dateMethodEff "getTimezoneOffset" dt

-- | Returns the date portion of a date value as a human-readable string.
toDateString :: JSDate -> String
toDateString dt = runFn2 dateMethod "toDateString" dt

-- | Converts a date value to an ISO 8601 Extended format date string.
toISOString :: forall eff. JSDate -> Eff (exception :: EXCEPTION | eff) String
toISOString :: JSDate -> Effect String
toISOString dt = runFn2 dateMethodEff "toISOString" dt

-- | Returns a string representing for a date value.
Expand Down
17 changes: 7 additions & 10 deletions test/Test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,22 @@ module Test.Main where

import Prelude

import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Control.Monad.Except (runExcept)

import Data.DateTime as DT
import Data.Enum (toEnum)
import Data.Either (isRight)
import Data.Foreign (F, Foreign)
import Data.Enum (toEnum)
import Data.JSDate as JSD
import Data.Maybe (Maybe(..), fromJust)
import Partial.Unsafe (unsafePartial)

import Effect (Effect)
import Effect.Console (log)
import Foreign (F, Foreign)
import Global (nan)

import Test.Assert (ASSERT, assert)
import Partial.Unsafe (unsafePartial)
import Test.Assert (assert)

foreign import myDate :: Foreign

main :: forall eff. Eff (console :: CONSOLE, assert :: ASSERT, locale :: JSD.LOCALE | eff) Unit
main :: Effect Unit
main = do

log "Checking that readDate will read JS date values..."
Expand Down

0 comments on commit f332c15

Please sign in to comment.