lib,cli,ui: Remove old CPP directives made redundant by version bounds.
This commit is contained in:
parent
dc426266a4
commit
2fd678e415
@ -1,4 +1,3 @@
|
|||||||
{-# LANGUAGE CPP #-}
|
|
||||||
{-# LANGUAGE NoMonoLocalBinds #-}
|
{-# LANGUAGE NoMonoLocalBinds #-}
|
||||||
{-# LANGUAGE FlexibleContexts #-}
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
{-# LANGUAGE TypeFamilies #-}
|
{-# LANGUAGE TypeFamilies #-}
|
||||||
@ -93,12 +92,7 @@ import Data.Maybe
|
|||||||
import qualified Data.Set as Set
|
import qualified Data.Set as Set
|
||||||
import Data.Text (Text)
|
import Data.Text (Text)
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
#if MIN_VERSION_time(1,5,0)
|
|
||||||
import Data.Time.Format hiding (months)
|
import Data.Time.Format hiding (months)
|
||||||
#else
|
|
||||||
import Data.Time.Format
|
|
||||||
import System.Locale (TimeLocale, defaultTimeLocale)
|
|
||||||
#endif
|
|
||||||
import Data.Time.Calendar
|
import Data.Time.Calendar
|
||||||
import Data.Time.Calendar.OrdinalDate
|
import Data.Time.Calendar.OrdinalDate
|
||||||
import Data.Time.Clock
|
import Data.Time.Clock
|
||||||
@ -669,23 +663,20 @@ advancetonthweekday n wd s =
|
|||||||
-- parseTime defaultTimeLocale "%Y-%m-%d %H:%M:%S" s
|
-- parseTime defaultTimeLocale "%Y-%m-%d %H:%M:%S" s
|
||||||
-- ]
|
-- ]
|
||||||
|
|
||||||
parsetime :: ParseTime t => TimeLocale -> String -> String -> Maybe t
|
|
||||||
parsetime =
|
|
||||||
#if MIN_VERSION_time(1,5,0)
|
|
||||||
parseTimeM True
|
|
||||||
#else
|
|
||||||
parseTime
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
-- | Try to parse a couple of date string formats:
|
-- | Try to parse a couple of date string formats:
|
||||||
-- `YYYY-MM-DD`, `YYYY/MM/DD` or `YYYY.MM.DD`, with leading zeros required.
|
-- `YYYY-MM-DD`, `YYYY/MM/DD` or `YYYY.MM.DD`, with leading zeros required.
|
||||||
-- For internal use, not quite the same as the journal's "simple dates".
|
-- For internal use, not quite the same as the journal's "simple dates".
|
||||||
|
-- >>> parsedateM "2008/02/03"
|
||||||
|
-- Just 2008-02-03
|
||||||
|
-- >>> parsedateM "2008/02/03/"
|
||||||
|
-- Nothing
|
||||||
|
-- >>> parsedateM "2008/02/30"
|
||||||
|
-- Nothing
|
||||||
parsedateM :: String -> Maybe Day
|
parsedateM :: String -> Maybe Day
|
||||||
parsedateM s = asum [
|
parsedateM s = asum [
|
||||||
parsetime defaultTimeLocale "%Y-%m-%d" s,
|
parseTimeM True defaultTimeLocale "%Y-%m-%d" s,
|
||||||
parsetime defaultTimeLocale "%Y/%m/%d" s,
|
parseTimeM True defaultTimeLocale "%Y/%m/%d" s,
|
||||||
parsetime defaultTimeLocale "%Y.%m.%d" s
|
parseTimeM True defaultTimeLocale "%Y.%m.%d" s
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -695,28 +686,9 @@ parsedateM s = asum [
|
|||||||
-- (parsedatetimeM s)
|
-- (parsedatetimeM s)
|
||||||
|
|
||||||
-- | Like parsedateM, raising an error on parse failure.
|
-- | Like parsedateM, raising an error on parse failure.
|
||||||
--
|
|
||||||
-- >>> parsedate "2008/02/03"
|
|
||||||
-- 2008-02-03
|
|
||||||
parsedate :: String -> Day
|
parsedate :: String -> Day
|
||||||
parsedate s = fromMaybe (error' $ "could not parse date \"" ++ s ++ "\"") -- PARTIAL:
|
parsedate s = fromMaybe (error' $ "could not parse date \"" ++ s ++ "\"") -- PARTIAL:
|
||||||
(parsedateM s)
|
$ parsedateM s
|
||||||
-- doctests I haven't been able to make compatible with both GHC 7 and 8
|
|
||||||
-- -- >>> parsedate "2008/02/03/"
|
|
||||||
-- -- *** Exception: could not parse date "2008/02/03/"
|
|
||||||
-- #if MIN_VERSION_base(4,9,0)
|
|
||||||
-- -- ...
|
|
||||||
-- #endif
|
|
||||||
-- #if MIN_VERSION_time(1,6,0)
|
|
||||||
-- -- >>> parsedate "2008/02/30" -- with time >= 1.6, invalid dates are rejected
|
|
||||||
-- -- *** Exception: could not parse date "2008/02/30"
|
|
||||||
-- #if MIN_VERSION_base(4,9,0)
|
|
||||||
-- -- ...
|
|
||||||
-- #endif
|
|
||||||
-- #else
|
|
||||||
-- -- >>> parsedate "2008/02/30" -- with time < 1.6, they are silently adjusted
|
|
||||||
-- -- 2008-02-29
|
|
||||||
-- #endif
|
|
||||||
|
|
||||||
{-|
|
{-|
|
||||||
Parse a date in any of the formats allowed in Ledger's period expressions, and some others.
|
Parse a date in any of the formats allowed in Ledger's period expressions, and some others.
|
||||||
|
|||||||
@ -6,7 +6,7 @@ converted to 'Transactions' and queried like a ledger.
|
|||||||
|
|
||||||
-}
|
-}
|
||||||
|
|
||||||
{-# LANGUAGE CPP, OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
module Hledger.Data.Timeclock (
|
module Hledger.Data.Timeclock (
|
||||||
timeclockEntriesToTransactions
|
timeclockEntriesToTransactions
|
||||||
@ -21,9 +21,6 @@ import Data.Time.Calendar
|
|||||||
import Data.Time.Clock
|
import Data.Time.Clock
|
||||||
import Data.Time.Format
|
import Data.Time.Format
|
||||||
import Data.Time.LocalTime
|
import Data.Time.LocalTime
|
||||||
#if !(MIN_VERSION_time(1,5,0))
|
|
||||||
import System.Locale (defaultTimeLocale)
|
|
||||||
#endif
|
|
||||||
import Text.Printf
|
import Text.Printf
|
||||||
|
|
||||||
import Hledger.Utils
|
import Hledger.Utils
|
||||||
@ -136,11 +133,7 @@ tests_Timeclock = tests "Timeclock" [
|
|||||||
yesterday = prevday today
|
yesterday = prevday today
|
||||||
clockin = TimeclockEntry nullsourcepos In
|
clockin = TimeclockEntry nullsourcepos In
|
||||||
mktime d = LocalTime d . fromMaybe midnight .
|
mktime d = LocalTime d . fromMaybe midnight .
|
||||||
#if MIN_VERSION_time(1,5,0)
|
|
||||||
parseTimeM True defaultTimeLocale "%H:%M:%S"
|
parseTimeM True defaultTimeLocale "%H:%M:%S"
|
||||||
#else
|
|
||||||
parseTime defaultTimeLocale "%H:%M:%S"
|
|
||||||
#endif
|
|
||||||
showtime = formatTime defaultTimeLocale "%H:%M"
|
showtime = formatTime defaultTimeLocale "%H:%M"
|
||||||
txndescs = map (T.unpack . tdescription) . timeclockEntriesToTransactions now
|
txndescs = map (T.unpack . tdescription) . timeclockEntriesToTransactions now
|
||||||
future = utcToLocalTime tz $ addUTCTime 100 now'
|
future = utcToLocalTime tz $ addUTCTime 100 now'
|
||||||
|
|||||||
@ -11,7 +11,6 @@ A reader for CSV data, using an extra rules file to help interpret the data.
|
|||||||
-- stack haddock hledger-lib --fast --no-haddock-deps --haddock-arguments='--ignore-all-exports' --open
|
-- stack haddock hledger-lib --fast --no-haddock-deps --haddock-arguments='--ignore-all-exports' --open
|
||||||
|
|
||||||
--- ** language
|
--- ** language
|
||||||
{-# LANGUAGE CPP #-}
|
|
||||||
{-# LANGUAGE FlexibleContexts #-}
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
{-# LANGUAGE FlexibleInstances #-}
|
{-# LANGUAGE FlexibleInstances #-}
|
||||||
{-# LANGUAGE MultiWayIf #-}
|
{-# LANGUAGE MultiWayIf #-}
|
||||||
@ -61,12 +60,7 @@ import qualified Data.Text as T
|
|||||||
import qualified Data.Text.Encoding as T
|
import qualified Data.Text.Encoding as T
|
||||||
import qualified Data.Text.IO as T
|
import qualified Data.Text.IO as T
|
||||||
import Data.Time.Calendar (Day)
|
import Data.Time.Calendar (Day)
|
||||||
#if MIN_VERSION_time(1,5,0)
|
|
||||||
import Data.Time.Format (parseTimeM, defaultTimeLocale)
|
import Data.Time.Format (parseTimeM, defaultTimeLocale)
|
||||||
#else
|
|
||||||
import Data.Time.Format (parseTime)
|
|
||||||
import System.Locale (defaultTimeLocale)
|
|
||||||
#endif
|
|
||||||
import Safe
|
import Safe
|
||||||
import System.Directory (doesFileExist)
|
import System.Directory (doesFileExist)
|
||||||
import System.FilePath
|
import System.FilePath
|
||||||
@ -1229,13 +1223,7 @@ csvFieldValue rules record fieldname = do
|
|||||||
parseDateWithCustomOrDefaultFormats :: Maybe DateFormat -> String -> Maybe Day
|
parseDateWithCustomOrDefaultFormats :: Maybe DateFormat -> String -> Maybe Day
|
||||||
parseDateWithCustomOrDefaultFormats mformat s = asum $ map parsewith formats
|
parseDateWithCustomOrDefaultFormats mformat s = asum $ map parsewith formats
|
||||||
where
|
where
|
||||||
parsetime =
|
parsewith = flip (parseTimeM True defaultTimeLocale) s
|
||||||
#if MIN_VERSION_time(1,5,0)
|
|
||||||
parseTimeM True
|
|
||||||
#else
|
|
||||||
parseTime
|
|
||||||
#endif
|
|
||||||
parsewith = flip (parsetime defaultTimeLocale) s
|
|
||||||
formats = maybe
|
formats = maybe
|
||||||
["%Y/%-m/%-d"
|
["%Y/%-m/%-d"
|
||||||
,"%Y-%-m-%-d"
|
,"%Y-%-m-%-d"
|
||||||
|
|||||||
@ -33,11 +33,7 @@ import System.FilePath
|
|||||||
import System.FSNotify
|
import System.FSNotify
|
||||||
import Brick
|
import Brick
|
||||||
|
|
||||||
#if MIN_VERSION_brick(0,16,0)
|
|
||||||
import qualified Brick.BChan as BC
|
import qualified Brick.BChan as BC
|
||||||
#else
|
|
||||||
import Control.Concurrent.Chan (newChan, writeChan)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
import Hledger
|
import Hledger
|
||||||
import Hledger.Cli hiding (progname,prognameandversion)
|
import Hledger.Cli hiding (progname,prognameandversion)
|
||||||
@ -50,13 +46,11 @@ import Hledger.UI.RegisterScreen
|
|||||||
|
|
||||||
----------------------------------------------------------------------
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
#if MIN_VERSION_brick(0,16,0)
|
|
||||||
newChan :: IO (BC.BChan a)
|
newChan :: IO (BC.BChan a)
|
||||||
newChan = BC.newBChan 10
|
newChan = BC.newBChan 10
|
||||||
|
|
||||||
writeChan :: BC.BChan a -> a -> IO ()
|
writeChan :: BC.BChan a -> a -> IO ()
|
||||||
writeChan = BC.writeBChan
|
writeChan = BC.writeBChan
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
{- | UIState operations. -}
|
{- | UIState operations. -}
|
||||||
|
|
||||||
{-# LANGUAGE CPP #-}
|
|
||||||
{-# LANGUAGE NamedFieldPuns #-}
|
{-# LANGUAGE NamedFieldPuns #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE RecordWildCards #-}
|
{-# LANGUAGE RecordWildCards #-}
|
||||||
@ -8,9 +7,6 @@
|
|||||||
module Hledger.UI.UIState
|
module Hledger.UI.UIState
|
||||||
where
|
where
|
||||||
|
|
||||||
#if !MIN_VERSION_brick(0,19,0)
|
|
||||||
import Brick
|
|
||||||
#endif
|
|
||||||
import Brick.Widgets.Edit
|
import Brick.Widgets.Edit
|
||||||
import Data.List
|
import Data.List
|
||||||
import Data.Text.Zipper (gotoEOL)
|
import Data.Text.Zipper (gotoEOL)
|
||||||
@ -308,11 +304,7 @@ getDepth UIState{aopts=UIOpts{cliopts_=CliOpts{reportopts_=ropts}}} = depth_ rop
|
|||||||
showMinibuffer :: UIState -> UIState
|
showMinibuffer :: UIState -> UIState
|
||||||
showMinibuffer ui = setMode (Minibuffer e) ui
|
showMinibuffer ui = setMode (Minibuffer e) ui
|
||||||
where
|
where
|
||||||
#if MIN_VERSION_brick(0,19,0)
|
|
||||||
e = applyEdit gotoEOL $ editor MinibufferEditor (Just 1) oldq
|
e = applyEdit gotoEOL $ editor MinibufferEditor (Just 1) oldq
|
||||||
#else
|
|
||||||
e = applyEdit gotoEOL $ editor MinibufferEditor (str . unlines) (Just 1) oldq
|
|
||||||
#endif
|
|
||||||
oldq = query_ $ reportopts_ $ cliopts_ $ aopts ui
|
oldq = query_ $ reportopts_ $ cliopts_ $ aopts ui
|
||||||
|
|
||||||
-- | Close the minibuffer, discarding any edit in progress.
|
-- | Close the minibuffer, discarding any edit in progress.
|
||||||
|
|||||||
@ -180,12 +180,7 @@ helpHandle ui ev = do
|
|||||||
minibuffer :: Editor String Name -> Widget Name
|
minibuffer :: Editor String Name -> Widget Name
|
||||||
minibuffer ed =
|
minibuffer ed =
|
||||||
forceAttr ("border" <> "minibuffer") $
|
forceAttr ("border" <> "minibuffer") $
|
||||||
hBox $
|
hBox [txt "filter: ", renderEditor (str . unlines) True ed]
|
||||||
#if MIN_VERSION_brick(0,19,0)
|
|
||||||
[txt "filter: ", renderEditor (str . unlines) True ed]
|
|
||||||
#else
|
|
||||||
[txt "filter: ", renderEditor True ed]
|
|
||||||
#endif
|
|
||||||
|
|
||||||
borderQueryStr :: String -> Widget Name
|
borderQueryStr :: String -> Widget Name
|
||||||
borderQueryStr "" = str ""
|
borderQueryStr "" = str ""
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
{-# LANGUAGE ParallelListComp, CPP #-}
|
{-# LANGUAGE ParallelListComp #-}
|
||||||
{-# LANGUAGE TemplateHaskell #-}
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
{-|
|
{-|
|
||||||
|
|
||||||
@ -205,14 +205,9 @@ internalRateOfReturn showCashFlow prettyTables (OneSpan spanBegin spanEnd valueB
|
|||||||
-- 0% is always a solution, so require at least something here
|
-- 0% is always a solution, so require at least something here
|
||||||
case totalCF of
|
case totalCF of
|
||||||
[] -> return 0
|
[] -> return 0
|
||||||
_ ->
|
_ -> case ridders (RiddersParam 100 (AbsTol 0.00001))
|
||||||
case ridders
|
(0.000000000001,10000)
|
||||||
#if MIN_VERSION_math_functions(0,3,0)
|
(interestSum spanEnd totalCF) of
|
||||||
(RiddersParam 100 (AbsTol 0.00001))
|
|
||||||
#else
|
|
||||||
0.00001
|
|
||||||
#endif
|
|
||||||
(0.000000000001,10000) (interestSum spanEnd totalCF) of
|
|
||||||
Root rate -> return ((rate-1)*100)
|
Root rate -> return ((rate-1)*100)
|
||||||
NotBracketed -> error' "Error: No solution -- not bracketed." -- PARTIAL:
|
NotBracketed -> error' "Error: No solution -- not bracketed." -- PARTIAL:
|
||||||
SearchFailed -> error' "Error: Failed to find solution."
|
SearchFailed -> error' "Error: Failed to find solution."
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user