summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins/DateZone.hs
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2011-08-21 19:48:44 +0200
committerJose Antonio Ortega Ruiz <jao@gnu.org>2011-08-21 19:48:44 +0200
commit1fab853cb8a76eb9b7c5400924a8c53b3b095712 (patch)
tree54f20fb5987904700669d67519cc45169ae78bb7 /src/Plugins/DateZone.hs
parent8afb450eb104e5335f4b1b976512842f7059142c (diff)
parent4a57c777bccbf169aa50411ecaed0af333ac6871 (diff)
downloadxmobar-1fab853cb8a76eb9b7c5400924a8c53b3b095712.tar.gz
xmobar-1fab853cb8a76eb9b7c5400924a8c53b3b095712.tar.bz2
Merge remote-tracking branch 'github/master'
Diffstat (limited to 'src/Plugins/DateZone.hs')
-rw-r--r--src/Plugins/DateZone.hs44
1 files changed, 44 insertions, 0 deletions
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