Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to PureScript 0.15 #39

Merged
merged 3 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
- uses: actions/checkout@v2

- name: Set up Node toolchain
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: "12.x"
node-version: "14.x"

- name: Cache NPM dependencies
uses: actions/cache@v2
Expand Down Expand Up @@ -45,7 +45,7 @@ jobs:
- name: Install dependencies
run: |
npm ci
npm install purescript@^0.14 pulp bower purescript-psa
npm install purescript@^0.15 pulp bower purescript-psa
npx bower install

- name: Run tests
Expand Down
10 changes: 10 additions & 0 deletions .tidyrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"importSort": "ide",
"importWrap": "source",
"indent": 2,
"operatorsFile": null,
"ribbon": 1,
"typeArrowPlacement": "first",
"unicode": "never",
"width": null
}
43 changes: 22 additions & 21 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,29 @@
"output"
],
"dependencies": {
"purescript-arrays": "^6.0.0",
"purescript-console": "^5.0.0",
"purescript-datetime": "^5.0.0",
"purescript-either": "^5.0.0",
"purescript-enums": "^5.0.0",
"purescript-foldable-traversable": "^5.0.0",
"purescript-formatters": "^5.0.0",
"purescript-integers": "^5.0.0",
"purescript-js-date": "^7.0.0",
"purescript-lists": "^6.0.0",
"purescript-maybe": "^5.0.0",
"purescript-newtype": "^4.0.0",
"purescript-prelude": "^5.0.0",
"purescript-strings": "^5.0.0",
"purescript-tuples": "^6.0.0",
"purescript-unicode": "^5.0.0",
"purescript-numbers": "^8.0.0",
"purescript-decimals": "^6.0.0"
"purescript-arrays": "^7.0.0",
"purescript-console": "^6.0.0",
"purescript-datetime": "^6.0.0",
"purescript-either": "^6.0.0",
"purescript-enums": "^6.0.0",
"purescript-foldable-traversable": "^6.0.0",
"purescript-formatters": "^7.0.0",
"purescript-integers": "^6.0.0",
"purescript-js-date": "^8.0.0",
"purescript-lists": "^7.0.0",
"purescript-maybe": "^6.0.0",
"purescript-newtype": "^5.0.0",
"purescript-prelude": "^6.0.0",
"purescript-strings": "^6.0.0",
"purescript-tuples": "^7.0.0",
"purescript-unicode": "^6.0.0",
"purescript-numbers": "^9.0.0",
"purescript-decimals": "^7.0.0",
"purescript-aff-promise": "^4.0.0"
},
"devDependencies": {
"purescript-psci-support": "^5.0.0",
"purescript-spec": "^5.0.0",
"purescript-spec-discovery": "^6.0.0"
"purescript-psci-support": "^6.0.0",
"purescript-spec": "^7.0.0",
"purescript-spec-discovery": "^8.0.0"
}
}
54 changes: 47 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"devDependencies": {
"big-integer": "^1.6.26",
"decimal.js": "^9.0.1"
"big-integer": "^1.6.51",
"decimal.js": "^10.3.1",
"purs-tidy": "^0.8.0"
}
}
10 changes: 3 additions & 7 deletions src/Data/PreciseDateTime.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import Data.Array ((!!))
import Data.CodePoint.Unicode (isDecDigit)
import Data.DateTime (DateTime, millisecond, time)
import Data.DateTime as DateTime
import Data.Decimal (Decimal)
import Data.Decimal as Decimal
import Data.Enum (fromEnum, toEnum)
import Data.Formatter.DateTime (format)
Expand Down Expand Up @@ -125,14 +124,11 @@ adjust pd (PreciseDateTime dt (Nanosecond ns)) = do
flip PreciseDateTime (Nanosecond nanos)
<$> DateTime.adjust (Milliseconds millis) dt

-- | Coerce a `Data.Decimal` to an Int, truncating it if it is out of range
decimalToInt :: Decimal -> Int
decimalToInt = Int.floor <<< Decimal.toNumber <<< Decimal.truncated

diff :: PreciseDateTime -> PreciseDateTime -> PreciseDuration
diff (PreciseDateTime dt0 (Nanosecond ns0)) (PreciseDateTime dt1 (Nanosecond ns1)) =
let Duration.Milliseconds msNum = DateTime.diff dt0 dt1
nsNum = Int.toNumber (ns0 - ns1) + msNum * 1000000.0
let
Duration.Milliseconds msNum = DateTime.diff dt0 dt1
nsNum = Int.toNumber (ns0 - ns1) + msNum * 1000000.0
in
PD.unsafeNanoseconds (Decimal.fromNumber nsNum)

Expand Down
4 changes: 2 additions & 2 deletions src/Data/PreciseDateTime/Internal.purs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ dateTimeFormatISO = dateFormat <> pure (Placeholder "T") <> timeFormat
dropWhileEnd :: (Char -> Boolean) -> String -> String
dropWhileEnd p s = snd $ Array.foldr check (Tuple false "") (String.toCharArray s)
where
check c state@(Tuple false _) = if p c then state else Tuple true (String.singleton c)
check c (Tuple true string) = Tuple true (String.singleton c <> string)
check c state@(Tuple false _) = if p c then state else Tuple true (String.singleton c)
check c (Tuple true string) = Tuple true (String.singleton c <> string)
5 changes: 2 additions & 3 deletions src/Data/RFC3339String.purs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ trim (RFC3339String s) =
withoutTrailingZeros = dropWhileEnd (eq '0') withoutZulu
withoutTrailingDot = dropWhileEnd (eq '.') withoutTrailingZeros
in
if withoutTrailingZeros == withoutTrailingDot
then RFC3339String $ withoutTrailingDot <> "Z"
-- always have a subseconds component
if withoutTrailingZeros == withoutTrailingDot then RFC3339String $ withoutTrailingDot <> "Z"
-- always have a subseconds component
else RFC3339String $ withoutTrailingDot <> ".0Z"

-- | Use our own formatter since we'd otherwise need to convert from `DateTime`
Expand Down
49 changes: 28 additions & 21 deletions src/Data/Time/PreciseDuration.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ module Data.Time.PreciseDuration
( PreciseDuration
, toString
, negatePreciseDuration
, nanoseconds, microseconds, milliseconds, seconds, minutes, hours, days, weeks
, nanoseconds
, microseconds
, milliseconds
, seconds
, minutes
, hours
, days
, weeks
, unsafeNanoseconds
, unPreciseDuration
, toNanoseconds
Expand Down Expand Up @@ -79,14 +86,14 @@ toString = case _ of

negatePreciseDuration :: PreciseDuration -> PreciseDuration
negatePreciseDuration = case _ of
Nanoseconds x -> Nanoseconds (negate x)
Microseconds x -> Microseconds (negate x)
Milliseconds x -> Milliseconds (negate x)
Seconds x -> Seconds (negate x)
Minutes x -> Minutes (negate x)
Hours x -> Hours (negate x)
Days x -> Days (negate x)
Weeks x -> Weeks (negate x)
Nanoseconds x -> Nanoseconds (negate x)
Microseconds x -> Microseconds (negate x)
Milliseconds x -> Milliseconds (negate x)
Seconds x -> Seconds (negate x)
Minutes x -> Minutes (negate x)
Hours x -> Hours (negate x)
Days x -> Days (negate x)
Weeks x -> Weeks (negate x)

-- Smart constructors
unsafeNanoseconds :: Decimal -> PreciseDuration
Expand Down Expand Up @@ -119,14 +126,14 @@ weeks = Weeks

unPreciseDuration :: PreciseDuration -> Decimal
unPreciseDuration = case _ of
Nanoseconds d -> d
Nanoseconds d -> d
Microseconds d -> d * micro
Milliseconds d -> d * milli
Seconds d -> d * second
Minutes d -> d * minute
Hours d -> d * hour
Days d -> d * day
Weeks d -> d * week
Seconds d -> d * second
Minutes d -> d * minute
Hours d -> d * hour
Days d -> d * day
Weeks d -> d * week

-- Conversions
toNanoseconds :: PreciseDuration -> PreciseDuration
Expand Down Expand Up @@ -173,11 +180,11 @@ toDecimalLossy = case _ of
Weeks d -> d

-- Each duration in nanoseconds
nano = Decimal.fromInt 1 :: Decimal
micro = (nano * Decimal.fromInt 1000) :: Decimal
milli = (micro * Decimal.fromInt 1000) :: Decimal
nano = Decimal.fromInt 1 :: Decimal
micro = (nano * Decimal.fromInt 1000) :: Decimal
milli = (micro * Decimal.fromInt 1000) :: Decimal
second = (milli * Decimal.fromInt 1000) :: Decimal
minute = (second * Decimal.fromInt 60) :: Decimal
hour = (minute * Decimal.fromInt 60) :: Decimal
day = (hour * Decimal.fromInt 24) :: Decimal
week = (day * Decimal.fromInt 7) :: Decimal
hour = (minute * Decimal.fromInt 60) :: Decimal
day = (hour * Decimal.fromInt 24) :: Decimal
week = (day * Decimal.fromInt 7) :: Decimal
7 changes: 3 additions & 4 deletions test/Data/PreciseDateTime.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module Test.Data.PreciseDateTime.Spec where

import Prelude

import Data.Decimal (fromString)
import Data.Date as Date
import Data.Decimal (fromString)
import Data.Enum (toEnum)
import Data.Maybe (Maybe(..), fromJust)
import Data.Newtype (class Newtype)
Expand Down Expand Up @@ -74,7 +74,7 @@ spec =
fromRFC3339String (RFC3339String $ dateStringFixture <> ".1000000000Z")
`shouldEqual` (Just $ preciseDateTimeFixture 100 0)

it"toRFC3339String" do
it "toRFC3339String" do
toRFC3339String (preciseDateTimeFixture 0 0)
`shouldEqual` (RFC3339String $ dateStringFixture <> ".0Z")

Expand Down Expand Up @@ -133,7 +133,6 @@ spec =
diff (mkPreciseDateTime 1985 Date.March 5 23 59 59 999 999999) (mkPreciseDateTime 1985 Date.March 13 0 0 0 0 0)
`shouldEqual` (PD.unsafeNanoseconds <<< unsafePartial fromJust <<< fromString $ "-604800000000001")


it "adjust" do
adjust (PD.nanoseconds 0) (mkPreciseDateTime 1985 Date.March 13 0 0 0 0 0)
`shouldEqual` (Just $ mkPreciseDateTime 1985 Date.March 13 0 0 0 0 0)
Expand All @@ -147,7 +146,7 @@ spec =
adjust (PD.nanoseconds 1000000) (mkPreciseDateTime 1985 Date.March 13 0 0 0 0 0)
`shouldEqual` (Just $ mkPreciseDateTime 1985 Date.March 13 0 0 0 1 0)

adjust(PD.nanoseconds (-1000000)) (mkPreciseDateTime 1985 Date.March 13 0 0 0 0 0)
adjust (PD.nanoseconds (-1000000)) (mkPreciseDateTime 1985 Date.March 13 0 0 0 0 0)
`shouldEqual` (Just $ mkPreciseDateTime 1985 Date.March 12 23 59 59 999 0)

adjust (PD.nanoseconds 10000000) (mkPreciseDateTime 1985 Date.March 13 0 0 0 0 0)
Expand Down
2 changes: 1 addition & 1 deletion test/Data/Time/PreciseDuration.purs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ spec =
PD.toString (PD.toSeconds $ PD.nanoseconds 1) `shouldEqual` "0.000000001s"
PD.toString (PD.toMinutes $ PD.nanoseconds 1) `shouldEqual` "0.00000000001666666667m"
PD.toString (PD.toHours $ PD.nanoseconds 1) `shouldEqual` "0.00000000000027777778h"
PD.toString (PD.toDays $ PD.nanoseconds 1) `shouldEqual` "0.00000000000001157407d"
PD.toString (PD.toDays $ PD.nanoseconds 1) `shouldEqual` "0.00000000000001157407d"
PD.toString (PD.toWeeks $ PD.nanoseconds 1) `shouldEqual` "0.00000000000000165344w"
2 changes: 1 addition & 1 deletion test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ import Test.Spec.Runner (runSpec)
main :: Effect Unit
main = launchAff_ do
spec <- discover "Test\\..*\\.Spec"
runSpec [consoleReporter] spec
runSpec [ consoleReporter ] spec