Feeds:
Posts
Comments

First Post … I’ll start with something useful and practical.

I’ve spent some time experimenting with Haskell. The reason was inspired by Linq and the idea of using functional programming. It reminded me of the Haskell course I did at university, and even then I thought functional programming was very powerful, and sometimes hard to get to grips with.

Once I relearned the basic syntax I wanted to do something practical. And it involved dates and times. There isn’t much info on my search in Google for how to use dates and times. So as a starter I have created a little function to make it easy to construct a time … so you don’t have to!

import Data.Time
import Data.Fixed

easyUtc :: Integer->Int->Int->Int->Int->Pico->UTCTime
easyUtc y m d h mm s = UTCTime (fromGregorian y m d) (timeOfDayToTime ( TimeOfDay h mm s))

This function takes a year, month, day, hours, minutes and seconds and returns a UTC time with all of that information. An example of the usage is:

easyUtc 2007 01 01 00 00 00

So now you can use dates and times in your code, and construct the test data with ease.