pkg!: Migrate the last of old-time over to time, changing ClockTime to

POSIXTime.

This eliminates old-time, which has been deprecated for a while, from
our dependencies.

This introduces a slight incompatibility, as a small number of functions
now take/return POSIXTime instead of ClockTime. Generally you will be
using the current time, in which case you should use getPOSIXTime from
Data.Time.Clock.POSIX instead of getClockTime.

utcTimeToClockTime has been removed, as it is now equivalent to
utcTimeToPOSIXSeconds from Data.Time.Clock.POSIX.
This commit is contained in:
Stephen Morgan 2021-08-11 13:52:39 +10:00 committed by Simon Michael
parent c135c1a3fc
commit 4576f8effd
9 changed files with 14 additions and 37 deletions

View File

@ -116,8 +116,8 @@ import Data.Text (Text)
import qualified Data.Text as T import qualified Data.Text as T
import Safe (headMay, headDef, maximumMay, minimumMay) import Safe (headMay, headDef, maximumMay, minimumMay)
import Data.Time.Calendar (Day, addDays, fromGregorian) import Data.Time.Calendar (Day, addDays, fromGregorian)
import Data.Time.Clock.POSIX (POSIXTime)
import Data.Tree (Tree, flatten) import Data.Tree (Tree, flatten)
import System.Time (ClockTime(TOD))
import Text.Printf (printf) import Text.Printf (printf)
import Hledger.Utils import Hledger.Utils
@ -234,7 +234,7 @@ nulljournal = Journal {
,jtxns = [] ,jtxns = []
,jfinalcommentlines = "" ,jfinalcommentlines = ""
,jfiles = [] ,jfiles = []
,jlastreadtime = TOD 0 0 ,jlastreadtime = 0
} }
journalFilePath :: Journal -> FilePath journalFilePath :: Journal -> FilePath
@ -697,7 +697,7 @@ journalReverse j =
} }
-- | Set this journal's last read time, ie when its files were last read. -- | Set this journal's last read time, ie when its files were last read.
journalSetLastReadTime :: ClockTime -> Journal -> Journal journalSetLastReadTime :: POSIXTime -> Journal -> Journal
journalSetLastReadTime t j = j{ jlastreadtime = t } journalSetLastReadTime t j = j{ jlastreadtime = t }

View File

@ -43,7 +43,6 @@ import Data.Maybe (fromMaybe)
import qualified Data.Text.Lazy as TL import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Builder as TB import qualified Data.Text.Lazy.Builder as TB
import GHC.Generics (Generic) import GHC.Generics (Generic)
import System.Time (ClockTime)
import Hledger.Data.Types import Hledger.Data.Types
import Hledger.Data.Amount (amountsRaw, mixed) import Hledger.Data.Amount (amountsRaw, mixed)
@ -149,7 +148,6 @@ instance ToJSON PayeeDeclarationInfo
instance ToJSON Commodity instance ToJSON Commodity
instance ToJSON TimeclockCode instance ToJSON TimeclockCode
instance ToJSON TimeclockEntry instance ToJSON TimeclockEntry
instance ToJSON ClockTime
instance ToJSON Journal instance ToJSON Journal
instance ToJSON Account where instance ToJSON Account where

View File

@ -39,10 +39,10 @@ import Text.Blaze (ToMarkup(..))
import qualified Data.Map as M import qualified Data.Map as M
import Data.Ord (comparing) import Data.Ord (comparing)
import Data.Text (Text) import Data.Text (Text)
import Data.Time.Calendar import Data.Time.Calendar (Day)
import Data.Time.LocalTime import Data.Time.Clock.POSIX (POSIXTime)
import Data.Time.LocalTime (LocalTime)
import Data.Word (Word8) import Data.Word (Word8)
import System.Time (ClockTime(..))
import Hledger.Utils.Regex import Hledger.Utils.Regex
@ -528,11 +528,9 @@ data Journal = Journal {
-- followed by any included files in the order encountered. -- followed by any included files in the order encountered.
-- TODO: FilePath is a sloppy type here, don't assume it's a -- TODO: FilePath is a sloppy type here, don't assume it's a
-- real file; values like "", "-", "(string)" can be seen -- real file; values like "", "-", "(string)" can be seen
,jlastreadtime :: ClockTime -- ^ when this journal was last read from its file(s) ,jlastreadtime :: POSIXTime -- ^ when this journal was last read from its file(s)
} deriving (Eq, Generic) } deriving (Eq, Generic)
deriving instance Generic ClockTime
-- | A journal in the process of being parsed, not yet finalised. -- | A journal in the process of being parsed, not yet finalised.
-- The data is partial, and list fields are in reverse order. -- The data is partial, and list fields are in reverse order.
type ParsedJournal = Journal type ParsedJournal = Journal

View File

@ -149,9 +149,9 @@ import qualified Data.Semigroup as Sem
import Data.Text (Text) import Data.Text (Text)
import qualified Data.Text as T import qualified Data.Text as T
import Data.Time.Calendar (Day, addDays, fromGregorianValid, toGregorian) import Data.Time.Calendar (Day, addDays, fromGregorianValid, toGregorian)
import Data.Time.Clock.POSIX (getPOSIXTime)
import Data.Time.LocalTime (LocalTime(..), TimeOfDay(..)) import Data.Time.LocalTime (LocalTime(..), TimeOfDay(..))
import Data.Word (Word8) import Data.Word (Word8)
import System.Time (getClockTime)
import Text.Megaparsec import Text.Megaparsec
import Text.Megaparsec.Char (char, char', digitChar, newline, string) import Text.Megaparsec.Char (char, char', digitChar, newline, string)
import Text.Megaparsec.Char.Lexer (decimal) import Text.Megaparsec.Char.Lexer (decimal)
@ -363,7 +363,7 @@ parseAndFinaliseJournal' parser iopts f txt = do
-- --
journalFinalise :: InputOpts -> FilePath -> Text -> ParsedJournal -> ExceptT String IO Journal journalFinalise :: InputOpts -> FilePath -> Text -> ParsedJournal -> ExceptT String IO Journal
journalFinalise InputOpts{forecast_,auto_,balancingopts_,strict_} f txt pj = do journalFinalise InputOpts{forecast_,auto_,balancingopts_,strict_} f txt pj = do
t <- liftIO getClockTime t <- liftIO getPOSIXTime
d <- liftIO getCurrentDay d <- liftIO getCurrentDay
-- Infer and apply canonical styles for each commodity (or throw an error). -- Infer and apply canonical styles for each commodity (or throw an error).
-- This affects transaction balancing/assertions/assignments, so needs to be done early. -- This affects transaction balancing/assertions/assignments, so needs to be done early.

View File

@ -120,7 +120,6 @@ library
, megaparsec >=7.0.0 && <9.2 , megaparsec >=7.0.0 && <9.2
, microlens >=0.4 , microlens >=0.4
, mtl >=2.2.1 , mtl >=2.2.1
, old-time
, parser-combinators >=0.4.0 , parser-combinators >=0.4.0
, pretty-simple >4 && <5 , pretty-simple >4 && <5
, regex-tdfa , regex-tdfa
@ -171,7 +170,6 @@ test-suite doctest
, megaparsec >=7.0.0 && <9.2 , megaparsec >=7.0.0 && <9.2
, microlens >=0.4 , microlens >=0.4
, mtl >=2.2.1 , mtl >=2.2.1
, old-time
, parser-combinators >=0.4.0 , parser-combinators >=0.4.0
, pretty-simple >4 && <5 , pretty-simple >4 && <5
, regex-tdfa , regex-tdfa
@ -224,7 +222,6 @@ test-suite unittest
, megaparsec >=7.0.0 && <9.2 , megaparsec >=7.0.0 && <9.2
, microlens >=0.4 , microlens >=0.4
, mtl >=2.2.1 , mtl >=2.2.1
, old-time
, parser-combinators >=0.4.0 , parser-combinators >=0.4.0
, pretty-simple >4 && <5 , pretty-simple >4 && <5
, regex-tdfa , regex-tdfa

View File

@ -54,7 +54,6 @@ dependencies:
- megaparsec >=7.0.0 && <9.2 - megaparsec >=7.0.0 && <9.2
- microlens >=0.4 - microlens >=0.4
- mtl >=2.2.1 - mtl >=2.2.1
- old-time
- parser-combinators >=0.4.0 - parser-combinators >=0.4.0
- pretty-simple >4 && <5 - pretty-simple >4 && <5
- regex-tdfa - regex-tdfa

View File

@ -24,7 +24,6 @@ module Hledger.Cli.Utils
readFileStrictly, readFileStrictly,
pivotByOpts, pivotByOpts,
anonymiseByOpts, anonymiseByOpts,
utcTimeToClockTime,
journalSimilarTransaction, journalSimilarTransaction,
tests_Cli_Utils, tests_Cli_Utils,
) )
@ -37,7 +36,8 @@ import qualified Data.Text as T
import qualified Data.Text.IO as T import qualified Data.Text.IO as T
import qualified Data.Text.Lazy as TL import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.IO as TL import qualified Data.Text.Lazy.IO as TL
import Data.Time (UTCTime, Day) import Data.Time (Day)
import Data.Time.Clock.POSIX (POSIXTime, utcTimeToPOSIXSeconds)
import Safe (readMay, headMay) import Safe (readMay, headMay)
import System.Console.CmdArgs import System.Console.CmdArgs
import System.Directory (getModificationTime, getDirectoryContents, copyFile, doesFileExist) import System.Directory (getModificationTime, getDirectoryContents, copyFile, doesFileExist)
@ -45,13 +45,9 @@ import System.Exit
import System.FilePath ((</>), splitFileName, takeDirectory) import System.FilePath ((</>), splitFileName, takeDirectory)
import System.Info (os) import System.Info (os)
import System.Process (readProcessWithExitCode) import System.Process (readProcessWithExitCode)
import System.Time (diffClockTimes, TimeDiff(TimeDiff))
import Text.Printf import Text.Printf
import Text.Regex.TDFA ((=~)) import Text.Regex.TDFA ((=~))
import System.Time (ClockTime(TOD))
import Data.Time.Clock.POSIX (utcTimeToPOSIXSeconds)
import Hledger.Cli.CliOptions import Hledger.Cli.CliOptions
import Hledger.Cli.Anon import Hledger.Cli.Anon
import Hledger.Data import Hledger.Data
@ -166,26 +162,20 @@ journalFileIsNewer Journal{jlastreadtime=tread} f = do
mtmod <- maybeFileModificationTime f mtmod <- maybeFileModificationTime f
return $ return $
case mtmod of case mtmod of
Just tmod -> diffClockTimes tmod tread > (TimeDiff 0 0 0 0 0 0 0) Just tmod -> tmod > tread
Nothing -> False Nothing -> False
-- | Get the last modified time of the specified file, if it exists. -- | Get the last modified time of the specified file, if it exists.
maybeFileModificationTime :: FilePath -> IO (Maybe ClockTime) maybeFileModificationTime :: FilePath -> IO (Maybe POSIXTime)
maybeFileModificationTime f = do maybeFileModificationTime f = do
exists <- doesFileExist f exists <- doesFileExist f
if exists if exists
then do then do
utc <- getModificationTime f utc <- getModificationTime f
return $ Just $ utcTimeToClockTime utc return . Just $ utcTimeToPOSIXSeconds utc
else else
return Nothing return Nothing
utcTimeToClockTime :: UTCTime -> ClockTime
utcTimeToClockTime utc = TOD posixsecs picosecs
where
(posixsecs, frac) = properFraction $ utcTimeToPOSIXSeconds utc
picosecs = round $ frac * 1e12
-- | Attempt to open a web browser on the given url, all platforms. -- | Attempt to open a web browser on the given url, all platforms.
openBrowserOn :: String -> IO ExitCode openBrowserOn :: String -> IO ExitCode
openBrowserOn u = trybrowsers browsers u openBrowserOn u = trybrowsers browsers u

View File

@ -159,7 +159,6 @@ library
, math-functions >=0.3.3.0 , math-functions >=0.3.3.0
, megaparsec >=7.0.0 && <9.2 , megaparsec >=7.0.0 && <9.2
, mtl >=2.2.1 , mtl >=2.2.1
, old-time
, process , process
, regex-tdfa , regex-tdfa
, safe >=0.2 , safe >=0.2
@ -209,7 +208,6 @@ executable hledger
, math-functions >=0.3.3.0 , math-functions >=0.3.3.0
, megaparsec >=7.0.0 && <9.2 , megaparsec >=7.0.0 && <9.2
, mtl >=2.2.1 , mtl >=2.2.1
, old-time
, process , process
, regex-tdfa , regex-tdfa
, safe >=0.2 , safe >=0.2
@ -260,7 +258,6 @@ test-suite unittest
, math-functions >=0.3.3.0 , math-functions >=0.3.3.0
, megaparsec >=7.0.0 && <9.2 , megaparsec >=7.0.0 && <9.2
, mtl >=2.2.1 , mtl >=2.2.1
, old-time
, process , process
, regex-tdfa , regex-tdfa
, safe >=0.2 , safe >=0.2
@ -310,7 +307,6 @@ benchmark bench
, math-functions >=0.3.3.0 , math-functions >=0.3.3.0
, megaparsec >=7.0.0 && <9.2 , megaparsec >=7.0.0 && <9.2
, mtl >=2.2.1 , mtl >=2.2.1
, old-time
, process , process
, regex-tdfa , regex-tdfa
, safe >=0.2 , safe >=0.2

View File

@ -113,7 +113,6 @@ dependencies:
- haskeline >=0.6 - haskeline >=0.6
- megaparsec >=7.0.0 && <9.2 - megaparsec >=7.0.0 && <9.2
- mtl >=2.2.1 - mtl >=2.2.1
- old-time
- process - process
- regex-tdfa - regex-tdfa
- safe >=0.2 - safe >=0.2