aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Rosenthal <jrosenthal@jhu.edu>2016-11-30 09:46:08 -0500
committerJohn MacFarlane <jgm@berkeley.edu>2017-01-25 17:07:40 +0100
commit9d9f615593dc2cd986063058e9d8d91f99456242 (patch)
tree5439a09c6a603ae593f292d2a2c77bbc02bcf8fd /src
parentfe0b71a2f1505e265202fd9e07458ff1e9554651 (diff)
downloadpandoc-9d9f615593dc2cd986063058e9d8d91f99456242.tar.gz
Add Zoned time to class.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Class.hs16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Class.hs b/src/Text/Pandoc/Class.hs
index e6435eae3..cee93c4fc 100644
--- a/src/Text/Pandoc/Class.hs
+++ b/src/Text/Pandoc/Class.hs
@@ -35,6 +35,7 @@ module Text.Pandoc.Class ( PandocMonad(..)
, PureState(..)
, PureEnv(..)
, getPOSIXTime
+ , getZonedTime
, addWarningWithPos
, PandocIO(..)
, PandocPure(..)
@@ -64,6 +65,8 @@ import qualified Text.Pandoc.Compat.Time as IO (getCurrentTime)
import Data.Time.Clock.POSIX ( utcTimeToPOSIXSeconds
, posixSecondsToUTCTime
, POSIXTime )
+import Data.Time.LocalTime (TimeZone, ZonedTime, utcToZonedTime, utc)
+import qualified Data.Time.LocalTime as IO (getCurrentTimeZone)
import Text.Pandoc.MIME (MimeType, getMimeType)
import Text.Pandoc.MediaBag (MediaBag)
import qualified Text.Pandoc.MediaBag as MB
@@ -82,12 +85,12 @@ import Data.Word (Word8)
import Data.Typeable
import Data.Default
import System.IO.Error
-import Data.Map (Map)
import qualified Data.Map as M
class (Functor m, Applicative m, Monad m, MonadError PandocExecutionError m) => PandocMonad m where
lookupEnv :: String -> m (Maybe String)
getCurrentTime :: m UTCTime
+ getCurrentTimeZone :: m TimeZone
getDefaultReferenceDocx :: Maybe FilePath -> m Archive
getDefaultReferenceODT :: Maybe FilePath -> m Archive
newStdGen :: m StdGen
@@ -117,6 +120,12 @@ class (Functor m, Applicative m, Monad m, MonadError PandocExecutionError m) =>
getPOSIXTime :: (PandocMonad m) => m POSIXTime
getPOSIXTime = utcTimeToPOSIXSeconds <$> getCurrentTime
+getZonedTime :: (PandocMonad m) => m ZonedTime
+getZonedTime = do
+ t <- getCurrentTime
+ tz <- getCurrentTimeZone
+ return $ utcToZonedTime tz t
+
addWarningWithPos :: PandocMonad m
=> Maybe SourcePos
-> String
@@ -169,6 +178,7 @@ newtype PandocIO a = PandocIO {
instance PandocMonad PandocIO where
lookupEnv = liftIO . IO.lookupEnv
getCurrentTime = liftIO IO.getCurrentTime
+ getCurrentTimeZone = liftIO IO.getCurrentTimeZone
getDefaultReferenceDocx = liftIO . IO.getDefaultReferenceDocx
getDefaultReferenceODT = liftIO . IO.getDefaultReferenceODT
newStdGen = liftIO IO.newStdGen
@@ -236,6 +246,7 @@ getFileInfo fp tree = M.lookup fp $ unFileTree tree
data PureEnv = PureEnv { envEnv :: [(String, String)]
, envTime :: UTCTime
+ , envTimeZone :: TimeZone
, envReferenceDocx :: Archive
, envReferenceODT :: Archive
, envFiles :: FileTree
@@ -249,6 +260,7 @@ data PureEnv = PureEnv { envEnv :: [(String, String)]
instance Default PureEnv where
def = PureEnv { envEnv = [("USER", "pandoc-user")]
, envTime = posixSecondsToUTCTime 0
+ , envTimeZone = utc
, envReferenceDocx = emptyArchive
, envReferenceODT = emptyArchive
, envFiles = mempty
@@ -280,6 +292,8 @@ instance PandocMonad PandocPure where
getCurrentTime = asks envTime
+ getCurrentTimeZone = asks envTimeZone
+
getDefaultReferenceDocx _ = asks envReferenceDocx
getDefaultReferenceODT _ = asks envReferenceODT