diff options
author | Martin Perner <martin@perner.cc> | 2011-10-26 01:00:32 +0200 |
---|---|---|
committer | Martin Perner <martin@perner.cc> | 2011-10-26 02:01:05 +0200 |
commit | 9718dabe6c6d5979e3f6837ef04a39d3ad8c786c (patch) | |
tree | a4b13708063b856499989bd453d7c28a335b55e7 /src/Plugins/DateZoneL.hs | |
parent | 218d07606a7564cdcde5974d53b8e81d04c02a44 (diff) | |
download | xmobar-9718dabe6c6d5979e3f6837ef04a39d3ad8c786c.tar.gz xmobar-9718dabe6c6d5979e3f6837ef04a39d3ad8c786c.tar.bz2 |
Adding locale support to Date plugins
This commits adds support for localized datetime outputs like date(1).
Diffstat (limited to 'src/Plugins/DateZoneL.hs')
-rw-r--r-- | src/Plugins/DateZoneL.hs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/Plugins/DateZoneL.hs b/src/Plugins/DateZoneL.hs new file mode 100644 index 0000000..2b7c467 --- /dev/null +++ b/src/Plugins/DateZoneL.hs @@ -0,0 +1,42 @@ +----------------------------------------------------------------------------- +-- | +-- Module : Plugins.DateZoneL +-- Copyright : (c) Martin Perner +-- License : BSD-style (see LICENSE) +-- +-- Maintainer : Martin Perner <martin@perner.cc> +-- Stability : unstable +-- Portability : unportable +-- +-- A date plugin with localization and location support for Xmobar +-- +-- Based on Plugins.DateZone +-- +----------------------------------------------------------------------------- + +module Plugins.DateZoneL (DateZoneL(..)) where + +import Plugins + +import Localize + +import Data.Time.LocalTime +import Data.Time.Format +import Data.Time.LocalTime.TimeZone.Olson +import Data.Time.LocalTime.TimeZone.Series + +data DateZoneL = DateZoneL String String String String Int + deriving (Read, Show) + +instance Exec DateZoneL where + alias (DateZoneL _ _ a _ _) = a + start (DateZoneL f l _ z r) cb = do + setupTimeLocale l + go + where go = date f z >>= cb >> tenthSeconds r >> go + +date :: String -> String -> IO String +date format zone = do + timeZone <- getTimeZoneSeriesFromOlsonFile ("/usr/share/zoneinfo/" ++ zone) + zonedTime <- getZonedTime + return $ formatTime getTimeLocale format $ utcToLocalTime' timeZone $ zonedTimeToUTC zonedTime |