summaryrefslogtreecommitdiffhomepage
path: root/src/Plugins/DateZoneL.hs
blob: 2b7c467e1a1c4d8063a8d35ff4a0d27fd6a88be5 (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
36
37
38
39
40
41
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