correct • elegant • free

Feeds now available

I finally got around to making Atom and RSS feeds working. Huge thanks are due to pbrisbin, first for his work on yesod-newsfeed (in which the ubiquitous Michael Snoyman also seems to have had a hand). Secondly, for publishing the code to his own (very cool) site on github.

Haskell folk seem to be averse to examples, something I try to remedy in my own tutorials; it was essential to me to see working yesod-newsfeed code. Maybe I should publish my site code too, although I'd probably want to clean it up rather a lot first.

Absolutely the worst part of getting the feed up and running was the mess of time-related functions in Haskell. Why does System.Directory.getModificationTime return a value of the obsolescent ClockTime type? The code that turns this into the UTCTime that we need is truly hideous:

toTime f =
  let file = docDir ++ "journal/" ++ f ++ ".html"
  in do
    t <- getModificationTime file -- XXX this can fail
    let ct = toUTCTime t
    return $ UTCTime (fromGregorian
        (toInteger $ ctYear ct) (1 + fromEnum (ctMonth ct)) (ctDay ct))
      (secondsToDiffTime $ (toInteger $ ctSec ct) + 60 * ((toInteger $ ctMin ct) + 60 * (toInteger $ ctHour ct)))

I'm sure there's a better way: please get in touch if you know what it is!

Anyway, I haven't really got all that much to say today, I just wanted to make a new post to see it turn up in the feed. I confess I mainly use Google Reader these days, and the feed seems to work just fine there. One day, I'll get back to newsbeuter, the feed aggregator for people who miss trn (as I do).