Re: [Haskell-cafe] time of day

2009-12-28 Thread Yitzchak Gale
Brian Denheyer wrote:
>> What's the best way to get the year/month/day/hour/min/sec of the
>> current time ?

import Data.Time
...
  now <- getCurrentTime
  tz <- getCurrentTimeZone
  let t = utcToLocalTime tz now
  (year, month, day) = toGregorian $ localDay t
  TimeOfDay hour minute sec = localTimeOfDay t

If you need the day of week, then also:

import Data.Time.Calendar.OrdinalDate (sundayStartWeek)
...
  (_, dow) = sundayStartWeek $ localDay t -- Sunday = 0

If you need to use different time zones other than the
current local one, construct them like this:

est = TimeZone
  {timeZoneMinutes = -300,
   timeZoneSummerOnly = False,
   timeZoneName = "EST"}
edt = TimeZone
  {timeZoneMinutes = -240,
   timeZoneSummerOnly = True,
   timeZoneName = "EDT"}

>> I've become mired in confusion with Time, Data.Time,
>> DateTime and I think there is even an old-time.
>> Might be a couple of calendar libraries in there, not quite sure...

Thomas DuBuisson wrote:
> 'time' is the generally accepted package which exports the
> Data.Time you mentioned.

Yes, use that.

> 'DateTime' looks to use 'time' to provide an aledgedly simpler
> API.

I tried that once. It is supposed to have a slightly gentler learning
curve, but in the end I think Data.Time itself is nicer.

The only reason Data.Time is a little confusing at first is because
the most useful functions are sprinkled into many different
modules in the documentation, and hidden among less useful
ones. Once you know where to look for things, it's easy.

-Yitz
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] time of day

2009-12-27 Thread Thomas DuBuisson
'time' is the generally accepted package which exports the Data.Time you
mentioned. 'DateTime' looks to use 'time' to provide an aledgedly simpler
API. 'old-time' should go away eventually and thus you should not use it for
new projects.

You likely want 'getCurrentTime' [1].

Thomas

[1]
http://hackage.haskell.org/packages/archive/time/1.1.4/doc/html/Data-Time-Clock.html#v%3AgetCurrentTime

On Sun, Dec 27, 2009 at 10:42 PM, Brian Denheyer  wrote:

>
> Hi All,
>
> What's the best way to get the year/month/day/hour/min/sec of the
> current time ?  I've become mired in confusion with Time, Data.Time,
> DateTime and I think there is even an old-time.
>
> Might be a couple of calendar libraries in there, not quite sure...
>
> Thanks,
>
> Brian
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] time of day

2009-12-27 Thread Brian Denheyer

Hi All,

What's the best way to get the year/month/day/hour/min/sec of the
current time ?  I've become mired in confusion with Time, Data.Time,
DateTime and I think there is even an old-time.

Might be a couple of calendar libraries in there, not quite sure...

Thanks,

Brian

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe