diff options
| author | Martin Perner <martin@perner.cc> | 2011-07-21 18:13:32 +0200 | 
|---|---|---|
| committer | Martin Perner <martin@perner.cc> | 2011-07-21 18:27:40 +0200 | 
| commit | 4c1a6b350095e671eea5a4963e6b82997c5098fc (patch) | |
| tree | 14d8068afb63cca955af6787ea47c7fcb3ee2c5f | |
| parent | 5d5b4a4d7e07d20eec62b5650df5d55807741a4c (diff) | |
| download | xmobar-4c1a6b350095e671eea5a4963e6b82997c5098fc.tar.gz xmobar-4c1a6b350095e671eea5a4963e6b82997c5098fc.tar.bz2 | |
DateZone: Added plugin for localized date
| -rw-r--r-- | README | 14 | ||||
| -rw-r--r-- | src/Config.hs | 7 | ||||
| -rw-r--r-- | src/Plugins/DateZone.hs | 44 | ||||
| -rw-r--r-- | xmobar.cabal | 9 | 
4 files changed, 74 insertions, 0 deletions
| @@ -124,6 +124,10 @@ Otherwise, you'll need to install them yourself.  :    Support for ALSA sound cards. Enables the Volume plugin. Requires the       [alsa-mixer] package. +`with_datezone` +:    Support for localized times. Enables the DateZone plugin. Requires +     [timezone-olson] and [timezone-series] package. +  `all_extensions`  :    Enables all the extensions above. @@ -846,6 +850,16 @@ can be used in the output template as `%mydate%`    `strftime` function (or Haskell's `formatCalendarTime`).  - Sample usage: `Run Date "%a %b %_d %Y <fc=#ee9a00>%H:%M:%S</fc>" "date" 10` +`Date Format Alias Zone RefreshRate` + +- Format is a time format string, as accepted by the standard ISO C +  `strftime` function (or Haskell's `formatCalendarTime`). +- Zone is the name of the TimeZone. Assumes that the tz database is stored in +  /usr/share/zoneinfo/ +- Sample usage: +  `Run DateZone "<fc=#ee9a00>%H:%M:%S</fc>" "viennaDate" "Europa/Vienna" 10` + +  `CommandReader "/path/to/program" Alias`  - Runs the given program, and displays its standard output. 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 diff --git a/xmobar.cabal b/xmobar.cabal index abdf136..ecafe1d 100644 --- a/xmobar.cabal +++ b/xmobar.cabal @@ -57,6 +57,10 @@ flag with_alsa    description: Use alsa-mixer to get the volume from soundcards.    default: False +flag with_datezone +  description: Enables localized date support +  default: False +  executable xmobar      hs-source-dirs:     src      main-is:            Main.hs @@ -120,3 +124,8 @@ executable xmobar         build-depends: alsa-mixer == 0.1.*         other-modules: Plugins.Monitors.Volume         cpp-options: -DALSA + +    if flag(with_datezone) || flag(all_extensions) +       build-depends: timezone-olson, timezone-series +       other-modules: Plugins.DateZone +       cpp-options: -DDATEZONE | 
