Use time instead of old-time and old-locale

Get rid of these deprecated libraries, as the new `time' library
provides a strict superset of the functionality of `old-time' and
`old-locale'.
This commit is contained in:
slotThe 2021-03-20 16:14:26 +01:00
parent f1bd315448
commit 94f1e943d4
3 changed files with 13 additions and 15 deletions

View File

@ -19,7 +19,8 @@ module XMonad.Actions.AfterDrag (
ifClick') where ifClick') where
import XMonad import XMonad
import System.Time
import Data.Time (NominalDiffTime, diffUTCTime, getCurrentTime)
-- $usage -- $usage
-- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@: -- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@:
@ -53,7 +54,7 @@ afterDrag task = do drag <- gets dragging
-- A drag is considered a click if it is completed within 300 ms. -- A drag is considered a click if it is completed within 300 ms.
ifClick ifClick
:: X () -- ^ The action to take if the dragging turned out to be a click. :: X () -- ^ The action to take if the dragging turned out to be a click.
-> X () -> X ()
ifClick action = ifClick' 300 action (return ()) ifClick action = ifClick' 300 action (return ())
-- | Take an action if the current dragging is completed within a certain time (in milliseconds.) -- | Take an action if the current dragging is completed within a certain time (in milliseconds.)
@ -61,11 +62,11 @@ ifClick'
:: Int -- ^ Maximum time of dragging for it to be considered a click (in milliseconds.) :: Int -- ^ Maximum time of dragging for it to be considered a click (in milliseconds.)
-> X () -- ^ The action to take if the dragging turned out to be a click. -> X () -- ^ The action to take if the dragging turned out to be a click.
-> X () -- ^ The action to take if the dragging turned out to not be a click. -> X () -- ^ The action to take if the dragging turned out to not be a click.
-> X () -> X ()
ifClick' ms click drag = do ifClick' ms click drag = do
start <- io $ getClockTime start <- io getCurrentTime
afterDrag $ do afterDrag $ do
stop <- io $ getClockTime stop <- io getCurrentTime
if diffClockTimes stop start <= noTimeDiff { tdPicosec = fromIntegral ms * 10^(9 :: Integer) } if diffUTCTime stop start <= (fromIntegral ms / 10^(3 :: Integer) :: NominalDiffTime)
then click then click
else drag else drag

View File

@ -57,11 +57,10 @@ import XMonad.Util.NamedWindows (getName)
import Control.Exception as E import Control.Exception as E
import Data.List (find, isPrefixOf, isSuffixOf) import Data.List (find, isPrefixOf, isSuffixOf)
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
import Data.Time (defaultTimeLocale, formatTime, getCurrentTime)
import System.Directory (getDirectoryContents) import System.Directory (getDirectoryContents)
import System.IO import System.IO (hGetLine)
import System.Locale
import System.Process (runInteractiveCommand) import System.Process (runInteractiveCommand)
import System.Time
econst :: Monad m => a -> IOException -> m a econst :: Monad m => a -> IOException -> m a
econst = const . return econst = const . return
@ -129,8 +128,7 @@ battery = logCmd "acpi | sed -r 's/.*?: (.*%).*/\\1/; s/[dD]ischarging, ([0-9]+%
-- For more information see something like -- For more information see something like
-- <http://www.cplusplus.com/reference/clibrary/ctime/strftime.html>. -- <http://www.cplusplus.com/reference/clibrary/ctime/strftime.html>.
date :: String -> Logger date :: String -> Logger
date fmt = io $ do cal <- getClockTime >>= toCalendarTime date fmt = io $ Just . formatTime defaultTimeLocale fmt <$> getCurrentTime
return . Just $ formatCalendarTime defaultTimeLocale fmt cal
-- | Get the load average. This assumes that you have a -- | Get the load average. This assumes that you have a
-- utility called @uptime@ and that you have @sed@ -- utility called @uptime@ and that you have @sed@
@ -248,7 +246,7 @@ withScreen f n = do
ss <- withWindowSet $ return . W.screens ss <- withWindowSet $ return . W.screens
case find ((== n) . W.screen) ss of case find ((== n) . W.screen) ss of
Just s -> f s Just s -> f s
Nothing -> pure $ Nothing Nothing -> pure Nothing
-- $format -- $format
-- Combine logger formatting functions to make your -- Combine logger formatting functions to make your

View File

@ -52,8 +52,7 @@ library
containers >= 0.5 && < 0.7, containers >= 0.5 && < 0.7,
directory, directory,
filepath, filepath,
old-locale, time >= 1.8 && < 1.12,
old-time,
process, process,
random, random,
mtl >= 1 && < 3, mtl >= 1 && < 3,