Sisällytä desimaalitieto rahan Money-tietotyyppiin
This commit is contained in:
parent
24fe93cd90
commit
c7a512175c
@ -19,7 +19,8 @@
|
|||||||
#:recursive? #t
|
#:recursive? #t
|
||||||
#:select? vcs-file?))
|
#:select? vcs-file?))
|
||||||
(build-system haskell-build-system)
|
(build-system haskell-build-system)
|
||||||
(inputs (list ghc-megaparsec))
|
(inputs (list ghc-megaparsec
|
||||||
|
ghc-decimal))
|
||||||
(home-page "https://git.olarinmaensamoojat.fi/OMS/tito")
|
(home-page "https://git.olarinmaensamoojat.fi/OMS/tito")
|
||||||
(synopsis "TITO parsing library")
|
(synopsis "TITO parsing library")
|
||||||
(description "")
|
(description "")
|
||||||
|
@ -9,6 +9,7 @@ import Data.Maybe
|
|||||||
import Control.Monad
|
import Control.Monad
|
||||||
|
|
||||||
import Data.Char (isSpace)
|
import Data.Char (isSpace)
|
||||||
|
import Data.Decimal (DecimalRaw(Decimal))
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import Data.Void (Void)
|
import Data.Void (Void)
|
||||||
import Text.Megaparsec ((<|>))
|
import Text.Megaparsec ((<|>))
|
||||||
@ -80,7 +81,7 @@ money = do
|
|||||||
sign <- P.label "+ or -" $ P.oneOf [43, 45] -- +, -
|
sign <- P.label "+ or -" $ P.oneOf [43, 45] -- +, -
|
||||||
let setSign | sign == 43 = id
|
let setSign | sign == 43 = id
|
||||||
| sign == 45 = negate
|
| sign == 45 = negate
|
||||||
Money . setSign <$> numeric 18
|
Money . Decimal 2 . setSign <$> numeric 18
|
||||||
|
|
||||||
optional :: Int -> Parser a -> Parser (Maybe a)
|
optional :: Int -> Parser a -> Parser (Maybe a)
|
||||||
optional n p = P.try (P.count n (P.char 32) *> pure Nothing) <|> (Just <$> p)
|
optional n p = P.try (P.count n (P.char 32) *> pure Nothing) <|> (Just <$> p)
|
||||||
@ -133,7 +134,7 @@ accountStatement = do
|
|||||||
_records <- optional' numeric 6
|
_records <- optional' numeric 6
|
||||||
currency <- optional' alphaNumeric 3
|
currency <- optional' alphaNumeric 3
|
||||||
accountName <- optional' alphaNumeric 30
|
accountName <- optional' alphaNumeric 30
|
||||||
accountLimit <- fmap Money <$> optional' numeric 18
|
accountLimit <- fmap (Money . Decimal 2) <$> optional' numeric 18
|
||||||
accountOwnerName <- alphaNumeric 35
|
accountOwnerName <- alphaNumeric 35
|
||||||
bankName <- alphaNumeric 40
|
bankName <- alphaNumeric 40
|
||||||
contactInformation <- optional' alphaNumeric 40
|
contactInformation <- optional' alphaNumeric 40
|
||||||
|
@ -7,6 +7,7 @@ import Data.ByteString (ByteString)
|
|||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import Data.Time (Day, LocalTime)
|
import Data.Time (Day, LocalTime)
|
||||||
import Data.List.NonEmpty (NonEmpty)
|
import Data.List.NonEmpty (NonEmpty)
|
||||||
|
import Data.Decimal (Decimal)
|
||||||
|
|
||||||
data AccountStatement = AccountStatement
|
data AccountStatement = AccountStatement
|
||||||
{ account :: Text
|
{ account :: Text
|
||||||
@ -28,7 +29,7 @@ data AccountStatement = AccountStatement
|
|||||||
, events :: [Event]
|
, events :: [Event]
|
||||||
} deriving (Show, Eq)
|
} deriving (Show, Eq)
|
||||||
|
|
||||||
newtype Money = Money Integer deriving (Eq, Show)
|
newtype Money = Money Decimal deriving (Eq, Show)
|
||||||
|
|
||||||
data Event = BasicTransaction Transaction -- T10
|
data Event = BasicTransaction Transaction -- T10
|
||||||
| TransactionNotification Transaction -- T80
|
| TransactionNotification Transaction -- T80
|
||||||
|
@ -12,6 +12,7 @@ library
|
|||||||
base,
|
base,
|
||||||
bytestring,
|
bytestring,
|
||||||
containers,
|
containers,
|
||||||
|
Decimal,
|
||||||
megaparsec,
|
megaparsec,
|
||||||
text,
|
text,
|
||||||
time
|
time
|
||||||
|
Loading…
Reference in New Issue
Block a user