X.P.OrgMode: Fix deprecation warning

Starting with time-1.10, the iso8601DateFormat function was deprecated
in favour of more sophisticated methods for showing ISO 8601 date
formats—as such, follow the libraries lead.

Sadly, the new functionality was only introduced in time-1.9, meaning
GHC 8.8 and up.  Since we still support 8.6, the introduction of some
CPP is necessary.
This commit is contained in:
Tony Zorman
2022-11-20 08:34:47 +01:00
parent 35e434ed85
commit 502f6a0e75

View File

@@ -67,7 +67,12 @@ import XMonad.Util.XSelection (getSelection)
import XMonad.Util.Run
import Control.DeepSeq (deepseq)
import Data.Time (Day (ModifiedJulianDay), NominalDiffTime, UTCTime (utctDay), addUTCTime, defaultTimeLocale, formatTime, fromGregorian, getCurrentTime, iso8601DateFormat, nominalDay, toGregorian)
import Data.Time (Day (ModifiedJulianDay), NominalDiffTime, UTCTime (utctDay), addUTCTime, fromGregorian, getCurrentTime, nominalDay, toGregorian)
#if MIN_VERSION_time(1, 9, 0)
import Data.Time.Format.ISO8601 (iso8601Show)
#else
import Data.Time.Format (defaultTimeLocale, formatTime, iso8601DateFormat)
#endif
import GHC.Natural (Natural)
import System.IO (IOMode (AppendMode, ReadMode), hClose, hGetContents, openFile, withFile)
@@ -382,7 +387,11 @@ toOrgFmt tod day =
mconcat ["<", isoDay, " ", take 3 $ show (dayOfWeek day), time, ">"]
where
time :: String = maybe "" ((' ' :) . show) tod
#if MIN_VERSION_time(1, 9, 0)
isoDay :: String = iso8601Show day
#else
isoDay :: String = formatTime defaultTimeLocale (iso8601DateFormat Nothing) day
#endif
-- | Pretty print a 'Date' and an optional time to reflect the actual
-- date.