diff options
author | jao <jao@gnu.org> | 2011-07-23 07:47:50 -0700 |
---|---|---|
committer | jao <jao@gnu.org> | 2011-07-23 07:47:50 -0700 |
commit | 6d438380213aaf903164ff6fa89dd768facb9bd5 (patch) | |
tree | 14d8068afb63cca955af6787ea47c7fcb3ee2c5f | |
parent | 5d5b4a4d7e07d20eec62b5650df5d55807741a4c (diff) | |
parent | 4c1a6b350095e671eea5a4963e6b82997c5098fc (diff) | |
download | xmobar-6d438380213aaf903164ff6fa89dd768facb9bd5.tar.gz xmobar-6d438380213aaf903164ff6fa89dd768facb9bd5.tar.bz2 |
Merge pull request #19 from skinner33/dateZone
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 |