From 9718dabe6c6d5979e3f6837ef04a39d3ad8c786c Mon Sep 17 00:00:00 2001 From: Martin Perner Date: Wed, 26 Oct 2011 01:00:32 +0200 Subject: Adding locale support to Date plugins This commits adds support for localized datetime outputs like date(1). --- src/Plugins/DateL.hs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/Plugins/DateL.hs (limited to 'src/Plugins/DateL.hs') diff --git a/src/Plugins/DateL.hs b/src/Plugins/DateL.hs new file mode 100644 index 0000000..d8859ed --- /dev/null +++ b/src/Plugins/DateL.hs @@ -0,0 +1,35 @@ +----------------------------------------------------------------------------- +-- | +-- Module : Plugins.DateL +-- Copyright : (c) Andrea Rossato +-- License : BSD-style (see LICENSE) +-- +-- Maintainer : Martin Perner +-- Stability : unstable +-- Portability : unportable +-- +-- A date plugin with localization for Xmobar +-- +----------------------------------------------------------------------------- + +module Plugins.DateL (DateL(..)) where + +import Plugins +import Localize + +import System.Time + +data DateL = DateL String String String Int + deriving (Read, Show) + +instance Exec DateL where + alias (DateL _ _ a _) = a + start (DateL f l _ r) cb = do + setupTimeLocale l + go + where go = date f >>= cb >> tenthSeconds r >> go + +date :: String -> IO String +date format = do + t <- toCalendarTime =<< getClockTime + return $ formatCalendarTime getTimeLocale format t -- cgit v1.2.3