The time math in the source looks like stuff gmtime()/mktime() do internally -- maybe you could delete some code by using these and working with Unix timestamps.