summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins/DateZone.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Plugins/DateZone.hs')
-rw-r--r--src/Plugins/DateZone.hs28
1 files changed, 21 insertions, 7 deletions
diff --git a/src/Plugins/DateZone.hs b/src/Plugins/DateZone.hs
index 79596c9..f1737fb 100644
--- a/src/Plugins/DateZone.hs
+++ b/src/Plugins/DateZone.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE CPP #-}
{-# LANGUAGE DoAndIfThenElse #-}
-----------------------------------------------------------------------------
-- |
@@ -23,30 +24,37 @@ module Plugins.DateZone (DateZone(..)) where
import Plugins
-import Localize
+#ifdef DATEZONE
import Control.Concurrent.STM
+import System.IO.Unsafe
+
+import Localize
import Data.Time.LocalTime
import Data.Time.Format
import Data.Time.LocalTime.TimeZone.Olson
import Data.Time.LocalTime.TimeZone.Series
-import System.IO.Unsafe
import System.Locale (TimeLocale)
+#else
+import System.IO
+import Plugins.Date
+#endif
-{-# NOINLINE localeLock #-}
--- ensures that only one plugin instance sets the locale
-localeLock :: TMVar Bool
-localeLock = unsafePerformIO (newTMVarIO False)
-
data DateZone = DateZone String String String String Int
deriving (Read, Show)
instance Exec DateZone where
alias (DateZone _ _ _ a _) = a
+#ifndef DATEZONE
+ start (DateZone f _ _ a r) cb = do
+ hPutStrLn stderr $ "Warning: DateZone plugin needs -fwith_datezone."++
+ " Using Date plugin instead."
+ start (Date f a r) cb
+#else
start (DateZone f l z _ r) cb = do
lock <- atomically $ takeTMVar localeLock
setupTimeLocale l
@@ -60,6 +68,11 @@ instance Exec DateZone where
where go func = func >>= cb >> tenthSeconds r >> go func
+{-# NOINLINE localeLock #-}
+-- ensures that only one plugin instance sets the locale
+localeLock :: TMVar Bool
+localeLock = unsafePerformIO (newTMVarIO False)
+
date :: String -> TimeLocale -> IO String
date format loc = getZonedTime >>= return . formatTime loc format
@@ -67,3 +80,4 @@ dateZone :: String -> TimeLocale -> TimeZoneSeries -> IO String
dateZone format loc timeZone = getZonedTime >>= return . formatTime loc format . utcToLocalTime' timeZone . zonedTimeToUTC
-- zonedTime <- getZonedTime
-- return $ formatTime loc format $ utcToLocalTime' timeZone $ zonedTimeToUTC zonedTime
+#endif