From 4c1a6b350095e671eea5a4963e6b82997c5098fc Mon Sep 17 00:00:00 2001
From: Martin Perner <martin@perner.cc>
Date: Thu, 21 Jul 2011 18:13:32 +0200
Subject: DateZone: Added plugin for localized date

---
 src/Plugins/DateZone.hs | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
 create mode 100644 src/Plugins/DateZone.hs

(limited to 'src/Plugins')

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
-- 
cgit v1.2.3