summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2011-07-23 07:47:50 -0700
committerjao <jao@gnu.org>2011-07-23 07:47:50 -0700
commit6d438380213aaf903164ff6fa89dd768facb9bd5 (patch)
tree14d8068afb63cca955af6787ea47c7fcb3ee2c5f /src
parent5d5b4a4d7e07d20eec62b5650df5d55807741a4c (diff)
parent4c1a6b350095e671eea5a4963e6b82997c5098fc (diff)
downloadxmobar-6d438380213aaf903164ff6fa89dd768facb9bd5.tar.gz
xmobar-6d438380213aaf903164ff6fa89dd768facb9bd5.tar.bz2
Merge pull request #19 from skinner33/dateZone
DateZone: Added plugin for localized date
Diffstat (limited to 'src')
-rw-r--r--src/Config.hs7
-rw-r--r--src/Plugins/DateZone.hs44
2 files changed, 51 insertions, 0 deletions
diff --git a/src/Config.hs b/src/Config.hs
index 6eb55a0..3184023 100644
--- a/src/Config.hs
+++ b/src/Config.hs
@@ -38,6 +38,10 @@ import Plugins.Mail
import Plugins.MBox
#endif
+#ifdef DATEZONE
+import Plugins.DateZone
+#endif
+
-- $config
-- Configuration data type and default configuration
@@ -112,5 +116,8 @@ runnableTypes :: Command :*: Monitors :*: Date :*: PipeReader :*: CommandReader
#ifdef INOTIFY
Mail :*: MBox :*:
#endif
+#ifdef DATEZONE
+ DateZone :*:
+#endif
()
runnableTypes = undefined
diff --git a/src/Plugins/DateZone.hs b/src/Plugins/DateZone.hs
new file mode 100644
index 0000000..4d5ce6a
--- /dev/null
+++ b/src/Plugins/DateZone.hs
@@ -0,0 +1,44 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module : Plugins.DateZone
+-- Copyright : (c) Martin Perner
+-- License : BSD-style (see LICENSE)
+--
+-- Maintainer : Martin Perner <martin@perner.cc>
+-- Stability : unstable
+-- Portability : unportable
+--
+-- A date plugin with localization support for Xmobar
+--
+-- Based on Plugins.Date
+--
+-- Usage example: in template put
+--
+-- > Run DateZone "%H:%M:%S" "utcDate" "UTC" 10
+--
+-----------------------------------------------------------------------------
+
+module Plugins.DateZone (DateZone(..)) where
+
+import Plugins
+
+import System.Locale
+
+import Data.Time.LocalTime
+import Data.Time.Format
+import Data.Time.LocalTime.TimeZone.Olson
+import Data.Time.LocalTime.TimeZone.Series
+
+data DateZone = DateZone String String String Int
+ deriving (Read, Show)
+
+instance Exec DateZone where
+ alias (DateZone _ a _ _) = a
+ run (DateZone f _ z _) = date f z
+ rate (DateZone _ _ _ r) = r
+
+date :: String -> String -> IO String
+date format zone = do
+ timeZone <- getTimeZoneSeriesFromOlsonFile ("/usr/share/zoneinfo/" ++ zone)
+ zonedTime <- getZonedTime
+ return $ formatTime defaultTimeLocale format $ utcToLocalTime' timeZone $ zonedTimeToUTC zonedTime