summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins/DateL.hs
blob: d8859edf291da42d692e6fc251e45e569e598d41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
-----------------------------------------------------------------------------
-- |
-- Module      :  Plugins.DateL
-- Copyright   :  (c) Andrea Rossato
-- License     :  BSD-style (see LICENSE)
--
-- Maintainer  :  Martin Perner <martin@perner.cc>
-- 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