[Haskell-cafe] timezone-series and timezone-olson

Manfred Lotz manfred.lotz at arcor.de
Sun Mar 27 19:10:07 CEST 2011


Hi Yitz,
Thanks for answering so quickly.

On Sun, 27 Mar 2011 14:16:50 +0200
Yitzchak Gale <gale at sefer.org> wrote:

> Hi Manfred,
> > runhaskell caltest.hs
"  03/27/11\n"

> I am copying this response to the Haskell Cafe mailing list.
> 
> Manfred Lotz wrote:
> > ...I'm trying to figure out how to use your
> > packages to get the time in a different timezone.
> > Do you have an example how to do that? What I want for example is to
> > provide the timezone preferably like this: US/Eastern, and get the
> > time information like for example this:
> >
> > US/Eastern        DST  EDT   2011.03.27 05:20:52
> >
> > The pieces I like to get are: Summertime indicator, TZ abbrev and
> > the date resp. time in that timezone.
> 

...

> 
> Assuming you have the timezone file that you need - let's say it
> is in the directory /usr/share/zoneinfo as typical for Linux and
> Mac - here is how to code it:
> 
> do
>   ...
>   tzs <- getTimeZoneSeriesFromOlsonFile
> "/usr/share/zoneinfo/America/New_York" let usEastern =
> utcToLocalTime' tzs utc
> 
> Then, to format the time as you require, use the formatTime function
> from the time package.
> 

I tried it like this:

<------------------------------snip--------------------------------->

module Main where

import System.Environment
import System.Exit
import System.Locale
import Data.Time
import Data.Time.Clock
import Data.Time.LocalTime
import Data.Time.LocalTime.TimeZone.Olson 
import Data.Time.LocalTime.TimeZone.Series


path = "/usr/share/zoneinfo/"

showTime t = fmap (formatTime defaultTimeLocale "%Z %z %D%n") t

  
getTime :: [Char] -> IO LocalTime
getTime tz = do
  tzs <- getTimeZoneSeriesFromOlsonFile (path ++ tz)
  utcnow <- getCurrentTime
  let tzo = utcToLocalTime' tzs utcnow in return tzo


     
main = let t = getTime "US/Eastern"
       in showTime 
<------------------------------snap--------------------------------->

Don't know if this is the proper way to do. In the output I do not get
the timezone information:

> runhaskell caltest.hs
"  03/27/11\n"

Don't know what I'm doing wrong.	


-- 
Manfred





More information about the Haskell-Cafe mailing list