Comparing DateTime and Date

For my project Novo, I’ve been working on a script to sync my Apple iCal to Google’s gCal. Think of it as a poor man’s version of SpanningSync.

One of our challenges is that sometimes we are dealing with Ruby DateTime objects, and other times we are dealing with Date objects. And of course, you can’t compare the two to each other (argh!).

So initially I would convert them to strings, and then create Time objects and then compare them. And if they were in UTC format, I had a hardcoded value that swapped in my offset from UTC. Of course, with the early arrival (ending???) of Daylight Savings Time change in the US, this caused one week all my appointments to be synced into gCal one hour off!

So I took advantage of chatting with Chris Hapgood about his challenges with dates and timezones and implemented TZInfo.

But, much to my disgust, when I hand in a DateTime to TZInfo, I get back a proper UTC formatted DateTime. And when I hand in a Time to TZInfo, I get back a proper UTC formatted Time object! So, I am still stuck converting to String, and then reparsing into Time for comparisions.

I’ve looked around, and the only thing I’ve found was from a site that has Ruby Cookbook tips, but it just seems like I should be able to more simply parse/compare the two! Especially since I don’t know if I am dealing with DateTimes or Times, and so have to put in some funky logic to figure it out and do the right parsing….